• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <sched.h>
20 
21 #include <vector>
22 #include <map>
23 #include <string>
24 
25 namespace swappy {
26 
27 class CpuInfo {
28 public:
29     struct Cpu {
30         enum class Type {
31             Little,
32             Big
33         };
34 
35         int id;
36         int package_id;
37         long frequency;
38 
39         Type type;
40     };
41 
42     CpuInfo();
43 
44     unsigned int getNumberOfCpus() const;
45 
46     const std::vector<Cpu>& getCpus() const;
47     const std::string getHardware() const;
48 
49     unsigned int getNumberOfLittleCores() const;
50     unsigned int getNumberOfBigCores() const;
51 
52     cpu_set_t getLittleCoresMask() const;
53     cpu_set_t getBigCoresMask() const;
54 
55 private:
56     std::vector<Cpu> mCpus;
57     std::string mHardware;
58 
59     long mMaxFrequency;
60     long mMinFrequency;
61 
62     unsigned int mNumberOfLittleCores = 0;
63     unsigned int mNumberOfBigCores = 0;
64 
65     cpu_set_t mLittleCoresMask;
66     cpu_set_t mBigCoresMask;
67 };
68 
69 unsigned int to_mask(cpu_set_t cpu_set);
70 
71 } // namespace swappy
72