1 /*
2 **
3 ** Copyright 2015, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 //
19 // Helper class to perform cpu setup (if needed) prior to a profile collection.
20 //
21 class HardwireCpuHelper {
22  public:
23 
24   // The constructor for this class checks to see if the 'mpdecision'
25   // service is running; if so (and if 'perform' is TRUE), then it
26   // disables the service and on-lines all of the available cores/cpus
27   // (anything listed in /sys/devices/system/cpu/possible). The
28   // destructor will re-enable the mpdecision service if it was
29   // previously disabled.
30   HardwireCpuHelper(bool perform);
31   virtual ~HardwireCpuHelper();
32 
33  private:
34   bool mpdecision_stopped_;
35 
36   // Collect the number of available cpus/cores from /sys/devices/system/cpu/possible
37   int GetNumCores();
38 
39   // Returns TRUE if the system service 'mpdecision' is running
40   bool GetMpdecisionRunning();
41 
42   // Online/offline the specified cpu
43   void OnlineCore(int whichCore, int onoff);
44 
45   // Enable/disable the mpdecision service via the equivalent of
46   //   setprop ctl.start mpdecision
47   //   setprop ctl.stop mpdecision
48   void StopMpdecision();
49   void RestartMpdecision();
50 };
51