1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chromeos/system/core_scheduling.h"
6 
7 #include <base/logging.h>
8 #include <errno.h>
9 #include <sys/prctl.h>
10 
11 #include "base/feature_list.h"
12 #include "base/metrics/field_trial_params.h"
13 
14 #ifndef PR_SET_CORE_SCHED
15 // Setup core-scheduling for the task.
16 // TODO(b/152605392): Replace this once upstream interface is known.
17 #define PR_SET_CORE_SCHED 0x200
18 #endif
19 
20 namespace chromeos {
21 namespace system {
22 
23 namespace {
24 const base::Feature kCoreScheduling{"CoreSchedulingEnabled",
25                                     base::FEATURE_DISABLED_BY_DEFAULT};
26 }
27 
EnableCoreSchedulingIfAvailable()28 void EnableCoreSchedulingIfAvailable() {
29   if (!base::FeatureList::IsEnabled(kCoreScheduling)) {
30     return;
31   }
32 
33   if (prctl(PR_SET_CORE_SCHED, 1) == -1) {
34     // prctl(2) will return EINVAL for unknown functions. We're tolerant to this
35     // and will log an error message for non EINVAL errnos.
36     PLOG_IF(WARNING, errno != EINVAL) << "Unable to set core scheduling";
37   }
38 }
39 
40 }  // namespace system
41 }  // namespace chromeos
42