xref: /dpdk/lib/power/rte_power_cpufreq.h (revision 37dda90ee15b7098bc48356868a87d34f727eecc)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  * Copyright(c) 2024 Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef RTE_POWER_CPUFREQ_H
7 #define RTE_POWER_CPUFREQ_H
8 
9 /**
10  * @file
11  * CPU Frequency Management
12  */
13 
14 #include <rte_common.h>
15 #include <rte_log.h>
16 
17 #include "power_cpufreq.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* Power Management Environment State */
24 enum power_management_env {
25 	PM_ENV_NOT_SET = 0,
26 	PM_ENV_ACPI_CPUFREQ,
27 	PM_ENV_KVM_VM,
28 	PM_ENV_PSTATE_CPUFREQ,
29 	PM_ENV_CPPC_CPUFREQ,
30 	PM_ENV_AMD_PSTATE_CPUFREQ
31 };
32 
33 /**
34  * Check if a specific power management environment type is supported on a
35  * currently running system.
36  *
37  * @param env
38  *   The environment type to check support for.
39  *
40  * @return
41  *   - 1 if supported
42  *   - 0 if unsupported
43  *   - -1 if error, with rte_errno indicating reason for error.
44  */
45 int rte_power_check_env_supported(enum power_management_env env);
46 
47 /**
48  * Set the default power management implementation. If this is not called prior
49  * to rte_power_init(), then auto-detect of the environment will take place.
50  * It is thread safe. New env can be set only in uninitialized state
51  * (thus rte_power_unset_env must be called if different env was already set).
52  *
53  * @param env
54  *  env. The environment in which to initialise Power Management for.
55  *
56  * @return
57  *  - 0 on success.
58  *  - Negative on error.
59  */
60 int rte_power_set_env(enum power_management_env env);
61 
62 /**
63  * Unset the global environment configuration.
64  * This can only be called after all threads have completed.
65  */
66 void rte_power_unset_env(void);
67 
68 /**
69  * Get the default power management implementation.
70  *
71  * @return
72  *  power_management_env The configured environment.
73  */
74 enum power_management_env rte_power_get_env(void);
75 
76 /**
77  * Initialize power management for a specific lcore. If rte_power_set_env() has
78  * not been called then an auto-detect of the environment will start and
79  * initialise the corresponding resources.
80  *
81  * @param lcore_id
82  *  lcore id.
83  *
84  * @return
85  *  - 0 on success.
86  *  - Negative on error.
87  */
88 int rte_power_init(unsigned int lcore_id);
89 
90 /**
91  * Exit power management on a specific lcore. This will call the environment
92  * dependent exit function.
93  *
94  * @param lcore_id
95  *  lcore id.
96  *
97  * @return
98  *  - 0 on success.
99  *  - Negative on error.
100  */
101 int rte_power_exit(unsigned int lcore_id);
102 
103 /**
104  * Get the available frequencies of a specific lcore.
105  * Function pointer definition. Review each environments
106  * specific documentation for usage.
107  *
108  * @param lcore_id
109  *  lcore id.
110  * @param freqs
111  *  The buffer array to save the frequencies.
112  * @param num
113  *  The number of frequencies to get.
114  *
115  * @return
116  *  The number of available frequencies.
117  */
118 uint32_t rte_power_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num);
119 
120 /**
121  * Return the current index of available frequencies of a specific lcore.
122  * Function pointer definition. Review each environments
123  * specific documentation for usage.
124  *
125  * @param lcore_id
126  *  lcore id.
127  *
128  * @return
129  *  The current index of available frequencies.
130  */
131 uint32_t rte_power_get_freq(unsigned int lcore_id);
132 
133 /**
134  * Set the new frequency for a specific lcore by indicating the index of
135  * available frequencies.
136  * Function pointer definition. Review each environments
137  * specific documentation for usage.
138  *
139  * @param lcore_id
140  *  lcore id.
141  * @param index
142  *  The index of available frequencies.
143  *
144  * @return
145  *  - 1 on success with frequency changed.
146  *  - 0 on success without frequency changed.
147  *  - Negative on error.
148  */
149 uint32_t rte_power_set_freq(unsigned int lcore_id, uint32_t index);
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 int rte_power_freq_up(unsigned int lcore_id);
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 int rte_power_freq_down(unsigned int lcore_id);
180 
181 /**
182  * Scale up the frequency of a specific lcore to the highest according to the
183  * available frequencies.
184  * Review each environments specific documentation for usage.
185  *
186  * @param lcore_id
187  *  lcore id.
188  *
189  * @return
190  *  - 1 on success with frequency changed.
191  *  - 0 on success without frequency changed.
192  *  - Negative on error.
193  */
194 int rte_power_freq_max(unsigned int lcore_id);
195 
196 /**
197  * Scale down the frequency of a specific lcore to the lowest according to the
198  * available frequencies.
199  * Review each environments specific documentation for usage..
200  *
201  * @param lcore_id
202  *  lcore id.
203  *
204  * @return
205  *  - 1 on success with frequency changed.
206  *  - 0 on success without frequency changed.
207  *  - Negative on error.
208  */
209 int rte_power_freq_min(unsigned int lcore_id);
210 
211 /**
212  * Query the Turbo Boost status of a specific lcore.
213  * Review each environments specific documentation for usage..
214  *
215  * @param lcore_id
216  *  lcore id.
217  *
218  * @return
219  *  - 1 turbo boost enabled.
220  *  - 0 turbo boost disabled.
221  *  - Negative on error.
222  */
223 int rte_power_turbo_status(unsigned int lcore_id);
224 
225 /**
226  * Enable Turbo Boost for this lcore.
227  * Review each environments specific documentation for usage..
228  *
229  * @param lcore_id
230  *  lcore id.
231  *
232  * @return
233  *  - 0 on success.
234  *  - Negative on error.
235  */
236 int rte_power_freq_enable_turbo(unsigned int lcore_id);
237 
238 /**
239  * Disable Turbo Boost for this lcore.
240  * Review each environments specific documentation for usage..
241  *
242  * @param lcore_id
243  *  lcore id.
244  *
245  * @return
246  *  - 0 on success.
247  *  - Negative on error.
248  */
249 int rte_power_freq_disable_turbo(unsigned int lcore_id);
250 
251 /**
252  * Returns power capabilities for a specific lcore.
253  * Function pointer definition. Review each environments
254  * specific documentation for usage.
255  *
256  * @param lcore_id
257  *  lcore id.
258  * @param caps
259  *  pointer to rte_power_core_capabilities object.
260  *
261  * @return
262  *  - 0 on success.
263  *  - Negative on error.
264  */
265 int rte_power_get_capabilities(unsigned int lcore_id,
266 		struct rte_power_core_capabilities *caps);
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #endif /* RTE_POWER_CPUFREQ_H */
273