e81a60ae54ca62719b1747c6a3fc2d84d05940c5
[dpdk.git] / examples / vm_power_manager / power_manager.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef POWER_MANAGER_H_
6 #define POWER_MANAGER_H_
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 struct core_details {
12         uint64_t last_branches;
13         uint64_t last_branch_misses;
14         uint16_t global_enabled_cpus;
15         uint16_t oob_enabled;
16         int msr_fd;
17 };
18
19 struct core_info {
20         uint16_t core_count;
21         struct core_details *cd;
22         float branch_ratio_threshold;
23 };
24
25 #define BRANCH_RATIO_THRESHOLD 0.1
26
27 struct core_info *
28 get_core_info(void);
29
30 int
31 core_info_init(void);
32
33 #define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
34
35 /**
36  * Initialize power management.
37  * Initializes resources and verifies the number of CPUs on the system.
38  * Wraps librte_power int rte_power_init(unsigned lcore_id);
39  *
40  * @return
41  *  - 0 on success.
42  *  - Negative on error.
43  */
44 int power_manager_init(void);
45
46 /**
47  * Exit power management. Must be called prior to exiting the application.
48  *
49  * @return
50  *  - 0 on success.
51  *  - Negative on error.
52  */
53 int power_manager_exit(void);
54
55 /**
56  * Scale up the frequency of the cores specified in core_mask.
57  * It is thread-safe.
58  *
59  * @param core_mask
60  *  The uint64_t bit-mask of cores to change frequency.
61  *
62  * @return
63  *  - 1 on success.
64  *  - Negative on error.
65  */
66 int power_manager_scale_mask_up(uint64_t core_mask);
67
68 /**
69  * Scale down the frequency of the cores specified in core_mask.
70  * It is thread-safe.
71  *
72  * @param core_mask
73  *  The uint64_t bit-mask of cores to change frequency.
74  *
75  * @return
76  *  - 1 on success.
77  *  - Negative on error.
78  */
79 int power_manager_scale_mask_down(uint64_t core_mask);
80
81 /**
82  * Scale to the minimum frequency of the cores specified in core_mask.
83  * It is thread-safe.
84  *
85  * @param core_mask
86  *  The uint64_t bit-mask of cores to change frequency.
87  *
88  * @return
89  *  - 1 on success.
90  *  - Negative on error.
91  */
92 int power_manager_scale_mask_min(uint64_t core_mask);
93
94 /**
95  * Scale to the maximum frequency of the cores specified in core_mask.
96  * It is thread-safe.
97  *
98  * @param core_mask
99  *  The uint64_t bit-mask of cores to change frequency.
100  *
101  * @return
102  *  - 1 on success.
103  *  - Negative on error.
104  */
105 int power_manager_scale_mask_max(uint64_t core_mask);
106
107 /**
108  * Enable Turbo Boost on the cores specified in core_mask.
109  * It is thread-safe.
110  *
111  * @param core_mask
112  *  The uint64_t bit-mask of cores to change frequency.
113  *
114  * @return
115  *  - 1 on success.
116  *  - Negative on error.
117  */
118 int power_manager_enable_turbo_mask(uint64_t core_mask);
119
120 /**
121  * Disable Turbo Boost on the cores specified in core_mask.
122  * It is thread-safe.
123  *
124  * @param core_mask
125  *  The uint64_t bit-mask of cores to change frequency.
126  *
127  * @return
128  *  - 1 on success.
129  *  - Negative on error.
130  */
131 int power_manager_disable_turbo_mask(uint64_t core_mask);
132
133 /**
134  * Scale up frequency for the core specified by core_num.
135  * It is thread-safe.
136  *
137  * @param core_num
138  *  The core number to change frequency
139  *
140  * @return
141  *  - 1 on success.
142  *  - Negative on error.
143  */
144 int power_manager_scale_core_up(unsigned core_num);
145
146 /**
147  * Scale down frequency for the core specified by core_num.
148  * It is thread-safe.
149  *
150  * @param core_num
151  *  The core number to change frequency
152  *
153  * @return
154  *  - 1 on success.
155  *  - 0 if frequency not changed.
156  *  - Negative on error.
157  */
158 int power_manager_scale_core_down(unsigned core_num);
159
160 /**
161  * Scale to minimum frequency for the core specified by core_num.
162  * It is thread-safe.
163  *
164  * @param core_num
165  *  The core number to change frequency
166  *
167  * @return
168  *  - 1 on success.
169  *  - 0 if frequency not changed.
170  *  - Negative on error.
171  */
172 int power_manager_scale_core_min(unsigned core_num);
173
174 /**
175  * Scale to maximum frequency for the core specified by core_num.
176  * It is thread-safe.
177  *
178  * @param core_num
179  *  The core number to change frequency
180  *
181  * @return
182  *  - 1 on success.
183  *  - 0 if frequency not changed.
184  *  - Negative on error.
185  */
186 int power_manager_scale_core_max(unsigned core_num);
187
188 /**
189  * Enable Turbo Boost for the core specified by core_num.
190  * It is thread-safe.
191  *
192  * @param core_num
193  *  The core number to boost
194  *
195  * @return
196  *  - 1 on success.
197  *  - Negative on error.
198  */
199 int power_manager_enable_turbo_core(unsigned int core_num);
200
201 /**
202  * Disable Turbo Boost for the core specified by core_num.
203  * It is thread-safe.
204  *
205  * @param core_num
206  *  The core number to boost
207  *
208  * @return
209  *  - 1 on success.
210  *  - Negative on error.
211  */
212 int power_manager_disable_turbo_core(unsigned int core_num);
213
214 /**
215  * Get the current freuency of the core specified by core_num
216  *
217  * @param core_num
218  *  The core number to get the current frequency
219  *
220  * @return
221  *  - 0  on error
222  *  - >0 for current frequency.
223  */
224 uint32_t power_manager_get_current_frequency(unsigned core_num);
225
226 /**
227  * Scale to medium frequency for the core specified by core_num.
228  * It is thread-safe.
229  *
230  * @param core_num
231  *  The core number to change frequency
232  *
233  * @return
234  *  - 1 on success.
235  *  - 0 if frequency not changed.
236  *  - Negative on error.
237  */
238 int power_manager_scale_core_med(unsigned int core_num);
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244
245 #endif /* POWER_MANAGER_H_ */