xref: /dpdk/examples/vm_power_manager/power_manager.h (revision 7be78d027918dbc846e502780faf94d5acdf5f75)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3d26c18c9SAlan Carew  */
4d26c18c9SAlan Carew 
5d26c18c9SAlan Carew #ifndef POWER_MANAGER_H_
6d26c18c9SAlan Carew #define POWER_MANAGER_H_
7d26c18c9SAlan Carew 
8d26c18c9SAlan Carew #ifdef __cplusplus
9d26c18c9SAlan Carew extern "C" {
10d26c18c9SAlan Carew #endif
1131c9a664SDavid Hunt 
1231c9a664SDavid Hunt #define FREQ_WINDOW_SIZE 32
1331c9a664SDavid Hunt 
1431c9a664SDavid Hunt enum {
1531c9a664SDavid Hunt 	FREQ_UNKNOWN,
1631c9a664SDavid Hunt 	FREQ_MIN,
1731c9a664SDavid Hunt 	FREQ_MAX
1831c9a664SDavid Hunt };
1931c9a664SDavid Hunt 
2099a968faSDavid Hunt struct core_details {
2199a968faSDavid Hunt 	uint64_t last_branches;
2299a968faSDavid Hunt 	uint64_t last_branch_misses;
2399a968faSDavid Hunt 	uint16_t global_enabled_cpus;
2499a968faSDavid Hunt 	uint16_t oob_enabled;
2599a968faSDavid Hunt 	int msr_fd;
2631c9a664SDavid Hunt 	uint16_t freq_directions[FREQ_WINDOW_SIZE];
2731c9a664SDavid Hunt 	uint16_t freq_window_idx;
2831c9a664SDavid Hunt 	uint16_t freq_state;
2995f648ffSRory Sexton 	float branch_ratio_threshold;
3099a968faSDavid Hunt };
3199a968faSDavid Hunt 
3299a968faSDavid Hunt struct core_info {
3399a968faSDavid Hunt 	uint16_t core_count;
3499a968faSDavid Hunt 	struct core_details *cd;
3599a968faSDavid Hunt };
3699a968faSDavid Hunt 
37711f43baSDavid Hunt #define BRANCH_RATIO_THRESHOLD 0.1
38711f43baSDavid Hunt 
3999a968faSDavid Hunt struct core_info *
4099a968faSDavid Hunt get_core_info(void);
4199a968faSDavid Hunt 
4299a968faSDavid Hunt int
4399a968faSDavid Hunt core_info_init(void);
4499a968faSDavid Hunt 
4599a968faSDavid Hunt #define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
46d26c18c9SAlan Carew 
47d26c18c9SAlan Carew /**
48d26c18c9SAlan Carew  * Initialize power management.
49d26c18c9SAlan Carew  * Initializes resources and verifies the number of CPUs on the system.
50d26c18c9SAlan Carew  * Wraps librte_power int rte_power_init(unsigned lcore_id);
51d26c18c9SAlan Carew  *
52d26c18c9SAlan Carew  * @return
53d26c18c9SAlan Carew  *  - 0 on success.
54d26c18c9SAlan Carew  *  - Negative on error.
55d26c18c9SAlan Carew  */
56d26c18c9SAlan Carew int power_manager_init(void);
57d26c18c9SAlan Carew 
58d26c18c9SAlan Carew /**
59d26c18c9SAlan Carew  * Exit power management. Must be called prior to exiting the application.
60d26c18c9SAlan Carew  *
61d26c18c9SAlan Carew  * @return
62d26c18c9SAlan Carew  *  - 0 on success.
63d26c18c9SAlan Carew  *  - Negative on error.
64d26c18c9SAlan Carew  */
65d26c18c9SAlan Carew int power_manager_exit(void);
66d26c18c9SAlan Carew 
67d26c18c9SAlan Carew /**
68d26c18c9SAlan Carew  * Scale up the frequency of the cores specified in core_mask.
69d26c18c9SAlan Carew  * It is thread-safe.
70d26c18c9SAlan Carew  *
71d26c18c9SAlan Carew  * @param core_mask
72d26c18c9SAlan Carew  *  The uint64_t bit-mask of cores to change frequency.
73d26c18c9SAlan Carew  *
74d26c18c9SAlan Carew  * @return
75d26c18c9SAlan Carew  *  - 1 on success.
76d26c18c9SAlan Carew  *  - Negative on error.
77d26c18c9SAlan Carew  */
78d26c18c9SAlan Carew int power_manager_scale_mask_up(uint64_t core_mask);
79d26c18c9SAlan Carew 
80d26c18c9SAlan Carew /**
81d26c18c9SAlan Carew  * Scale down the frequency of the cores specified in core_mask.
82d26c18c9SAlan Carew  * It is thread-safe.
83d26c18c9SAlan Carew  *
84d26c18c9SAlan Carew  * @param core_mask
85d26c18c9SAlan Carew  *  The uint64_t bit-mask of cores to change frequency.
86d26c18c9SAlan Carew  *
87d26c18c9SAlan Carew  * @return
88d26c18c9SAlan Carew  *  - 1 on success.
89d26c18c9SAlan Carew  *  - Negative on error.
90d26c18c9SAlan Carew  */
91d26c18c9SAlan Carew int power_manager_scale_mask_down(uint64_t core_mask);
92d26c18c9SAlan Carew 
93d26c18c9SAlan Carew /**
94d26c18c9SAlan Carew  * Scale to the minimum frequency of the cores specified in core_mask.
95d26c18c9SAlan Carew  * It is thread-safe.
96d26c18c9SAlan Carew  *
97d26c18c9SAlan Carew  * @param core_mask
98d26c18c9SAlan Carew  *  The uint64_t bit-mask of cores to change frequency.
99d26c18c9SAlan Carew  *
100d26c18c9SAlan Carew  * @return
101d26c18c9SAlan Carew  *  - 1 on success.
102d26c18c9SAlan Carew  *  - Negative on error.
103d26c18c9SAlan Carew  */
104d26c18c9SAlan Carew int power_manager_scale_mask_min(uint64_t core_mask);
105d26c18c9SAlan Carew 
106d26c18c9SAlan Carew /**
107d26c18c9SAlan Carew  * Scale to the maximum frequency of the cores specified in core_mask.
108d26c18c9SAlan Carew  * It is thread-safe.
109d26c18c9SAlan Carew  *
110d26c18c9SAlan Carew  * @param core_mask
111d26c18c9SAlan Carew  *  The uint64_t bit-mask of cores to change frequency.
112d26c18c9SAlan Carew  *
113d26c18c9SAlan Carew  * @return
114d26c18c9SAlan Carew  *  - 1 on success.
115d26c18c9SAlan Carew  *  - Negative on error.
116d26c18c9SAlan Carew  */
117d26c18c9SAlan Carew int power_manager_scale_mask_max(uint64_t core_mask);
118d26c18c9SAlan Carew 
119d26c18c9SAlan Carew /**
120567997b9SDavid Hunt  * Enable Turbo Boost on the cores specified in core_mask.
121567997b9SDavid Hunt  * It is thread-safe.
122567997b9SDavid Hunt  *
123567997b9SDavid Hunt  * @param core_mask
124567997b9SDavid Hunt  *  The uint64_t bit-mask of cores to change frequency.
125567997b9SDavid Hunt  *
126567997b9SDavid Hunt  * @return
127567997b9SDavid Hunt  *  - 1 on success.
128567997b9SDavid Hunt  *  - Negative on error.
129567997b9SDavid Hunt  */
130567997b9SDavid Hunt int power_manager_enable_turbo_mask(uint64_t core_mask);
131567997b9SDavid Hunt 
132567997b9SDavid Hunt /**
133567997b9SDavid Hunt  * Disable Turbo Boost on the cores specified in core_mask.
134567997b9SDavid Hunt  * It is thread-safe.
135567997b9SDavid Hunt  *
136567997b9SDavid Hunt  * @param core_mask
137567997b9SDavid Hunt  *  The uint64_t bit-mask of cores to change frequency.
138567997b9SDavid Hunt  *
139567997b9SDavid Hunt  * @return
140567997b9SDavid Hunt  *  - 1 on success.
141567997b9SDavid Hunt  *  - Negative on error.
142567997b9SDavid Hunt  */
143567997b9SDavid Hunt int power_manager_disable_turbo_mask(uint64_t core_mask);
144567997b9SDavid Hunt 
145567997b9SDavid Hunt /**
146d26c18c9SAlan Carew  * Scale up frequency for the core specified by core_num.
147d26c18c9SAlan Carew  * It is thread-safe.
148d26c18c9SAlan Carew  *
149d26c18c9SAlan Carew  * @param core_num
150d26c18c9SAlan Carew  *  The core number to change frequency
151d26c18c9SAlan Carew  *
152d26c18c9SAlan Carew  * @return
153d26c18c9SAlan Carew  *  - 1 on success.
154d26c18c9SAlan Carew  *  - Negative on error.
155d26c18c9SAlan Carew  */
156d26c18c9SAlan Carew int power_manager_scale_core_up(unsigned core_num);
157d26c18c9SAlan Carew 
158d26c18c9SAlan Carew /**
159d26c18c9SAlan Carew  * Scale down frequency for the core specified by core_num.
160d26c18c9SAlan Carew  * It is thread-safe.
161d26c18c9SAlan Carew  *
162d26c18c9SAlan Carew  * @param core_num
163d26c18c9SAlan Carew  *  The core number to change frequency
164d26c18c9SAlan Carew  *
165d26c18c9SAlan Carew  * @return
166d26c18c9SAlan Carew  *  - 1 on success.
167d26c18c9SAlan Carew  *  - 0 if frequency not changed.
168d26c18c9SAlan Carew  *  - Negative on error.
169d26c18c9SAlan Carew  */
170d26c18c9SAlan Carew int power_manager_scale_core_down(unsigned core_num);
171d26c18c9SAlan Carew 
172d26c18c9SAlan Carew /**
173d26c18c9SAlan Carew  * Scale to minimum frequency for the core specified by core_num.
174d26c18c9SAlan Carew  * It is thread-safe.
175d26c18c9SAlan Carew  *
176d26c18c9SAlan Carew  * @param core_num
177d26c18c9SAlan Carew  *  The core number to change frequency
178d26c18c9SAlan Carew  *
179d26c18c9SAlan Carew  * @return
180d26c18c9SAlan Carew  *  - 1 on success.
181d26c18c9SAlan Carew  *  - 0 if frequency not changed.
182d26c18c9SAlan Carew  *  - Negative on error.
183d26c18c9SAlan Carew  */
184d26c18c9SAlan Carew int power_manager_scale_core_min(unsigned core_num);
185d26c18c9SAlan Carew 
186d26c18c9SAlan Carew /**
187d26c18c9SAlan Carew  * Scale to maximum frequency for the core specified by core_num.
188d26c18c9SAlan Carew  * It is thread-safe.
189d26c18c9SAlan Carew  *
190d26c18c9SAlan Carew  * @param core_num
191d26c18c9SAlan Carew  *  The core number to change frequency
192d26c18c9SAlan Carew  *
193d26c18c9SAlan Carew  * @return
194d26c18c9SAlan Carew  *  - 1 on success.
195d26c18c9SAlan Carew  *  - 0 if frequency not changed.
196d26c18c9SAlan Carew  *  - Negative on error.
197d26c18c9SAlan Carew  */
198d26c18c9SAlan Carew int power_manager_scale_core_max(unsigned core_num);
199d26c18c9SAlan Carew 
200d26c18c9SAlan Carew /**
201567997b9SDavid Hunt  * Enable Turbo Boost for the core specified by core_num.
202567997b9SDavid Hunt  * It is thread-safe.
203567997b9SDavid Hunt  *
204567997b9SDavid Hunt  * @param core_num
205567997b9SDavid Hunt  *  The core number to boost
206567997b9SDavid Hunt  *
207567997b9SDavid Hunt  * @return
208567997b9SDavid Hunt  *  - 1 on success.
209567997b9SDavid Hunt  *  - Negative on error.
210567997b9SDavid Hunt  */
211567997b9SDavid Hunt int power_manager_enable_turbo_core(unsigned int core_num);
212567997b9SDavid Hunt 
213567997b9SDavid Hunt /**
214567997b9SDavid Hunt  * Disable Turbo Boost for the core specified by core_num.
215567997b9SDavid Hunt  * It is thread-safe.
216567997b9SDavid Hunt  *
217567997b9SDavid Hunt  * @param core_num
218567997b9SDavid Hunt  *  The core number to boost
219567997b9SDavid Hunt  *
220567997b9SDavid Hunt  * @return
221567997b9SDavid Hunt  *  - 1 on success.
222567997b9SDavid Hunt  *  - Negative on error.
223567997b9SDavid Hunt  */
224567997b9SDavid Hunt int power_manager_disable_turbo_core(unsigned int core_num);
225567997b9SDavid Hunt 
226567997b9SDavid Hunt /**
227*7be78d02SJosh Soref  * Get the current frequency of the core specified by core_num
228d26c18c9SAlan Carew  *
229d26c18c9SAlan Carew  * @param core_num
230d26c18c9SAlan Carew  *  The core number to get the current frequency
231d26c18c9SAlan Carew  *
232d26c18c9SAlan Carew  * @return
233d26c18c9SAlan Carew  *  - 0  on error
234d26c18c9SAlan Carew  *  - >0 for current frequency.
235d26c18c9SAlan Carew  */
236d26c18c9SAlan Carew uint32_t power_manager_get_current_frequency(unsigned core_num);
237d26c18c9SAlan Carew 
2387f472f74SDavid Hunt /**
2397f472f74SDavid Hunt  * Scale to medium frequency for the core specified by core_num.
2407f472f74SDavid Hunt  * It is thread-safe.
2417f472f74SDavid Hunt  *
2427f472f74SDavid Hunt  * @param core_num
2437f472f74SDavid Hunt  *  The core number to change frequency
2447f472f74SDavid Hunt  *
2457f472f74SDavid Hunt  * @return
2467f472f74SDavid Hunt  *  - 1 on success.
2477f472f74SDavid Hunt  *  - 0 if frequency not changed.
2487f472f74SDavid Hunt  *  - Negative on error.
2497f472f74SDavid Hunt  */
2507f472f74SDavid Hunt int power_manager_scale_core_med(unsigned int core_num);
251d26c18c9SAlan Carew 
252d26c18c9SAlan Carew #ifdef __cplusplus
253d26c18c9SAlan Carew }
254d26c18c9SAlan Carew #endif
255d26c18c9SAlan Carew 
256d26c18c9SAlan Carew 
257d26c18c9SAlan Carew #endif /* POWER_MANAGER_H_ */
258