Commit f4090186 authored by Brian Geffon's avatar Brian Geffon Committed by Commit Bot

CrOS: Add a feature and code to enable core scheduling for renderers

This change allows core scheduling to be turned on when renderers
start and before entering the sandbox. By doing it before entering the
sandbox it cannot be disabled. There is a flag we can use to disable
this if necessary via a finch kill switch should bugs in the kernel
be encountered.

BUG=b:152605392

Change-Id: I0f3b81a03eac2e3603bff8514e0c58e0d4e286c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2140066Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757541}
parent a3a082b8
...@@ -9,9 +9,12 @@ component("system") { ...@@ -9,9 +9,12 @@ component("system") {
defines = [ "IS_CHROMEOS_SYSTEM_IMPL" ] defines = [ "IS_CHROMEOS_SYSTEM_IMPL" ]
deps = [ deps = [
"//base", "//base",
"//chromeos:chromeos_export",
"//chromeos/constants", "//chromeos/constants",
] ]
sources = [ sources = [
"core_scheduling.cc",
"core_scheduling.h",
"cpu_temperature_reader.cc", "cpu_temperature_reader.cc",
"cpu_temperature_reader.h", "cpu_temperature_reader.h",
"devicemode.cc", "devicemode.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/system/core_scheduling.h"
#include <base/logging.h>
#include <errno.h>
#include <sys/prctl.h>
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#ifndef PR_SET_CORE_SCHED
#define PR_SET_CORE_SCHED 57
#endif
namespace chromeos {
namespace system {
namespace {
const base::Feature kCoreScheduling{"CoreSchedulingEnabled",
base::FEATURE_ENABLED_BY_DEFAULT};
}
void EnableCoreSchedulingIfAvailable() {
if (!base::FeatureList::IsEnabled(kCoreScheduling)) {
return;
}
if (prctl(PR_SET_CORE_SCHED, 1) == -1) {
// prctl(2) will return EINVAL for unknown functions. We're tolerant to this
// and will log an error message for non EINVAL errnos.
PLOG_IF(WARNING, errno != EINVAL) << "Unable to set core scheduling";
}
}
} // namespace system
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SYSTEM_CORE_SCHEDULING_H_
#define CHROMEOS_SYSTEM_CORE_SCHEDULING_H_
#include "chromeos/chromeos_export.h"
namespace chromeos {
namespace system {
// EnableCoreScheduVlingIfAvailable will turn on core scheduling for a process
// if it's available,
void CHROMEOS_EXPORT EnableCoreSchedulingIfAvailable();
} // namespace system
} // namespace chromeos
#endif // CHROMEOS_SYSTEM_CORE_SCHEDULING_H_
...@@ -344,6 +344,17 @@ source_set("common") { ...@@ -344,6 +344,17 @@ source_set("common") {
libs += [ "android" ] libs += [ "android" ]
} }
if (is_chromeos) {
sources += [
"//chromeos/system/core_scheduling.cc",
"//chromeos/system/core_scheduling.h",
]
deps += [
"//chromeos:chromeos_export",
"//chromeos/system",
]
}
if (is_debug && !is_component_build && enable_plugins) { if (is_debug && !is_component_build && enable_plugins) {
# Content depends on the PPAPI message logging stuff; if this isn't here, # Content depends on the PPAPI message logging stuff; if this isn't here,
# some unit test binaries won't compile. This only worked in release mode # some unit test binaries won't compile. This only worked in release mode
......
...@@ -16,6 +16,7 @@ include_rules = [ ...@@ -16,6 +16,7 @@ include_rules = [
# If adding a new component dependency, email content/OWNERS first. # If adding a new component dependency, email content/OWNERS first.
# **************************************************************************** # ****************************************************************************
"+chromeos/system/core_scheduling.h",
"+content/public/child", "+content/public/child",
"+content/public/renderer", "+content/public/renderer",
"+content/child", "+content/child",
......
...@@ -57,6 +57,10 @@ ...@@ -57,6 +57,10 @@
#include "third_party/blink/public/web/web_view.h" #include "third_party/blink/public/web/web_view.h"
#endif // OS_MACOSX #endif // OS_MACOSX
#if defined(OS_CHROMEOS)
#include "chromeos/system/core_scheduling.h"
#endif // OS_CHROMEOS
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
#include "content/renderer/pepper/pepper_plugin_registry.h" #include "content/renderer/pepper/pepper_plugin_registry.h"
#endif #endif
...@@ -121,6 +125,10 @@ int RendererMain(const MainFunctionParams& parameters) { ...@@ -121,6 +125,10 @@ int RendererMain(const MainFunctionParams& parameters) {
command_line.GetSwitchValueASCII(switches::kLang); command_line.GetSwitchValueASCII(switches::kLang);
base::i18n::SetICUDefaultLocale(locale); base::i18n::SetICUDefaultLocale(locale);
} }
// When we start the renderer on ChromeOS if the system has core scheduling
// available we want to turn it on.
chromeos::system::EnableCoreSchedulingIfAvailable();
#endif #endif
InitializeSkia(); InitializeSkia();
......
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