New upstream version 18.08
[deb_dpdk.git] / lib / librte_power / power_acpi_cpufreq.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _POWER_ACPI_CPUFREQ_H
6 #define _POWER_ACPI_CPUFREQ_H
7
8 /**
9  * @file
10  * RTE Power Management via userspace ACPI cpufreq
11  */
12
13 #include <rte_common.h>
14 #include <rte_byteorder.h>
15 #include <rte_log.h>
16 #include <rte_string_fns.h>
17 #include "rte_power.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /**
24  * Initialize power management for a specific lcore. It will check and set the
25  * governor to userspace for the lcore, get the available frequencies, and
26  * prepare to set new lcore frequency.
27  *
28  * @param lcore_id
29  *  lcore id.
30  *
31  * @return
32  *  - 0 on success.
33  *  - Negative on error.
34  */
35 int power_acpi_cpufreq_init(unsigned int lcore_id);
36
37 /**
38  * Exit power management on a specific lcore. It will set the governor to which
39  * is before initialized.
40  *
41  * @param lcore_id
42  *  lcore id.
43  *
44  * @return
45  *  - 0 on success.
46  *  - Negative on error.
47  */
48 int power_acpi_cpufreq_exit(unsigned int lcore_id);
49
50 /**
51  * Get the available frequencies of a specific lcore. The return value will be
52  * the minimal one of the total number of available frequencies and the number
53  * of buffer. The index of available frequencies used in other interfaces
54  * should be in the range of 0 to this return value.
55  * It should be protected outside of this function for threadsafe.
56  *
57  * @param lcore_id
58  *  lcore id.
59  * @param freqs
60  *  The buffer array to save the frequencies.
61  * @param num
62  *  The number of frequencies to get.
63  *
64  * @return
65  *  The number of available frequencies.
66  */
67 uint32_t power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs,
68                 uint32_t num);
69
70 /**
71  * Return the current index of available frequencies of a specific lcore. It
72  * will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.
73  * It should be protected outside of this function for threadsafe.
74  *
75  * @param lcore_id
76  *  lcore id.
77  *
78  * @return
79  *  The current index of available frequencies.
80  */
81 uint32_t power_acpi_cpufreq_get_freq(unsigned int lcore_id);
82
83 /**
84  * Set the new frequency for a specific lcore by indicating the index of
85  * available frequencies.
86  * It should be protected outside of this function for threadsafe.
87  *
88  * @param lcore_id
89  *  lcore id.
90  * @param index
91  *  The index of available frequencies.
92  *
93  * @return
94  *  - 1 on success with frequency changed.
95  *  - 0 on success without frequency changed.
96  *  - Negative on error.
97  */
98 int power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index);
99
100 /**
101  * Scale up the frequency of a specific lcore according to the available
102  * frequencies.
103  * It should be protected outside of this function for threadsafe.
104  *
105  * @param lcore_id
106  *  lcore id.
107  *
108  * @return
109  *  - 1 on success with frequency changed.
110  *  - 0 on success without frequency changed.
111  *  - Negative on error.
112  */
113 int power_acpi_cpufreq_freq_up(unsigned int lcore_id);
114
115 /**
116  * Scale down the frequency of a specific lcore according to the available
117  * frequencies.
118  * It should be protected outside of this function for threadsafe.
119  *
120  * @param lcore_id
121  *  lcore id.
122  *
123  * @return
124  *  - 1 on success with frequency changed.
125  *  - 0 on success without frequency changed.
126  *  - Negative on error.
127  */
128 int power_acpi_cpufreq_freq_down(unsigned int lcore_id);
129
130 /**
131  * Scale up the frequency of a specific lcore to the highest according to the
132  * available frequencies.
133  * It should be protected outside of this function for threadsafe.
134  *
135  * @param lcore_id
136  *  lcore id.
137  *
138  * @return
139  *  - 1 on success with frequency changed.
140  *  - 0 on success without frequency changed.
141  *  - Negative on error.
142  */
143 int power_acpi_cpufreq_freq_max(unsigned int lcore_id);
144
145 /**
146  * Scale down the frequency of a specific lcore to the lowest according to the
147  * available frequencies.
148  * It should be protected outside of this function for threadsafe.
149  *
150  * @param lcore_id
151  *  lcore id.
152  *
153  * @return
154  *  - 1 on success with frequency changed.
155  *  - 0 on success without frequency changed.
156  *  - Negative on error.
157  */
158 int power_acpi_cpufreq_freq_min(unsigned int lcore_id);
159
160 /**
161  * Get the turbo status of a specific lcore.
162  * It should be protected outside of this function for threadsafe.
163  *
164  * @param lcore_id
165  *  lcore id.
166  *
167  * @return
168  *  - 1 Turbo Boost is enabled on this lcore.
169  *  - 0 Turbo Boost is disabled on this lcore.
170  *  - Negative on error.
171  */
172 int power_acpi_turbo_status(unsigned int lcore_id);
173
174 /**
175  * Enable Turbo Boost on a specific lcore.
176  * It should be protected outside of this function for threadsafe.
177  *
178  * @param lcore_id
179  *  lcore id.
180  *
181  * @return
182  *  - 0 Turbo Boost is enabled successfully on this lcore.
183  *  - Negative on error.
184  */
185 int power_acpi_enable_turbo(unsigned int lcore_id);
186
187 /**
188  * Disable Turbo Boost on a specific lcore.
189  * It should be protected outside of this function for threadsafe.
190  *
191  * @param lcore_id
192  *  lcore id.
193  *
194  * @return
195  *  - 0 Turbo Boost disabled successfully on this lcore.
196  *  - Negative on error.
197  */
198 int power_acpi_disable_turbo(unsigned int lcore_id);
199
200 /**
201  * Returns power capabilities for a specific lcore.
202  *
203  * @param lcore_id
204  *  lcore id.
205  * @param caps
206  *  pointer to rte_power_core_capabilities object.
207  *
208  * @return
209  *  - 0 on success.
210  *  - Negative on error.
211  */
212 int power_acpi_get_capabilities(unsigned int lcore_id,
213                 struct rte_power_core_capabilities *caps);
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219 #endif