1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2022 Intel Corporation 3 * Copyright(c) 2023 AMD Corporation 4 */ 5 6 #ifndef RTE_POWER_UNCORE_H 7 #define RTE_POWER_UNCORE_H 8 9 /** 10 * @file 11 * RTE Uncore Frequency Management 12 */ 13 14 #include <rte_compat.h> 15 #include "rte_power.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /* Uncore Power Management Environment */ 22 enum rte_uncore_power_mgmt_env { 23 RTE_UNCORE_PM_ENV_NOT_SET, 24 RTE_UNCORE_PM_ENV_AUTO_DETECT, 25 RTE_UNCORE_PM_ENV_INTEL_UNCORE, 26 RTE_UNCORE_PM_ENV_AMD_HSMP 27 }; 28 29 /** 30 * Set the default uncore power management implementation. 31 * This has to be called prior to calling any other rte_power_uncore_*() API. 32 * It is thread safe. New env can be set only in uninitialized state. 33 * rte_power_unset_uncore_env must be called if different env was already set. 34 * 35 * @param env 36 * env. The environment in which to initialise Uncore Power Management for. 37 * 38 * @return 39 * - 0 on success. 40 * - Negative on error. 41 */ 42 __rte_experimental 43 int rte_power_set_uncore_env(enum rte_uncore_power_mgmt_env env); 44 45 /** 46 * Unset the global uncore environment configuration. 47 * This can only be called after all threads have completed. 48 */ 49 __rte_experimental 50 void rte_power_unset_uncore_env(void); 51 52 /** 53 * Get the default uncore power management implementation. 54 * 55 * @return 56 * power_management_env The configured environment. 57 */ 58 __rte_experimental 59 enum rte_uncore_power_mgmt_env rte_power_get_uncore_env(void); 60 61 /** 62 * Initialize uncore frequency management for specific die on a package. 63 * It will get the available frequencies and prepare to set new die frequencies. 64 * 65 * This function should NOT be called in the fast path. 66 * 67 * @param pkg 68 * Package number. 69 * Each physical CPU in a system is referred to as a package. 70 * @param die 71 * Die number. 72 * Each package can have several dies connected together via the uncore mesh. 73 * 74 * @return 75 * - 0 on success. 76 * - Negative on error. 77 */ 78 int 79 rte_power_uncore_init(unsigned int pkg, unsigned int die); 80 81 /** 82 * Exit uncore frequency management on a specific die on a package. 83 * It will restore uncore min and* max values to previous values 84 * before initialization of API. 85 * 86 * This function should NOT be called in the fast path. 87 * 88 * @param pkg 89 * Package number. 90 * Each physical CPU in a system is referred to as a package. 91 * @param die 92 * Die number. 93 * Each package can have several dies connected together via the uncore mesh. 94 * 95 * @return 96 * - 0 on success. 97 * - Negative on error. 98 */ 99 int 100 rte_power_uncore_exit(unsigned int pkg, unsigned int die); 101 102 /** 103 * Return the current index of available frequencies of a specific die on a package. 104 * It should be protected outside of this function for threadsafe. 105 * 106 * This function should NOT be called in the fast path. 107 * 108 * @param pkg 109 * Package number. 110 * Each physical CPU in a system is referred to as a package. 111 * @param die 112 * Die number. 113 * Each package can have several dies connected together via the uncore mesh. 114 * 115 * @return 116 * The current index of available frequencies. 117 * If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'. 118 */ 119 typedef uint32_t (*rte_power_get_uncore_freq_t)(unsigned int pkg, unsigned int die); 120 121 extern rte_power_get_uncore_freq_t rte_power_get_uncore_freq; 122 123 /** 124 * Set minimum and maximum uncore frequency for specified die on a package 125 * to specified index value. 126 * It should be protected outside of this function for threadsafe. 127 * 128 * This function should NOT be called in the fast path. 129 * 130 * @param pkg 131 * Package number. 132 * Each physical CPU in a system is referred to as a package. 133 * @param die 134 * Die number. 135 * Each package can have several dies connected together via the uncore mesh. 136 * @param index 137 * The index of available frequencies. 138 * 139 * @return 140 * - 1 on success with frequency changed. 141 * - 0 on success without frequency changed. 142 * - Negative on error. 143 */ 144 typedef int (*rte_power_set_uncore_freq_t)(unsigned int pkg, unsigned int die, uint32_t index); 145 146 extern rte_power_set_uncore_freq_t rte_power_set_uncore_freq; 147 148 /** 149 * Function pointer definition for generic frequency change functions. 150 * 151 * @param pkg 152 * Package number. 153 * Each physical CPU in a system is referred to as a package. 154 * @param die 155 * Die number. 156 * Each package can have several dies connected together via the uncore mesh. 157 * 158 * @return 159 * - 1 on success with frequency changed. 160 * - 0 on success without frequency changed. 161 * - Negative on error. 162 */ 163 typedef int (*rte_power_uncore_freq_change_t)(unsigned int pkg, unsigned int die); 164 165 /** 166 * Set minimum and maximum uncore frequency for specified die on a package 167 * to maximum value according to the available frequencies. 168 * It should be protected outside of this function for threadsafe. 169 * 170 * This function should NOT be called in the fast path. 171 */ 172 extern rte_power_uncore_freq_change_t rte_power_uncore_freq_max; 173 174 /** 175 * Set minimum and maximum uncore frequency for specified die on a package 176 * to minimum value according to the available frequencies. 177 * It should be protected outside of this function for threadsafe. 178 * 179 * This function should NOT be called in the fast path. 180 */ 181 extern rte_power_uncore_freq_change_t rte_power_uncore_freq_min; 182 183 /** 184 * Return the list of available frequencies in the index array. 185 * 186 * This function should NOT be called in the fast path. 187 * 188 * @param pkg 189 * Package number. 190 * Each physical CPU in a system is referred to as a package. 191 * @param die 192 * Die number. 193 * Each package can have several dies connected together via the uncore mesh. 194 * @param freqs 195 * The buffer array to save the frequencies. 196 * @param num 197 * The number of frequencies to get. 198 * 199 * @return 200 * - The number of available index's in frequency array. 201 * - Negative on error. 202 */ 203 typedef int (*rte_power_uncore_freqs_t)(unsigned int pkg, unsigned int die, 204 uint32_t *freqs, uint32_t num); 205 206 extern rte_power_uncore_freqs_t rte_power_uncore_freqs; 207 208 /** 209 * Return the list length of available frequencies in the index array. 210 * 211 * This function should NOT be called in the fast path. 212 * 213 * @param pkg 214 * Package number. 215 * Each physical CPU in a system is referred to as a package. 216 * @param die 217 * Die number. 218 * Each package can have several dies connected together via the uncore mesh. 219 * 220 * @return 221 * - The number of available index's in frequency array. 222 * - Negative on error. 223 */ 224 typedef int (*rte_power_uncore_get_num_freqs_t)(unsigned int pkg, unsigned int die); 225 226 extern rte_power_uncore_get_num_freqs_t rte_power_uncore_get_num_freqs; 227 228 /** 229 * Return the number of packages (CPUs) on a system 230 * by parsing the uncore sysfs directory. 231 * 232 * This function should NOT be called in the fast path. 233 * 234 * @return 235 * - Zero on error. 236 * - Number of package on system on success. 237 */ 238 typedef unsigned int (*rte_power_uncore_get_num_pkgs_t)(void); 239 240 extern rte_power_uncore_get_num_pkgs_t rte_power_uncore_get_num_pkgs; 241 242 /** 243 * Return the number of dies for pakckages (CPUs) specified 244 * from parsing the uncore sysfs directory. 245 * 246 * This function should NOT be called in the fast path. 247 * 248 * @param pkg 249 * Package number. 250 * Each physical CPU in a system is referred to as a package. 251 * 252 * @return 253 * - Zero on error. 254 * - Number of dies for package on sucecss. 255 */ 256 typedef unsigned int (*rte_power_uncore_get_num_dies_t)(unsigned int pkg); 257 258 extern rte_power_uncore_get_num_dies_t rte_power_uncore_get_num_dies; 259 260 #ifdef __cplusplus 261 } 262 #endif 263 264 #endif /* RTE_POWER_UNCORE_H */ 265