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