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