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