New upstream version 18.02
[deb_dpdk.git] / lib / librte_power / rte_power.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
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 */
23 enum power_management_env {PM_ENV_NOT_SET, PM_ENV_ACPI_CPUFREQ, PM_ENV_KVM_VM};
24
25 /**
26  * Set the default power management implementation. If this is not called prior
27  * to rte_power_init(), then auto-detect of the environment will take place.
28  * It is not thread safe.
29  *
30  * @param env
31  *  env. The environment in which to initialise Power Management for.
32  *
33  * @return
34  *  - 0 on success.
35  *  - Negative on error.
36  */
37 int rte_power_set_env(enum power_management_env env);
38
39 /**
40  * Unset the global environment configuration.
41  * This can only be called after all threads have completed.
42  */
43 void rte_power_unset_env(void);
44
45 /**
46  * Get the default power management implementation.
47  *
48  * @return
49  *  power_management_env The configured environment.
50  */
51 enum power_management_env rte_power_get_env(void);
52
53 /**
54  * Initialize power management for a specific lcore. If rte_power_set_env() has
55  * not been called then an auto-detect of the environment will start and
56  * initialise the corresponding resources.
57  *
58  * @param lcore_id
59  *  lcore id.
60  *
61  * @return
62  *  - 0 on success.
63  *  - Negative on error.
64  */
65 int rte_power_init(unsigned int lcore_id);
66
67 /**
68  * Exit power management on a specific lcore. This will call the environment
69  * dependent exit function.
70  *
71  * @param lcore_id
72  *  lcore id.
73  *
74  * @return
75  *  - 0 on success.
76  *  - Negative on error.
77  */
78 int rte_power_exit(unsigned int lcore_id);
79
80 /**
81  * Get the available frequencies of a specific lcore.
82  * Function pointer definition. Review each environments
83  * specific documentation for usage.
84  *
85  * @param lcore_id
86  *  lcore id.
87  * @param freqs
88  *  The buffer array to save the frequencies.
89  * @param num
90  *  The number of frequencies to get.
91  *
92  * @return
93  *  The number of available frequencies.
94  */
95 typedef uint32_t (*rte_power_freqs_t)(unsigned int lcore_id, uint32_t *freqs,
96                 uint32_t num);
97
98 extern rte_power_freqs_t rte_power_freqs;
99
100 /**
101  * Return the current index of available frequencies of a specific lcore.
102  * Function pointer definition. Review each environments
103  * specific documentation for usage.
104  *
105  * @param lcore_id
106  *  lcore id.
107  *
108  * @return
109  *  The current index of available frequencies.
110  */
111 typedef uint32_t (*rte_power_get_freq_t)(unsigned int lcore_id);
112
113 extern rte_power_get_freq_t rte_power_get_freq;
114
115 /**
116  * Set the new frequency for a specific lcore by indicating the index of
117  * available frequencies.
118  * Function pointer definition. Review each environments
119  * specific documentation for usage.
120  *
121  * @param lcore_id
122  *  lcore id.
123  * @param index
124  *  The index of available frequencies.
125  *
126  * @return
127  *  - 1 on success with frequency changed.
128  *  - 0 on success without frequency changed.
129  *  - Negative on error.
130  */
131 typedef int (*rte_power_set_freq_t)(unsigned int lcore_id, uint32_t index);
132
133 extern rte_power_set_freq_t rte_power_set_freq;
134
135 /**
136  * Function pointer definition for generic frequency change functions. Review
137  * each environments specific documentation for usage.
138  *
139  * @param lcore_id
140  *  lcore id.
141  *
142  * @return
143  *  - 1 on success with frequency changed.
144  *  - 0 on success without frequency changed.
145  *  - Negative on error.
146  */
147 typedef int (*rte_power_freq_change_t)(unsigned int lcore_id);
148
149 /**
150  * Scale up the frequency of a specific lcore according to the available
151  * frequencies.
152  * Review each environments specific documentation for usage.
153  *
154  * @param lcore_id
155  *  lcore id.
156  *
157  * @return
158  *  - 1 on success with frequency changed.
159  *  - 0 on success without frequency changed.
160  *  - Negative on error.
161  */
162 extern rte_power_freq_change_t rte_power_freq_up;
163
164 /**
165  * Scale down the frequency of a specific lcore according to the available
166  * frequencies.
167  * Review each environments specific documentation for usage.
168  *
169  * @param lcore_id
170  *  lcore id.
171  *
172  * @return
173  *  - 1 on success with frequency changed.
174  *  - 0 on success without frequency changed.
175  *  - Negative on error.
176  */
177
178 extern rte_power_freq_change_t rte_power_freq_down;
179
180 /**
181  * Scale up the frequency of a specific lcore to the highest according to the
182  * available frequencies.
183  * Review each environments specific documentation for usage.
184  *
185  * @param lcore_id
186  *  lcore id.
187  *
188  * @return
189  *  - 1 on success with frequency changed.
190  *  - 0 on success without frequency changed.
191  *  - Negative on error.
192  */
193 extern rte_power_freq_change_t rte_power_freq_max;
194
195 /**
196  * Scale down the frequency of a specific lcore to the lowest according to the
197  * available frequencies.
198  * Review each environments specific documentation for usage..
199  *
200  * @param lcore_id
201  *  lcore id.
202  *
203  * @return
204  *  - 1 on success with frequency changed.
205  *  - 0 on success without frequency changed.
206  *  - Negative on error.
207  */
208 extern rte_power_freq_change_t rte_power_freq_min;
209
210 /**
211  * Query the Turbo Boost status of a specific lcore.
212  * Review each environments specific documentation for usage..
213  *
214  * @param lcore_id
215  *  lcore id.
216  *
217  * @return
218  *  - 1 Turbo Boost is enabled for this lcore.
219  *  - 0 Turbo Boost is disabled for this lcore.
220  *  - Negative on error.
221  */
222 extern rte_power_freq_change_t rte_power_turbo_status;
223
224 /**
225  * Enable Turbo Boost for this lcore.
226  * Review each environments specific documentation for usage..
227  *
228  * @param lcore_id
229  *  lcore id.
230  *
231  * @return
232  *  - 0 on success.
233  *  - Negative on error.
234  */
235 extern rte_power_freq_change_t rte_power_freq_enable_turbo;
236
237 /**
238  * Disable Turbo Boost for this lcore.
239  * Review each environments specific documentation for usage..
240  *
241  * @param lcore_id
242  *  lcore id.
243  *
244  * @return
245  *  - 0 on success.
246  *  - Negative on error.
247  */
248 extern rte_power_freq_change_t rte_power_freq_disable_turbo;
249
250
251 #ifdef __cplusplus
252 }
253 #endif
254
255 #endif