]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2010-2014 Intel Corporation | |
7c673cae FG |
3 | */ |
4 | ||
5 | #ifndef _RTE_POWER_H | |
6 | #define _RTE_POWER_H | |
7 | ||
8 | /** | |
9 | * @file | |
10 | * RTE Power Management | |
11 | */ | |
12 | ||
13 | #include <rte_common.h> | |
14 | #include <rte_byteorder.h> | |
15 | #include <rte_log.h> | |
16 | #include <rte_string_fns.h> | |
17 | ||
18 | #ifdef __cplusplus | |
19 | extern "C" { | |
20 | #endif | |
21 | ||
22 | /* Power Management Environment State */ | |
9f95a23c TL |
23 | enum power_management_env {PM_ENV_NOT_SET, PM_ENV_ACPI_CPUFREQ, PM_ENV_KVM_VM, |
24 | PM_ENV_PSTATE_CPUFREQ}; | |
7c673cae FG |
25 | |
26 | /** | |
27 | * Set the default power management implementation. If this is not called prior | |
28 | * to rte_power_init(), then auto-detect of the environment will take place. | |
9f95a23c TL |
29 | * It is thread safe. New env can be set only in unitialized state |
30 | * (thus rte_power_unset_env must be called if different env was already set). | |
7c673cae FG |
31 | * |
32 | * @param env | |
33 | * env. The environment in which to initialise Power Management for. | |
34 | * | |
35 | * @return | |
36 | * - 0 on success. | |
37 | * - Negative on error. | |
38 | */ | |
39 | int rte_power_set_env(enum power_management_env env); | |
40 | ||
41 | /** | |
42 | * Unset the global environment configuration. | |
43 | * This can only be called after all threads have completed. | |
44 | */ | |
45 | void rte_power_unset_env(void); | |
46 | ||
47 | /** | |
48 | * Get the default power management implementation. | |
49 | * | |
50 | * @return | |
51 | * power_management_env The configured environment. | |
52 | */ | |
53 | enum power_management_env rte_power_get_env(void); | |
54 | ||
55 | /** | |
56 | * Initialize power management for a specific lcore. If rte_power_set_env() has | |
57 | * not been called then an auto-detect of the environment will start and | |
58 | * initialise the corresponding resources. | |
59 | * | |
60 | * @param lcore_id | |
61 | * lcore id. | |
62 | * | |
63 | * @return | |
64 | * - 0 on success. | |
65 | * - Negative on error. | |
66 | */ | |
9f95a23c | 67 | int rte_power_init(unsigned int lcore_id); |
7c673cae FG |
68 | |
69 | /** | |
70 | * Exit power management on a specific lcore. This will call the environment | |
71 | * dependent exit function. | |
72 | * | |
73 | * @param lcore_id | |
74 | * lcore id. | |
75 | * | |
76 | * @return | |
77 | * - 0 on success. | |
78 | * - Negative on error. | |
79 | */ | |
9f95a23c | 80 | int rte_power_exit(unsigned int lcore_id); |
7c673cae FG |
81 | |
82 | /** | |
83 | * Get the available frequencies of a specific lcore. | |
84 | * Function pointer definition. Review each environments | |
85 | * specific documentation for usage. | |
86 | * | |
87 | * @param lcore_id | |
88 | * lcore id. | |
89 | * @param freqs | |
90 | * The buffer array to save the frequencies. | |
91 | * @param num | |
92 | * The number of frequencies to get. | |
93 | * | |
94 | * @return | |
95 | * The number of available frequencies. | |
96 | */ | |
9f95a23c | 97 | typedef uint32_t (*rte_power_freqs_t)(unsigned int lcore_id, uint32_t *freqs, |
7c673cae FG |
98 | uint32_t num); |
99 | ||
100 | extern rte_power_freqs_t rte_power_freqs; | |
101 | ||
102 | /** | |
103 | * Return the current index of available frequencies of a specific lcore. | |
104 | * Function pointer definition. Review each environments | |
105 | * specific documentation for usage. | |
106 | * | |
107 | * @param lcore_id | |
108 | * lcore id. | |
109 | * | |
110 | * @return | |
111 | * The current index of available frequencies. | |
112 | */ | |
9f95a23c | 113 | typedef uint32_t (*rte_power_get_freq_t)(unsigned int lcore_id); |
7c673cae FG |
114 | |
115 | extern rte_power_get_freq_t rte_power_get_freq; | |
116 | ||
117 | /** | |
118 | * Set the new frequency for a specific lcore by indicating the index of | |
119 | * available frequencies. | |
120 | * Function pointer definition. Review each environments | |
121 | * specific documentation for usage. | |
122 | * | |
123 | * @param lcore_id | |
124 | * lcore id. | |
125 | * @param index | |
126 | * The index of available frequencies. | |
127 | * | |
128 | * @return | |
129 | * - 1 on success with frequency changed. | |
130 | * - 0 on success without frequency changed. | |
131 | * - Negative on error. | |
132 | */ | |
9f95a23c | 133 | typedef int (*rte_power_set_freq_t)(unsigned int lcore_id, uint32_t index); |
7c673cae FG |
134 | |
135 | extern rte_power_set_freq_t rte_power_set_freq; | |
136 | ||
137 | /** | |
138 | * Function pointer definition for generic frequency change functions. Review | |
139 | * each environments specific documentation for usage. | |
140 | * | |
141 | * @param lcore_id | |
142 | * lcore id. | |
143 | * | |
144 | * @return | |
145 | * - 1 on success with frequency changed. | |
146 | * - 0 on success without frequency changed. | |
147 | * - Negative on error. | |
148 | */ | |
9f95a23c | 149 | typedef int (*rte_power_freq_change_t)(unsigned int lcore_id); |
7c673cae FG |
150 | |
151 | /** | |
152 | * Scale up the frequency of a specific lcore according to the available | |
153 | * frequencies. | |
154 | * Review each environments specific documentation for usage. | |
155 | * | |
156 | * @param lcore_id | |
157 | * lcore id. | |
158 | * | |
159 | * @return | |
160 | * - 1 on success with frequency changed. | |
161 | * - 0 on success without frequency changed. | |
162 | * - Negative on error. | |
163 | */ | |
164 | extern rte_power_freq_change_t rte_power_freq_up; | |
165 | ||
166 | /** | |
167 | * Scale down the frequency of a specific lcore according to the available | |
168 | * frequencies. | |
169 | * Review each environments specific documentation for usage. | |
170 | * | |
171 | * @param lcore_id | |
172 | * lcore id. | |
173 | * | |
174 | * @return | |
175 | * - 1 on success with frequency changed. | |
176 | * - 0 on success without frequency changed. | |
177 | * - Negative on error. | |
178 | */ | |
179 | ||
180 | extern rte_power_freq_change_t rte_power_freq_down; | |
181 | ||
182 | /** | |
183 | * Scale up the frequency of a specific lcore to the highest according to the | |
184 | * available frequencies. | |
185 | * Review each environments specific documentation for usage. | |
186 | * | |
187 | * @param lcore_id | |
188 | * lcore id. | |
189 | * | |
190 | * @return | |
191 | * - 1 on success with frequency changed. | |
192 | * - 0 on success without frequency changed. | |
193 | * - Negative on error. | |
194 | */ | |
195 | extern rte_power_freq_change_t rte_power_freq_max; | |
196 | ||
197 | /** | |
198 | * Scale down the frequency of a specific lcore to the lowest according to the | |
199 | * available frequencies. | |
200 | * Review each environments specific documentation for usage.. | |
201 | * | |
202 | * @param lcore_id | |
203 | * lcore id. | |
204 | * | |
205 | * @return | |
206 | * - 1 on success with frequency changed. | |
207 | * - 0 on success without frequency changed. | |
208 | * - Negative on error. | |
209 | */ | |
210 | extern rte_power_freq_change_t rte_power_freq_min; | |
211 | ||
9f95a23c TL |
212 | /** |
213 | * Query the Turbo Boost status of a specific lcore. | |
214 | * Review each environments specific documentation for usage.. | |
215 | * | |
216 | * @param lcore_id | |
217 | * lcore id. | |
218 | * | |
219 | * @return | |
220 | * - 1 Turbo Boost is enabled for this lcore. | |
221 | * - 0 Turbo Boost is disabled for this lcore. | |
222 | * - Negative on error. | |
223 | */ | |
224 | extern rte_power_freq_change_t rte_power_turbo_status; | |
225 | ||
226 | /** | |
227 | * Enable Turbo Boost for this lcore. | |
228 | * Review each environments specific documentation for usage.. | |
229 | * | |
230 | * @param lcore_id | |
231 | * lcore id. | |
232 | * | |
233 | * @return | |
234 | * - 0 on success. | |
235 | * - Negative on error. | |
236 | */ | |
237 | extern rte_power_freq_change_t rte_power_freq_enable_turbo; | |
238 | ||
239 | /** | |
240 | * Disable Turbo Boost for this lcore. | |
241 | * Review each environments specific documentation for usage.. | |
242 | * | |
243 | * @param lcore_id | |
244 | * lcore id. | |
245 | * | |
246 | * @return | |
247 | * - 0 on success. | |
248 | * - Negative on error. | |
249 | */ | |
250 | extern rte_power_freq_change_t rte_power_freq_disable_turbo; | |
251 | ||
252 | /** | |
253 | * Power capabilities summary. | |
254 | */ | |
255 | struct rte_power_core_capabilities { | |
256 | RTE_STD_C11 | |
257 | union { | |
258 | uint64_t capabilities; | |
259 | RTE_STD_C11 | |
260 | struct { | |
261 | uint64_t turbo:1; /**< Turbo can be enabled. */ | |
262 | uint64_t priority:1; /**< SST-BF high freq core */ | |
263 | }; | |
264 | }; | |
265 | }; | |
266 | ||
267 | /** | |
268 | * Returns power capabilities for a specific lcore. | |
269 | * Function pointer definition. Review each environments | |
270 | * specific documentation for usage. | |
271 | * | |
272 | * @param lcore_id | |
273 | * lcore id. | |
274 | * @param caps | |
275 | * pointer to rte_power_core_capabilities object. | |
276 | * | |
277 | * @return | |
278 | * - 0 on success. | |
279 | * - Negative on error. | |
280 | */ | |
281 | typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id, | |
282 | struct rte_power_core_capabilities *caps); | |
283 | ||
284 | extern rte_power_get_capabilities_t rte_power_get_capabilities; | |
285 | ||
7c673cae FG |
286 | #ifdef __cplusplus |
287 | } | |
288 | #endif | |
289 | ||
290 | #endif |