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