Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 1 | // Copyright 2019 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 | #ifndef CHROME_BROWSER_CHROMEOS_SCHEDULER_CONFIGURATION_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_SCHEDULER_CONFIGURATION_MANAGER_H_ |
| 7 | |
Yusuke Sato | 1eab4d2 | 2019-10-03 05:39:01 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "base/memory/weak_ptr.h" |
Yusuke Sato | 1eab4d2 | 2019-10-03 05:39:01 | [diff] [blame] | 12 | #include "base/optional.h" |
Yusuke Sato | 17784796 | 2019-09-30 19:45:33 | [diff] [blame] | 13 | #include "chromeos/system/scheduler_configuration_manager_base.h" |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 14 | #include "components/prefs/pref_change_registrar.h" |
| 15 | |
| 16 | class PrefRegistrySimple; |
| 17 | class PrefService; |
| 18 | |
| 19 | namespace chromeos { |
| 20 | |
| 21 | class DebugDaemonClient; |
| 22 | |
| 23 | // Tracks scheduler configuration as provided by the respective local state pref |
| 24 | // and sends D-Bus IPC to reconfigure the system on config changes. |
Greg Kerr | 33cd466 | 2019-06-17 07:03:01 | [diff] [blame] | 25 | // |
| 26 | // This is the policy to enable and disable Hyper-Threading (H/T) on Intel CPUs. |
| 27 | // Conservative -> Hyper-Threading disabled. |
| 28 | // Performance -> Hyper-Threading enabled. |
| 29 | // For more information on why H/T is configurable, see |
| 30 | // https://www.chromium.org/chromium-os/mds-on-chromeos |
| 31 | // |
Yusuke Sato | 17784796 | 2019-09-30 19:45:33 | [diff] [blame] | 32 | class SchedulerConfigurationManager : public SchedulerConfigurationManagerBase { |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 33 | public: |
| 34 | SchedulerConfigurationManager(DebugDaemonClient* debug_daemon_client, |
| 35 | PrefService* local_state); |
Yusuke Sato | 17784796 | 2019-09-30 19:45:33 | [diff] [blame] | 36 | ~SchedulerConfigurationManager() override; |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 37 | |
| 38 | static void RegisterLocalStatePrefs(PrefRegistrySimple* registry); |
| 39 | |
Yusuke Sato | 1eab4d2 | 2019-10-03 05:39:01 | [diff] [blame] | 40 | // SchedulerConfigurationManagerBase overrides: |
| 41 | base::Optional<std::pair<bool, size_t>> GetLastReply() const override; |
| 42 | |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 43 | private: |
| 44 | void OnDebugDaemonReady(bool service_is_ready); |
| 45 | void OnPrefChange(); |
Yusuke Sato | a29dbe4 | 2019-09-30 18:11:16 | [diff] [blame] | 46 | void OnConfigurationSet(bool result, size_t num_cores_disabled); |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 47 | |
| 48 | DebugDaemonClient* debug_daemon_client_ = nullptr; |
| 49 | PrefChangeRegistrar observer_; |
| 50 | bool debug_daemon_ready_ = false; |
Yusuke Sato | 1eab4d2 | 2019-10-03 05:39:01 | [diff] [blame] | 51 | base::Optional<std::pair<bool, size_t>> last_reply_; |
| 52 | |
Mattias Nissler | 980f2aa5 | 2019-02-13 13:21:49 | [diff] [blame] | 53 | base::WeakPtrFactory<SchedulerConfigurationManager> weak_ptr_factory_{this}; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(SchedulerConfigurationManager); |
| 56 | }; |
| 57 | |
| 58 | } // namespace chromeos |
| 59 | |
| 60 | #endif // CHROME_BROWSER_CHROMEOS_SCHEDULER_CONFIGURATION_MANAGER_H_ |