Imported Upstream version 16.04
[deb_dpdk.git] / lib / librte_power / rte_power.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_POWER_H
35 #define _RTE_POWER_H
36
37 /**
38  * @file
39  * RTE Power Management
40  */
41
42 #include <rte_common.h>
43 #include <rte_byteorder.h>
44 #include <rte_log.h>
45 #include <rte_string_fns.h>
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /* Power Management Environment State */
52 enum power_management_env {PM_ENV_NOT_SET, PM_ENV_ACPI_CPUFREQ, PM_ENV_KVM_VM};
53
54 /**
55  * Set the default power management implementation. If this is not called prior
56  * to rte_power_init(), then auto-detect of the environment will take place.
57  * It is not thread safe.
58  *
59  * @param env
60  *  env. The environment in which to initialise Power Management for.
61  *
62  * @return
63  *  - 0 on success.
64  *  - Negative on error.
65  */
66 int rte_power_set_env(enum power_management_env env);
67
68 /**
69  * Unset the global environment configuration.
70  * This can only be called after all threads have completed.
71  */
72 void rte_power_unset_env(void);
73
74 /**
75  * Get the default power management implementation.
76  *
77  * @return
78  *  power_management_env The configured environment.
79  */
80 enum power_management_env rte_power_get_env(void);
81
82 /**
83  * Initialize power management for a specific lcore. If rte_power_set_env() has
84  * not been called then an auto-detect of the environment will start and
85  * initialise the corresponding resources.
86  *
87  * @param lcore_id
88  *  lcore id.
89  *
90  * @return
91  *  - 0 on success.
92  *  - Negative on error.
93  */
94 int rte_power_init(unsigned lcore_id);
95
96 /**
97  * Exit power management on a specific lcore. This will call the environment
98  * dependent exit function.
99  *
100  * @param lcore_id
101  *  lcore id.
102  *
103  * @return
104  *  - 0 on success.
105  *  - Negative on error.
106  */
107 int rte_power_exit(unsigned lcore_id);
108
109 /**
110  * Get the available frequencies of a specific lcore.
111  * Function pointer definition. Review each environments
112  * specific documentation for usage.
113  *
114  * @param lcore_id
115  *  lcore id.
116  * @param freqs
117  *  The buffer array to save the frequencies.
118  * @param num
119  *  The number of frequencies to get.
120  *
121  * @return
122  *  The number of available frequencies.
123  */
124 typedef uint32_t (*rte_power_freqs_t)(unsigned lcore_id, uint32_t *freqs,
125                 uint32_t num);
126
127 extern rte_power_freqs_t rte_power_freqs;
128
129 /**
130  * Return the current index of available frequencies of a specific lcore.
131  * Function pointer definition. Review each environments
132  * specific documentation for usage.
133  *
134  * @param lcore_id
135  *  lcore id.
136  *
137  * @return
138  *  The current index of available frequencies.
139  */
140 typedef uint32_t (*rte_power_get_freq_t)(unsigned lcore_id);
141
142 extern rte_power_get_freq_t rte_power_get_freq;
143
144 /**
145  * Set the new frequency for a specific lcore by indicating the index of
146  * available frequencies.
147  * Function pointer definition. Review each environments
148  * specific documentation for usage.
149  *
150  * @param lcore_id
151  *  lcore id.
152  * @param index
153  *  The index of available frequencies.
154  *
155  * @return
156  *  - 1 on success with frequency changed.
157  *  - 0 on success without frequency changed.
158  *  - Negative on error.
159  */
160 typedef int (*rte_power_set_freq_t)(unsigned lcore_id, uint32_t index);
161
162 extern rte_power_set_freq_t rte_power_set_freq;
163
164 /**
165  * Function pointer definition for generic frequency change functions. Review
166  * each environments specific documentation for usage.
167  *
168  * @param lcore_id
169  *  lcore id.
170  *
171  * @return
172  *  - 1 on success with frequency changed.
173  *  - 0 on success without frequency changed.
174  *  - Negative on error.
175  */
176 typedef int (*rte_power_freq_change_t)(unsigned lcore_id);
177
178 /**
179  * Scale up the frequency of a specific lcore according to the available
180  * frequencies.
181  * Review each environments specific documentation for usage.
182  *
183  * @param lcore_id
184  *  lcore id.
185  *
186  * @return
187  *  - 1 on success with frequency changed.
188  *  - 0 on success without frequency changed.
189  *  - Negative on error.
190  */
191 extern rte_power_freq_change_t rte_power_freq_up;
192
193 /**
194  * Scale down the frequency of a specific lcore according to the available
195  * frequencies.
196  * Review each environments specific documentation for usage.
197  *
198  * @param lcore_id
199  *  lcore id.
200  *
201  * @return
202  *  - 1 on success with frequency changed.
203  *  - 0 on success without frequency changed.
204  *  - Negative on error.
205  */
206
207 extern rte_power_freq_change_t rte_power_freq_down;
208
209 /**
210  * Scale up the frequency of a specific lcore to the highest according to the
211  * available frequencies.
212  * Review each environments specific documentation for usage.
213  *
214  * @param lcore_id
215  *  lcore id.
216  *
217  * @return
218  *  - 1 on success with frequency changed.
219  *  - 0 on success without frequency changed.
220  *  - Negative on error.
221  */
222 extern rte_power_freq_change_t rte_power_freq_max;
223
224 /**
225  * Scale down the frequency of a specific lcore to the lowest according to the
226  * available frequencies.
227  * Review each environments specific documentation for usage..
228  *
229  * @param lcore_id
230  *  lcore id.
231  *
232  * @return
233  *  - 1 on success with frequency changed.
234  *  - 0 on success without frequency changed.
235  *  - Negative on error.
236  */
237 extern rte_power_freq_change_t rte_power_freq_min;
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif