New upstream version 17.11-rc3
[deb_dpdk.git] / examples / vm_power_manager / power_manager.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 POWER_MANAGER_H_
35 #define POWER_MANAGER_H_
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /* Maximum number of CPUS to manage */
42 #define POWER_MGR_MAX_CPUS 64
43 /**
44  * Initialize power management.
45  * Initializes resources and verifies the number of CPUs on the system.
46  * Wraps librte_power int rte_power_init(unsigned lcore_id);
47  *
48  * @return
49  *  - 0 on success.
50  *  - Negative on error.
51  */
52 int power_manager_init(void);
53
54 /**
55  * Exit power management. Must be called prior to exiting the application.
56  *
57  * @return
58  *  - 0 on success.
59  *  - Negative on error.
60  */
61 int power_manager_exit(void);
62
63 /**
64  * Scale up the frequency of the cores specified in core_mask.
65  * It is thread-safe.
66  *
67  * @param core_mask
68  *  The uint64_t bit-mask of cores to change frequency.
69  *
70  * @return
71  *  - 1 on success.
72  *  - Negative on error.
73  */
74 int power_manager_scale_mask_up(uint64_t core_mask);
75
76 /**
77  * Scale down the frequency of the cores specified in core_mask.
78  * It is thread-safe.
79  *
80  * @param core_mask
81  *  The uint64_t bit-mask of cores to change frequency.
82  *
83  * @return
84  *  - 1 on success.
85  *  - Negative on error.
86  */
87 int power_manager_scale_mask_down(uint64_t core_mask);
88
89 /**
90  * Scale to the minimum frequency of the cores specified in core_mask.
91  * It is thread-safe.
92  *
93  * @param core_mask
94  *  The uint64_t bit-mask of cores to change frequency.
95  *
96  * @return
97  *  - 1 on success.
98  *  - Negative on error.
99  */
100 int power_manager_scale_mask_min(uint64_t core_mask);
101
102 /**
103  * Scale to the maximum frequency of the cores specified in core_mask.
104  * It is thread-safe.
105  *
106  * @param core_mask
107  *  The uint64_t bit-mask of cores to change frequency.
108  *
109  * @return
110  *  - 1 on success.
111  *  - Negative on error.
112  */
113 int power_manager_scale_mask_max(uint64_t core_mask);
114
115 /**
116  * Enable Turbo Boost on the cores specified in core_mask.
117  * It is thread-safe.
118  *
119  * @param core_mask
120  *  The uint64_t bit-mask of cores to change frequency.
121  *
122  * @return
123  *  - 1 on success.
124  *  - Negative on error.
125  */
126 int power_manager_enable_turbo_mask(uint64_t core_mask);
127
128 /**
129  * Disable Turbo Boost on the cores specified in core_mask.
130  * It is thread-safe.
131  *
132  * @param core_mask
133  *  The uint64_t bit-mask of cores to change frequency.
134  *
135  * @return
136  *  - 1 on success.
137  *  - Negative on error.
138  */
139 int power_manager_disable_turbo_mask(uint64_t core_mask);
140
141 /**
142  * Scale up frequency for the core specified by core_num.
143  * It is thread-safe.
144  *
145  * @param core_num
146  *  The core number to change frequency
147  *
148  * @return
149  *  - 1 on success.
150  *  - Negative on error.
151  */
152 int power_manager_scale_core_up(unsigned core_num);
153
154 /**
155  * Scale down frequency for the core specified by core_num.
156  * It is thread-safe.
157  *
158  * @param core_num
159  *  The core number to change frequency
160  *
161  * @return
162  *  - 1 on success.
163  *  - 0 if frequency not changed.
164  *  - Negative on error.
165  */
166 int power_manager_scale_core_down(unsigned core_num);
167
168 /**
169  * Scale to minimum frequency for the core specified by core_num.
170  * It is thread-safe.
171  *
172  * @param core_num
173  *  The core number to change frequency
174  *
175  * @return
176  *  - 1 on success.
177  *  - 0 if frequency not changed.
178  *  - Negative on error.
179  */
180 int power_manager_scale_core_min(unsigned core_num);
181
182 /**
183  * Scale to maximum frequency for the core specified by core_num.
184  * It is thread-safe.
185  *
186  * @param core_num
187  *  The core number to change frequency
188  *
189  * @return
190  *  - 1 on success.
191  *  - 0 if frequency not changed.
192  *  - Negative on error.
193  */
194 int power_manager_scale_core_max(unsigned core_num);
195
196 /**
197  * Enable Turbo Boost for the core specified by core_num.
198  * It is thread-safe.
199  *
200  * @param core_num
201  *  The core number to boost
202  *
203  * @return
204  *  - 1 on success.
205  *  - Negative on error.
206  */
207 int power_manager_enable_turbo_core(unsigned int core_num);
208
209 /**
210  * Disable Turbo Boost for the core specified by core_num.
211  * It is thread-safe.
212  *
213  * @param core_num
214  *  The core number to boost
215  *
216  * @return
217  *  - 1 on success.
218  *  - Negative on error.
219  */
220 int power_manager_disable_turbo_core(unsigned int core_num);
221
222 /**
223  * Get the current freuency of the core specified by core_num
224  *
225  * @param core_num
226  *  The core number to get the current frequency
227  *
228  * @return
229  *  - 0  on error
230  *  - >0 for current frequency.
231  */
232 uint32_t power_manager_get_current_frequency(unsigned core_num);
233
234 /**
235  * Scale to medium frequency for the core specified by core_num.
236  * It is thread-safe.
237  *
238  * @param core_num
239  *  The core number to change frequency
240  *
241  * @return
242  *  - 1 on success.
243  *  - 0 if frequency not changed.
244  *  - Negative on error.
245  */
246 int power_manager_scale_core_med(unsigned int core_num);
247
248 #ifdef __cplusplus
249 }
250 #endif
251
252
253 #endif /* POWER_MANAGER_H_ */