Commit 6ec3a579 authored by jln@chromium.org's avatar jln@chromium.org

GPU: call CreateGLContext() to warm up the sandbox on Linux.

We refactor the sandbox warmup code in a new WarmUpSandbox() function.
We call CreateGLContext() as part of the warm-up for Nvidia drivers.

BUG=140214

Review URL: https://chromiumcodereview.appspot.com/10831343

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152012 0039d316-1c4b-4281-b951-d872f2087c98
parent c33afde9
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
#include "content/public/common/sandbox_init.h" #include "content/public/common/sandbox_init.h"
#endif #endif
namespace {
void WarmUpSandbox(const content::GPUInfo&, bool);
void CollectGraphicsInfo(content::GPUInfo*);
}
// Main function for starting the Gpu process. // Main function for starting the Gpu process.
int GpuMain(const content::MainFunctionParams& parameters) { int GpuMain(const content::MainFunctionParams& parameters) {
TRACE_EVENT0("gpu", "GpuMain"); TRACE_EVENT0("gpu", "GpuMain");
...@@ -99,6 +104,8 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -99,6 +104,8 @@ int GpuMain(const content::MainFunctionParams& parameters) {
command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
content::GetContentClient()->SetGpuInfo(gpu_info); content::GetContentClient()->SetGpuInfo(gpu_info);
// We need to track that information for the WarmUpSandbox function.
bool initialized_gl_context = false;
// Load and initialize the GL implementation and locate the GL entry points. // Load and initialize the GL implementation and locate the GL entry points.
if (gfx::GLSurface::InitializeOneOff()) { if (gfx::GLSurface::InitializeOneOff()) {
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -108,9 +115,9 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -108,9 +115,9 @@ int GpuMain(const content::MainFunctionParams& parameters) {
// However, on Linux, we may not have enough info for blacklisting. // However, on Linux, we may not have enough info for blacklisting.
if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id || if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id ||
gpu_info.driver_vendor.empty() || gpu_info.driver_version.empty()) { gpu_info.driver_vendor.empty() || gpu_info.driver_version.empty()) {
if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) CollectGraphicsInfo(&gpu_info);
VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; // We know that CollectGraphicsInfo will initialize a GLContext.
content::GetContentClient()->SetGpuInfo(gpu_info); initialized_gl_context = true;
} }
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
...@@ -133,19 +140,10 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -133,19 +140,10 @@ int GpuMain(const content::MainFunctionParams& parameters) {
} }
{ {
TRACE_EVENT0("gpu", "Warm up rand"); const bool should_initialize_gl_context = !initialized_gl_context &&
// Warm up the random subsystem, which needs to be done pre-sandbox on all !dead_on_arrival;
// platforms. // Warm up the current process before enabling the sandbox.
(void) base::RandUint64(); WarmUpSandbox(gpu_info, should_initialize_gl_context);
}
{
TRACE_EVENT0("gpu", "Warm up HMAC");
// Warm up the crypto subsystem, which needs to done pre-sandbox on all
// platforms.
crypto::HMAC hmac(crypto::HMAC::SHA256);
unsigned char key = '\0';
bool ret = hmac.Init(&key, sizeof(key));
(void) ret;
} }
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -153,12 +151,6 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -153,12 +151,6 @@ int GpuMain(const content::MainFunctionParams& parameters) {
TRACE_EVENT0("gpu", "Initialize sandbox"); TRACE_EVENT0("gpu", "Initialize sandbox");
bool do_init_sandbox = true; bool do_init_sandbox = true;
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
OmxVideoDecodeAccelerator::PreSandboxInitialization();
#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
VaapiVideoDecodeAccelerator::PreSandboxInitialization();
#endif
#if defined(OS_CHROMEOS) && defined(NDEBUG) #if defined(OS_CHROMEOS) && defined(NDEBUG)
// On Chrome OS and when not on a debug build, initialize // On Chrome OS and when not on a debug build, initialize
// the GPU process' sandbox only for Intel GPUs. // the GPU process' sandbox only for Intel GPUs.
...@@ -171,24 +163,7 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -171,24 +163,7 @@ int GpuMain(const content::MainFunctionParams& parameters) {
} }
#endif #endif
{
TRACE_EVENT0("gpu", "Initialize COM");
base::win::ScopedCOMInitializer com_initializer;
}
#if defined(OS_WIN) #if defined(OS_WIN)
{
TRACE_EVENT0("gpu", "Preload setupapi.dll");
// Preload this DLL because the sandbox prevents it from loading.
LoadLibrary(L"setupapi.dll");
}
{
TRACE_EVENT0("gpu", "Initialize DXVA");
// Initialize H/W video decoding stuff which fails in the sandbox.
DXVAVideoDecodeAccelerator::PreSandboxInitialization();
}
{ {
TRACE_EVENT0("gpu", "Lower token"); TRACE_EVENT0("gpu", "Lower token");
// For windows, if the target_services interface is not zero, the process // For windows, if the target_services interface is not zero, the process
...@@ -235,3 +210,94 @@ int GpuMain(const content::MainFunctionParams& parameters) { ...@@ -235,3 +210,94 @@ int GpuMain(const content::MainFunctionParams& parameters) {
return 0; return 0;
} }
namespace {
void CreateDummyGlContext() {
scoped_refptr<gfx::GLSurface> surface(
gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)));
if (!surface.get()) {
VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
return;
}
// On Linux, this is needed to make sure /dev/nvidiactl has
// been opened and its descriptor cached.
scoped_refptr<gfx::GLContext> context(
gfx::GLContext::CreateGLContext(NULL,
surface,
gfx::PreferDiscreteGpu));
if (!context.get()) {
VLOG(1) << "gfx::GLContext::CreateGLContext failed";
return;
}
// Similarly, this is needed for /dev/nvidia0.
if (context->MakeCurrent(surface)) {
context->ReleaseCurrent(surface.get());
} else {
VLOG(1) << "gfx::GLContext::MakeCurrent failed";
}
}
void WarmUpSandbox(const content::GPUInfo& gpu_info,
bool should_initialize_gl_context) {
{
TRACE_EVENT0("gpu", "Warm up rand");
// Warm up the random subsystem, which needs to be done pre-sandbox on all
// platforms.
(void) base::RandUint64();
}
{
TRACE_EVENT0("gpu", "Warm up HMAC");
// Warm up the crypto subsystem, which needs to done pre-sandbox on all
// platforms.
crypto::HMAC hmac(crypto::HMAC::SHA256);
unsigned char key = '\0';
bool ret = hmac.Init(&key, sizeof(key));
(void) ret;
}
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
OmxVideoDecodeAccelerator::PreSandboxInitialization();
#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
VaapiVideoDecodeAccelerator::PreSandboxInitialization();
#endif
#if defined(OS_LINUX)
if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
gpu_info.driver_vendor == "NVIDIA" &&
should_initialize_gl_context) {
// We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
CreateDummyGlContext();
}
#endif
{
TRACE_EVENT0("gpu", "Initialize COM");
base::win::ScopedCOMInitializer com_initializer;
}
#if defined(OS_WIN)
{
TRACE_EVENT0("gpu", "Preload setupapi.dll");
// Preload this DLL because the sandbox prevents it from loading.
LoadLibrary(L"setupapi.dll");
}
{
TRACE_EVENT0("gpu", "Initialize DXVA");
// Initialize H/W video decoding stuff which fails in the sandbox.
DXVAVideoDecodeAccelerator::PreSandboxInitialization();
}
#endif
}
void CollectGraphicsInfo(content::GPUInfo* gpu_info) {
if (!gpu_info_collector::CollectGraphicsInfo(gpu_info))
VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed";
content::GetContentClient()->SetGpuInfo(*gpu_info);
}
} // namespace.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment