1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2010-2014 Intel Corporation. 3 4Power Management 5================ 6 7The DPDK Power Management feature allows users space applications to save power 8by dynamically adjusting CPU frequency or entering into different C-States. 9 10* Adjusting the CPU frequency dynamically according to the utilization of RX queue. 11 12* Entering into different deeper C-States according to the adaptive algorithms to speculate 13 brief periods of time suspending the application if no packets are received. 14 15The interfaces for adjusting the operating CPU frequency are in the power management library. 16C-State control is implemented in applications according to the different use cases. 17 18CPU Frequency Scaling 19--------------------- 20 21The Linux kernel provides a cpufreq module for CPU frequency scaling for each lcore. 22For example, for cpuX, /sys/devices/system/cpu/cpuX/cpufreq/ has the following sys files for frequency scaling: 23 24* affected_cpus 25 26* bios_limit 27 28* cpuinfo_cur_freq 29 30* cpuinfo_max_freq 31 32* cpuinfo_min_freq 33 34* cpuinfo_transition_latency 35 36* related_cpus 37 38* scaling_available_frequencies 39 40* scaling_available_governors 41 42* scaling_cur_freq 43 44* scaling_driver 45 46* scaling_governor 47 48* scaling_max_freq 49 50* scaling_min_freq 51 52* scaling_setspeed 53 54In the DPDK, scaling_governor is configured in user space. 55Then, a user space application can prompt the kernel by writing scaling_setspeed to adjust the CPU frequency 56according to the strategies defined by the user space application. 57 58Core-load Throttling through C-States 59------------------------------------- 60 61Core state can be altered by speculative sleeps whenever the specified lcore has nothing to do. 62In the DPDK, if no packet is received after polling, 63speculative sleeps can be triggered according the strategies defined by the user space application. 64 65Per-core Turbo Boost 66-------------------- 67 68Individual cores can be allowed to enter a Turbo Boost state on a per-core 69basis. This is achieved by enabling Turbo Boost Technology in the BIOS, then 70looping through the relevant cores and enabling/disabling Turbo Boost on each 71core. 72 73Use of Power Library in a Hyper-Threaded Environment 74---------------------------------------------------- 75 76In the case where the power library is in use on a system with Hyper-Threading enabled, 77the frequency on the physical core is set to the highest frequency of the Hyper-Thread siblings. 78So even though an application may request a scale down, the core frequency will 79remain at the highest frequency until all Hyper-Threads on that core request a scale down. 80 81API Overview of the Power Library 82--------------------------------- 83 84The main methods exported by power library are for CPU frequency scaling and include the following: 85 86* **Freq up**: Prompt the kernel to scale up the frequency of the specific lcore. 87 88* **Freq down**: Prompt the kernel to scale down the frequency of the specific lcore. 89 90* **Freq max**: Prompt the kernel to scale up the frequency of the specific lcore to the maximum. 91 92* **Freq min**: Prompt the kernel to scale down the frequency of the specific lcore to the minimum. 93 94* **Get available freqs**: Read the available frequencies of the specific lcore from the sys file. 95 96* **Freq get**: Get the current frequency of the specific lcore. 97 98* **Freq set**: Prompt the kernel to set the frequency for the specific lcore. 99 100* **Enable turbo**: Prompt the kernel to enable Turbo Boost for the specific lcore. 101 102* **Disable turbo**: Prompt the kernel to disable Turbo Boost for the specific lcore. 103 104User Cases 105---------- 106 107The power management mechanism is used to save power when performing L3 forwarding. 108 109 110PM QoS 111------ 112 113The ``/sys/devices/system/cpu/cpuX/power/pm_qos_resume_latency_us`` 114sysfs interface is used to set and get the resume latency limit 115on the cpuX for userspace. 116Each cpuidle governor in Linux selects which idle state to enter 117based on this CPU resume latency in their idle task. 118 119The deeper the idle state, the lower the power consumption, 120but the longer the resume time. 121Some services are latency sensitive and request a low resume time, 122like interrupt packet receiving mode. 123 124Applications can set and get the CPU resume latency with 125``rte_power_qos_set_cpu_resume_latency()`` 126and ``rte_power_qos_get_cpu_resume_latency()`` respectively. 127Applications can set a strict resume latency (zero value) 128to lower the resume latency and get better performance 129(instead, the power consumption of platform may increase). 130 131 132Ethernet PMD Power Management API 133--------------------------------- 134 135Abstract 136~~~~~~~~ 137 138Existing power management mechanisms require developers to change application 139design or change code to make use of it. The PMD power management API provides a 140convenient alternative by utilizing Ethernet PMD RX callbacks, and triggering 141power saving whenever empty poll count reaches a certain number. 142 143* Monitor 144 This power saving scheme will put the CPU into optimized power state and 145 monitor the Ethernet PMD RX descriptor address, waking the CPU up whenever 146 there's new traffic. Support for this scheme may not be available on all 147 platforms, and further limitations may apply (see below). 148 149* Pause 150 This power saving scheme will avoid busy polling by either entering 151 power-optimized sleep state with ``rte_power_pause()`` function, or, if it's 152 not supported by the underlying platform, use ``rte_pause()``. 153 154* Frequency scaling 155 This power saving scheme will use ``librte_power`` library functionality to 156 scale the core frequency up/down depending on traffic volume. 157 The reaction time of the frequency scaling mode is longer 158 than the pause and monitor mode. 159 160The "monitor" mode is only supported in the following configurations and scenarios: 161 162* On Linux* x86_64, `rte_power_monitor()` requires WAITPKG instruction set being 163 supported by the CPU, while `rte_power_monitor_multi()` requires WAITPKG and 164 RTM instruction sets being supported by the CPU. RTM instruction set may also 165 require booting the Linux with `tsx=on` command line parameter. Please refer 166 to your platform documentation for further information. 167 168* If ``rte_cpu_get_intrinsics_support()`` function indicates that 169 ``rte_power_monitor_multi()`` function is supported by the platform, then 170 monitoring multiple Ethernet Rx queues for traffic will be supported. 171 172* If ``rte_cpu_get_intrinsics_support()`` function indicates that only 173 ``rte_power_monitor()`` is supported by the platform, then monitoring will be 174 limited to a mapping of 1 core 1 queue (thus, each Rx queue will have to be 175 monitored from a different lcore). 176 177* If ``rte_cpu_get_intrinsics_support()`` function indicates that neither of the 178 two monitoring functions are supported, then monitor mode will not be supported. 179 180* Not all Ethernet drivers support monitoring, even if the underlying 181 platform may support the necessary CPU instructions. Please refer to 182 :doc:`../nics/overview` for more information. 183 184 185API Overview for Ethernet PMD Power Management 186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 187 188* **Queue Enable**: Enable specific power scheme for certain queue/port/core. 189 190* **Queue Disable**: Disable power scheme for certain queue/port/core. 191 192* **Get Emptypoll Max**: Get the configured number of empty polls to wait before 193 entering sleep state. 194 195* **Set Emptypoll Max**: Set the number of empty polls to wait before entering 196 sleep state. 197 198* **Get Pause Duration**: Get the configured duration (microseconds) to be used 199 in the Pause callback. 200 201* **Set Pause Duration**: Set the duration of the pause (microseconds) used in 202 the Pause mode callback. 203 204* **Get Scaling Min Freq**: Get the configured minimum frequency (kHz) to be used 205 in Frequency Scaling mode. 206 207* **Set Scaling Min Freq**: Set the minimum frequency (kHz) to be used in Frequency 208 Scaling mode. 209 210* **Get Scaling Max Freq**: Get the configured maximum frequency (kHz) to be used 211 in Frequency Scaling mode. 212 213* **Set Scaling Max Freq**: Set the maximum frequency (kHz) to be used in Frequency 214 Scaling mode. 215 216Uncore API 217---------- 218 219Abstract 220~~~~~~~~ 221 222Uncore is a term used by Intel to describe the functions of a microprocessor 223that are not in the core, but which must be closely connected to the core 224to achieve high performance: L3 cache, on-die memory controller, etc. 225Significant power savings can be achieved by reducing the uncore frequency 226to its lowest value. 227 228Intel Uncore 229~~~~~~~~~~~~ 230 231The Linux kernel provides the driver "intel-uncore-frequency" 232to control the uncore frequency limits for x86 platform. 233The driver is available from kernel version 5.6 and above. 234Also CONFIG_INTEL_UNCORE_FREQ_CONTROL will need to be enabled in the kernel, 235which was added in 5.6. 236This manipulates the context of MSR 0x620, 237which sets min/max of the uncore for the SKU. 238 239AMD EPYC Uncore 240~~~~~~~~~~~~~~~ 241 242On AMD EPYC platforms, the Host System Management Port (HSMP) kernel module 243facilitates user-level access to HSMP mailboxes, 244which are implemented by the firmware in the System Management Unit (SMU). 245The AMD HSMP driver is available starting from kernel version 5.18. 246Please ensure that ``CONFIG_AMD_HSMP`` is enabled in your kernel configuration. 247 248Additionally, the EPYC System Management Interface In-band Library for Linux 249offers essential API, enabling user-space software 250to effectively manage system functions. 251 252Uncore API Overview 253~~~~~~~~~~~~~~~~~~~ 254 255Overview of each function in the Uncore API, 256with explanation of what they do. 257Each function should not be called in the fast path. 258 259Uncore Power Init 260 Initialize uncore power, populate frequency array 261 and record original min & max for die on pkg. 262 263Uncore Power Exit 264 Exit uncore power, restoring original min & max for die on pkg. 265 266Get Uncore Power Freq 267 Get current uncore freq index for die on pkg. 268 269Set Uncore Power Freq 270 Set min & max uncore freq index for die on pkg 271 to specified index value (min and max will be the same). 272 273Uncore Power Max 274 Set min & max uncore freq to maximum frequency index for die on pkg 275 (min and max will be the same). 276 277Uncore Power Min 278 Set min & max uncore freq to minimum frequency index for die on pkg 279 (min and max will be the same). 280 281Get Num Freqs 282 Get the number of frequencies in the index array. 283 284Get Num Pkgs 285 Get the number of packages (CPU's) on the system. 286 287Get Num Dies 288 Get the number of die's on a given package. 289 290References 291---------- 292 293* The :doc:`../sample_app_ug/l3_forward_power_man` 294 chapter in the :doc:`../sample_app_ug/index` section. 295 296* The :doc:`../sample_app_ug/vm_power_management` 297 chapter in the :doc:`../sample_app_ug/index` section. 298 299* The :doc:`../nics/overview` chapter in the :doc:`../nics/index` section 300