Ocean
platform/android/Processor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_ANDROID_PROCESSOR_H
9 #define META_OCEAN_PLATFORM_ANDROID_PROCESSOR_H
10 
12 
13 namespace Ocean
14 {
15 
16 namespace Platform
17 {
18 
19 namespace Android
20 {
21 
22 /**
23  * This class implements processor functions.
24  * @ingroup platformandroid
25  */
26 class OCEAN_PLATFORM_ANDROID_EXPORT Processor
27 {
28  public:
29 
30  /**
31  * Definition of a processor operation frequency.
32  */
33  typedef unsigned int Frequency;
34 
35  public:
36 
37  /**
38  * Returns an invalid frequency.
39  */
40  static constexpr Frequency invalidFrequency();
41 
42  /**
43  * Returns the number of installed CPU cores.
44  * @return Number of installed CPU cores, 0 if the number could not be determined
45  */
46  static unsigned int installedCores();
47 
48  /**
49  * Returns the current operation frequency of a specified core.
50  * @param core The core to return the current frequency for
51  * @return Frequency in kHz otherwise invalidFrequency
52  */
53  static Frequency currentFrequency(const unsigned int core = 0u);
54 
55  /**
56  * Returns the maximal operation frequency of a specified core.
57  * @param core The core to return the maximal frequency for
58  * @return Frequency in kHz otherwise invalidFrequency
59  */
60  static Frequency maxFrequency(const unsigned int core = 0u);
61 
62  /**
63  * Returns the minimal operation frequency of a specified core.
64  * @param core The core to return the minimal frequency for
65  * @return Frequency in kHz otherwise invalidFrequency
66  */
67  static Frequency minFrequency(const unsigned int core = 0u);
68 
69  /**
70  * Returns the CPU affinity of the current thread.
71  * The affinity defines on which CPU cores the thread is allowed to run.
72  * @param cpuMask The affinity mask, each bit is associated with the corresponding CPU
73  * @return True, if succeeded
74  */
75  static bool currentThreadAffinity(uint32_t& cpuMask);
76 
77  /**
78  * Sets the CPU affinity of the current thread.
79  * The affinity defines on which CPU cores the thread is allowed to run.<br>
80  * Beware: Depending on the Android device, setting CPU affinity may not be allowed, or may be restricted to a subset of all cores.
81  * @param cpuMask The affinity mask, each bit is associated with the corresponding CPU
82  * @return True, if succeeded
83  */
84  static bool setCurrentThreadAffinity(const uint32_t cpuMask);
85 
86  /**
87  * Sets the CPU affinity of the current thread.
88  * The affinity defines on which CPU cores the thread is allowed to run.<br>
89  * This function allows to specify a range of CPUs (not a mask).
90  * Beware: Depending on the Android device, setting CPU affinity may not be allowed, or may be restricted to a subset of all cores.
91  * @param firstCPU The index of the first CPU to set, with range [0, 31]
92  * @param lastCPU The index of the last (including) CPU to set, with range [firstCPU, 31]
93  * @return True, if succeeded
94  */
95  static bool setCurrentThreadAffinity(const unsigned int firstCPU, const unsigned int lastCPU);
96 };
97 
99 {
100  return Frequency(-1);
101 }
102 
103 }
104 
105 }
106 
107 }
108 
109 #endif // META_OCEAN_PLATFORM_ANDROID_PROCESSOR_H
This class implements processor functions.
Definition: platform/android/Processor.h:27
static bool setCurrentThreadAffinity(const uint32_t cpuMask)
Sets the CPU affinity of the current thread.
static bool currentThreadAffinity(uint32_t &cpuMask)
Returns the CPU affinity of the current thread.
static Frequency minFrequency(const unsigned int core=0u)
Returns the minimal operation frequency of a specified core.
unsigned int Frequency
Definition of a processor operation frequency.
Definition: platform/android/Processor.h:33
static constexpr Frequency invalidFrequency()
Returns an invalid frequency.
Definition: platform/android/Processor.h:98
static Frequency maxFrequency(const unsigned int core=0u)
Returns the maximal operation frequency of a specified core.
static bool setCurrentThreadAffinity(const unsigned int firstCPU, const unsigned int lastCPU)
Sets the CPU affinity of the current thread.
static Frequency currentFrequency(const unsigned int core=0u)
Returns the current operation frequency of a specified core.
static unsigned int installedCores()
Returns the number of installed CPU cores.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15