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