Imported Upstream version 16.04
[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  * Scale up frequency for the core specified by core_num.
117  * It is thread-safe.
118  *
119  * @param core_num
120  *  The core number to change frequency
121  *
122  * @return
123  *  - 1 on success.
124  *  - Negative on error.
125  */
126 int power_manager_scale_core_up(unsigned core_num);
127
128 /**
129  * Scale down frequency for the core specified by core_num.
130  * It is thread-safe.
131  *
132  * @param core_num
133  *  The core number to change frequency
134  *
135  * @return
136  *  - 1 on success.
137  *  - 0 if frequency not changed.
138  *  - Negative on error.
139  */
140 int power_manager_scale_core_down(unsigned core_num);
141
142 /**
143  * Scale to minimum frequency for the core specified by core_num.
144  * It is thread-safe.
145  *
146  * @param core_num
147  *  The core number to change frequency
148  *
149  * @return
150  *  - 1 on success.
151  *  - 0 if frequency not changed.
152  *  - Negative on error.
153  */
154 int power_manager_scale_core_min(unsigned core_num);
155
156 /**
157  * Scale to maximum frequency for the core specified by core_num.
158  * It is thread-safe.
159  *
160  * @param core_num
161  *  The core number to change frequency
162  *
163  * @return
164  *  - 1 on success.
165  *  - 0 if frequency not changed.
166  *  - Negative on error.
167  */
168 int power_manager_scale_core_max(unsigned core_num);
169
170 /**
171  * Get the current freuency of the core specified by core_num
172  *
173  * @param core_num
174  *  The core number to get the current frequency
175  *
176  * @return
177  *  - 0  on error
178  *  - >0 for current frequency.
179  */
180 uint32_t power_manager_get_current_frequency(unsigned core_num);
181
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187
188 #endif /* POWER_MANAGER_H_ */