New upstream version 18.08
[deb_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 /* Maximum number of CPUS to manage */
36 #define POWER_MGR_MAX_CPUS 64
37 /**
38  * Initialize power management.
39  * Initializes resources and verifies the number of CPUs on the system.
40  * Wraps librte_power int rte_power_init(unsigned lcore_id);
41  *
42  * @return
43  *  - 0 on success.
44  *  - Negative on error.
45  */
46 int power_manager_init(void);
47
48 /**
49  * Exit power management. Must be called prior to exiting the application.
50  *
51  * @return
52  *  - 0 on success.
53  *  - Negative on error.
54  */
55 int power_manager_exit(void);
56
57 /**
58  * Scale up the frequency of the cores specified in core_mask.
59  * It is thread-safe.
60  *
61  * @param core_mask
62  *  The uint64_t bit-mask of cores to change frequency.
63  *
64  * @return
65  *  - 1 on success.
66  *  - Negative on error.
67  */
68 int power_manager_scale_mask_up(uint64_t core_mask);
69
70 /**
71  * Scale down the frequency of the cores specified in core_mask.
72  * It is thread-safe.
73  *
74  * @param core_mask
75  *  The uint64_t bit-mask of cores to change frequency.
76  *
77  * @return
78  *  - 1 on success.
79  *  - Negative on error.
80  */
81 int power_manager_scale_mask_down(uint64_t core_mask);
82
83 /**
84  * Scale to the minimum frequency of the cores specified in core_mask.
85  * It is thread-safe.
86  *
87  * @param core_mask
88  *  The uint64_t bit-mask of cores to change frequency.
89  *
90  * @return
91  *  - 1 on success.
92  *  - Negative on error.
93  */
94 int power_manager_scale_mask_min(uint64_t core_mask);
95
96 /**
97  * Scale to the maximum frequency of the cores specified in core_mask.
98  * It is thread-safe.
99  *
100  * @param core_mask
101  *  The uint64_t bit-mask of cores to change frequency.
102  *
103  * @return
104  *  - 1 on success.
105  *  - Negative on error.
106  */
107 int power_manager_scale_mask_max(uint64_t core_mask);
108
109 /**
110  * Enable Turbo Boost on the cores specified in core_mask.
111  * It is thread-safe.
112  *
113  * @param core_mask
114  *  The uint64_t bit-mask of cores to change frequency.
115  *
116  * @return
117  *  - 1 on success.
118  *  - Negative on error.
119  */
120 int power_manager_enable_turbo_mask(uint64_t core_mask);
121
122 /**
123  * Disable Turbo Boost on the cores specified in core_mask.
124  * It is thread-safe.
125  *
126  * @param core_mask
127  *  The uint64_t bit-mask of cores to change frequency.
128  *
129  * @return
130  *  - 1 on success.
131  *  - Negative on error.
132  */
133 int power_manager_disable_turbo_mask(uint64_t core_mask);
134
135 /**
136  * Scale up frequency for the core specified by core_num.
137  * It is thread-safe.
138  *
139  * @param core_num
140  *  The core number to change frequency
141  *
142  * @return
143  *  - 1 on success.
144  *  - Negative on error.
145  */
146 int power_manager_scale_core_up(unsigned core_num);
147
148 /**
149  * Scale down frequency for the core specified by core_num.
150  * It is thread-safe.
151  *
152  * @param core_num
153  *  The core number to change frequency
154  *
155  * @return
156  *  - 1 on success.
157  *  - 0 if frequency not changed.
158  *  - Negative on error.
159  */
160 int power_manager_scale_core_down(unsigned core_num);
161
162 /**
163  * Scale to minimum frequency for the core specified by core_num.
164  * It is thread-safe.
165  *
166  * @param core_num
167  *  The core number to change frequency
168  *
169  * @return
170  *  - 1 on success.
171  *  - 0 if frequency not changed.
172  *  - Negative on error.
173  */
174 int power_manager_scale_core_min(unsigned core_num);
175
176 /**
177  * Scale to maximum frequency for the core specified by core_num.
178  * It is thread-safe.
179  *
180  * @param core_num
181  *  The core number to change frequency
182  *
183  * @return
184  *  - 1 on success.
185  *  - 0 if frequency not changed.
186  *  - Negative on error.
187  */
188 int power_manager_scale_core_max(unsigned core_num);
189
190 /**
191  * Enable Turbo Boost for the core specified by core_num.
192  * It is thread-safe.
193  *
194  * @param core_num
195  *  The core number to boost
196  *
197  * @return
198  *  - 1 on success.
199  *  - Negative on error.
200  */
201 int power_manager_enable_turbo_core(unsigned int core_num);
202
203 /**
204  * Disable Turbo Boost for the core specified by core_num.
205  * It is thread-safe.
206  *
207  * @param core_num
208  *  The core number to boost
209  *
210  * @return
211  *  - 1 on success.
212  *  - Negative on error.
213  */
214 int power_manager_disable_turbo_core(unsigned int core_num);
215
216 /**
217  * Get the current freuency of the core specified by core_num
218  *
219  * @param core_num
220  *  The core number to get the current frequency
221  *
222  * @return
223  *  - 0  on error
224  *  - >0 for current frequency.
225  */
226 uint32_t power_manager_get_current_frequency(unsigned core_num);
227
228 /**
229  * Scale to medium frequency for the core specified by core_num.
230  * It is thread-safe.
231  *
232  * @param core_num
233  *  The core number to change frequency
234  *
235  * @return
236  *  - 1 on success.
237  *  - 0 if frequency not changed.
238  *  - Negative on error.
239  */
240 int power_manager_scale_core_med(unsigned int core_num);
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246
247 #endif /* POWER_MANAGER_H_ */