15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2010-2014 Intel Corporation. 3fc1f2750SBernard Iremonger 4fc1f2750SBernard IremongerPower Management 5fc1f2750SBernard Iremonger================ 6fc1f2750SBernard Iremonger 748624fd9SSiobhan ButlerThe DPDK Power Management feature allows users space applications to save power 8fc1f2750SBernard Iremongerby dynamically adjusting CPU frequency or entering into different C-States. 9fc1f2750SBernard Iremonger 10fc1f2750SBernard Iremonger* Adjusting the CPU frequency dynamically according to the utilization of RX queue. 11fc1f2750SBernard Iremonger 12fc1f2750SBernard Iremonger* Entering into different deeper C-States according to the adaptive algorithms to speculate 13fc1f2750SBernard Iremonger brief periods of time suspending the application if no packets are received. 14fc1f2750SBernard Iremonger 15fc1f2750SBernard IremongerThe interfaces for adjusting the operating CPU frequency are in the power management library. 16fc1f2750SBernard IremongerC-State control is implemented in applications according to the different use cases. 17fc1f2750SBernard Iremonger 18fc1f2750SBernard IremongerCPU Frequency Scaling 19fc1f2750SBernard Iremonger--------------------- 20fc1f2750SBernard Iremonger 21fc1f2750SBernard IremongerThe Linux kernel provides a cpufreq module for CPU frequency scaling for each lcore. 22fc1f2750SBernard IremongerFor example, for cpuX, /sys/devices/system/cpu/cpuX/cpufreq/ has the following sys files for frequency scaling: 23fc1f2750SBernard Iremonger 24fc1f2750SBernard Iremonger* affected_cpus 25fc1f2750SBernard Iremonger 26fc1f2750SBernard Iremonger* bios_limit 27fc1f2750SBernard Iremonger 28fc1f2750SBernard Iremonger* cpuinfo_cur_freq 29fc1f2750SBernard Iremonger 30fc1f2750SBernard Iremonger* cpuinfo_max_freq 31fc1f2750SBernard Iremonger 32fc1f2750SBernard Iremonger* cpuinfo_min_freq 33fc1f2750SBernard Iremonger 34fc1f2750SBernard Iremonger* cpuinfo_transition_latency 35fc1f2750SBernard Iremonger 36fc1f2750SBernard Iremonger* related_cpus 37fc1f2750SBernard Iremonger 38fc1f2750SBernard Iremonger* scaling_available_frequencies 39fc1f2750SBernard Iremonger 40fc1f2750SBernard Iremonger* scaling_available_governors 41fc1f2750SBernard Iremonger 42fc1f2750SBernard Iremonger* scaling_cur_freq 43fc1f2750SBernard Iremonger 44fc1f2750SBernard Iremonger* scaling_driver 45fc1f2750SBernard Iremonger 46fc1f2750SBernard Iremonger* scaling_governor 47fc1f2750SBernard Iremonger 48fc1f2750SBernard Iremonger* scaling_max_freq 49fc1f2750SBernard Iremonger 50fc1f2750SBernard Iremonger* scaling_min_freq 51fc1f2750SBernard Iremonger 52fc1f2750SBernard Iremonger* scaling_setspeed 53fc1f2750SBernard Iremonger 5448624fd9SSiobhan ButlerIn the DPDK, scaling_governor is configured in user space. 55fc1f2750SBernard IremongerThen, a user space application can prompt the kernel by writing scaling_setspeed to adjust the CPU frequency 56fc1f2750SBernard Iremongeraccording to the strategies defined by the user space application. 57fc1f2750SBernard Iremonger 58fc1f2750SBernard IremongerCore-load Throttling through C-States 59fc1f2750SBernard Iremonger------------------------------------- 60fc1f2750SBernard Iremonger 61fc1f2750SBernard IremongerCore state can be altered by speculative sleeps whenever the specified lcore has nothing to do. 6248624fd9SSiobhan ButlerIn the DPDK, if no packet is received after polling, 63fc1f2750SBernard Iremongerspeculative sleeps can be triggered according the strategies defined by the user space application. 64fc1f2750SBernard Iremonger 6594608a0fSDavid HuntPer-core Turbo Boost 6694608a0fSDavid Hunt-------------------- 6794608a0fSDavid Hunt 6894608a0fSDavid HuntIndividual cores can be allowed to enter a Turbo Boost state on a per-core 6994608a0fSDavid Huntbasis. This is achieved by enabling Turbo Boost Technology in the BIOS, then 7094608a0fSDavid Huntlooping through the relevant cores and enabling/disabling Turbo Boost on each 7194608a0fSDavid Huntcore. 7294608a0fSDavid Hunt 73d9e71f52SDavid HuntUse of Power Library in a Hyper-Threaded Environment 74d9e71f52SDavid Hunt---------------------------------------------------- 75d9e71f52SDavid Hunt 76d9e71f52SDavid HuntIn the case where the power library is in use on a system with Hyper-Threading enabled, 77d9e71f52SDavid Huntthe frequency on the physical core is set to the highest frequency of the Hyper-Thread siblings. 78d9e71f52SDavid HuntSo even though an application may request a scale down, the core frequency will 79d9e71f52SDavid Huntremain at the highest frequency until all Hyper-Threads on that core request a scale down. 80d9e71f52SDavid Hunt 81fc1f2750SBernard IremongerAPI Overview of the Power Library 82fc1f2750SBernard Iremonger--------------------------------- 83fc1f2750SBernard Iremonger 84fc1f2750SBernard IremongerThe main methods exported by power library are for CPU frequency scaling and include the following: 85fc1f2750SBernard Iremonger 86fc1f2750SBernard Iremonger* **Freq up**: Prompt the kernel to scale up the frequency of the specific lcore. 87fc1f2750SBernard Iremonger 88fc1f2750SBernard Iremonger* **Freq down**: Prompt the kernel to scale down the frequency of the specific lcore. 89fc1f2750SBernard Iremonger 90fc1f2750SBernard Iremonger* **Freq max**: Prompt the kernel to scale up the frequency of the specific lcore to the maximum. 91fc1f2750SBernard Iremonger 92fc1f2750SBernard Iremonger* **Freq min**: Prompt the kernel to scale down the frequency of the specific lcore to the minimum. 93fc1f2750SBernard Iremonger 94fc1f2750SBernard Iremonger* **Get available freqs**: Read the available frequencies of the specific lcore from the sys file. 95fc1f2750SBernard Iremonger 96fc1f2750SBernard Iremonger* **Freq get**: Get the current frequency of the specific lcore. 97fc1f2750SBernard Iremonger 98fc1f2750SBernard Iremonger* **Freq set**: Prompt the kernel to set the frequency for the specific lcore. 99fc1f2750SBernard Iremonger 10094608a0fSDavid Hunt* **Enable turbo**: Prompt the kernel to enable Turbo Boost for the specific lcore. 10194608a0fSDavid Hunt 10294608a0fSDavid Hunt* **Disable turbo**: Prompt the kernel to disable Turbo Boost for the specific lcore. 10394608a0fSDavid Hunt 104fc1f2750SBernard IremongerUser Cases 105fc1f2750SBernard Iremonger---------- 106fc1f2750SBernard Iremonger 107fc1f2750SBernard IremongerThe power management mechanism is used to save power when performing L3 forwarding. 108fc1f2750SBernard Iremonger 109450f0791SLiang Ma 110450f0791SLiang MaEmpty Poll API 111450f0791SLiang Ma-------------- 112450f0791SLiang Ma 113450f0791SLiang MaAbstract 114450f0791SLiang Ma~~~~~~~~ 115450f0791SLiang Ma 116450f0791SLiang MaFor packet processing workloads such as DPDK polling is continuous. 117450f0791SLiang MaThis means CPU cores always show 100% busy independent of how much work 118450f0791SLiang Mathose cores are doing. It is critical to accurately determine how busy 119450f0791SLiang Maa core is hugely important for the following reasons: 120450f0791SLiang Ma 121450f0791SLiang Ma * No indication of overload conditions 122450f0791SLiang Ma * User does not know how much real load is on a system, resulting 123450f0791SLiang Ma in wasted energy as no power management is utilized 124450f0791SLiang Ma 125450f0791SLiang MaCompared to the original l3fwd-power design, instead of going to sleep 126450f0791SLiang Maafter detecting an empty poll, the new mechanism just lowers the core frequency. 127450f0791SLiang MaAs a result, the application does not stop polling the device, which leads 128450f0791SLiang Mato improved handling of bursts of traffic. 129450f0791SLiang Ma 130450f0791SLiang MaWhen the system become busy, the empty poll mechanism can also increase the core 131450f0791SLiang Mafrequency (including turbo) to do best effort for intensive traffic. This gives 132450f0791SLiang Maus more flexible and balanced traffic awareness over the standard l3fwd-power 133450f0791SLiang Maapplication. 134450f0791SLiang Ma 135450f0791SLiang Ma 136450f0791SLiang MaProposed Solution 137450f0791SLiang Ma~~~~~~~~~~~~~~~~~ 138450f0791SLiang MaThe proposed solution focuses on how many times empty polls are executed. 139450f0791SLiang MaThe less the number of empty polls, means current core is busy with processing 140450f0791SLiang Maworkload, therefore, the higher frequency is needed. The high empty poll number 141450f0791SLiang Maindicates the current core not doing any real work therefore, we can lower the 142450f0791SLiang Mafrequency to safe power. 143450f0791SLiang Ma 144450f0791SLiang MaIn the current implementation, each core has 1 empty-poll counter which assume 145450f0791SLiang Ma1 core is dedicated to 1 queue. This will need to be expanded in the future to 146450f0791SLiang Masupport multiple queues per core. 147450f0791SLiang Ma 148450f0791SLiang MaPower state definition: 149450f0791SLiang Ma^^^^^^^^^^^^^^^^^^^^^^^ 150450f0791SLiang Ma 151450f0791SLiang Ma* LOW: Not currently used, reserved for future use. 152450f0791SLiang Ma 153450f0791SLiang Ma* MED: the frequency is used to process modest traffic workload. 154450f0791SLiang Ma 155450f0791SLiang Ma* HIGH: the frequency is used to process busy traffic workload. 156450f0791SLiang Ma 157450f0791SLiang MaThere are two phases to establish the power management system: 158450f0791SLiang Ma^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 159450f0791SLiang Ma* Training phase. This phase is used to measure the optimal frequency 160450f0791SLiang Ma change thresholds for a given system. The thresholds will differ from 161450f0791SLiang Ma system to system due to differences in processor micro-architecture, 162450f0791SLiang Ma cache and device configurations. 163450f0791SLiang Ma In this phase, the user must ensure that no traffic can enter the 164450f0791SLiang Ma system so that counts can be measured for empty polls at low, medium 165450f0791SLiang Ma and high frequencies. Each frequency is measured for two seconds. 166450f0791SLiang Ma Once the training phase is complete, the threshold numbers are 167450f0791SLiang Ma displayed, and normal mode resumes, and traffic can be allowed into 168450f0791SLiang Ma the system. These threshold number can be used on the command line 169450f0791SLiang Ma when starting the application in normal mode to avoid re-training 170450f0791SLiang Ma every time. 171450f0791SLiang Ma 172450f0791SLiang Ma* Normal phase. Every 10ms the run-time counters are compared 173450f0791SLiang Ma to the supplied threshold values, and the decision will be made 174450f0791SLiang Ma whether to move to a different power state (by adjusting the 175450f0791SLiang Ma frequency). 176450f0791SLiang Ma 177450f0791SLiang MaAPI Overview for Empty Poll Power Management 178450f0791SLiang Ma~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 179450f0791SLiang Ma* **State Init**: initialize the power management system. 180450f0791SLiang Ma 181450f0791SLiang Ma* **State Free**: free the resource hold by power management system. 182450f0791SLiang Ma 183450f0791SLiang Ma* **Update Empty Poll Counter**: update the empty poll counter. 184450f0791SLiang Ma 185450f0791SLiang Ma* **Update Valid Poll Counter**: update the valid poll counter. 186450f0791SLiang Ma 18750360349SYong Wang* **Set the Frequency Index**: update the power state/frequency mapping. 188450f0791SLiang Ma 189450f0791SLiang Ma* **Detect empty poll state change**: empty poll state change detection algorithm then take action. 190450f0791SLiang Ma 191450f0791SLiang MaUser Cases 192450f0791SLiang Ma---------- 193450f0791SLiang MaThe mechanism can applied to any device which is based on polling. e.g. NIC, FPGA. 194450f0791SLiang Ma 195682a6454SLiang MaEthernet PMD Power Management API 196682a6454SLiang Ma--------------------------------- 197682a6454SLiang Ma 198682a6454SLiang MaAbstract 199682a6454SLiang Ma~~~~~~~~ 200682a6454SLiang Ma 2015dff9a72SAnatoly BurakovExisting power management mechanisms require developers to change application 2025dff9a72SAnatoly Burakovdesign or change code to make use of it. The PMD power management API provides a 2035dff9a72SAnatoly Burakovconvenient alternative by utilizing Ethernet PMD RX callbacks, and triggering 2045dff9a72SAnatoly Burakovpower saving whenever empty poll count reaches a certain number. 205682a6454SLiang Ma 2065dff9a72SAnatoly Burakov* Monitor 2075dff9a72SAnatoly Burakov This power saving scheme will put the CPU into optimized power state and 2085dff9a72SAnatoly Burakov monitor the Ethernet PMD RX descriptor address, waking the CPU up whenever 2095dff9a72SAnatoly Burakov there's new traffic. Support for this scheme may not be available on all 2105dff9a72SAnatoly Burakov platforms, and further limitations may apply (see below). 211682a6454SLiang Ma 2125dff9a72SAnatoly Burakov* Pause 2135dff9a72SAnatoly Burakov This power saving scheme will avoid busy polling by either entering 2145dff9a72SAnatoly Burakov power-optimized sleep state with ``rte_power_pause()`` function, or, if it's 2155dff9a72SAnatoly Burakov not supported by the underlying platform, use ``rte_pause()``. 216682a6454SLiang Ma 2175dff9a72SAnatoly Burakov* Frequency scaling 2185dff9a72SAnatoly Burakov This power saving scheme will use ``librte_power`` library functionality to 2195dff9a72SAnatoly Burakov scale the core frequency up/down depending on traffic volume. 2207580f973SDavid Hunt The reaction time of the frequency scaling mode is longer 2217580f973SDavid Hunt than the pause and monitor mode. 222682a6454SLiang Ma 2235dff9a72SAnatoly BurakovThe "monitor" mode is only supported in the following configurations and scenarios: 224682a6454SLiang Ma 2255dff9a72SAnatoly Burakov* On Linux* x86_64, `rte_power_monitor()` requires WAITPKG instruction set being 226f53fe635SAnatoly Burakov supported by the CPU, while `rte_power_monitor_multi()` requires WAITPKG and 227f53fe635SAnatoly Burakov RTM instruction sets being supported by the CPU. RTM instruction set may also 228f53fe635SAnatoly Burakov require booting the Linux with `tsx=on` command line parameter. Please refer 229f53fe635SAnatoly Burakov to your platform documentation for further information. 2305dff9a72SAnatoly Burakov 2315dff9a72SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that 232f53fe635SAnatoly Burakov ``rte_power_monitor_multi()`` function is supported by the platform, then 233f53fe635SAnatoly Burakov monitoring multiple Ethernet Rx queues for traffic will be supported. 234f53fe635SAnatoly Burakov 235f53fe635SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that only 2365dff9a72SAnatoly Burakov ``rte_power_monitor()`` is supported by the platform, then monitoring will be 2375dff9a72SAnatoly Burakov limited to a mapping of 1 core 1 queue (thus, each Rx queue will have to be 2385dff9a72SAnatoly Burakov monitored from a different lcore). 2395dff9a72SAnatoly Burakov 240f53fe635SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that neither of the 241f53fe635SAnatoly Burakov two monitoring functions are supported, then monitor mode will not be supported. 2425dff9a72SAnatoly Burakov 2435dff9a72SAnatoly Burakov* Not all Ethernet drivers support monitoring, even if the underlying 2445dff9a72SAnatoly Burakov platform may support the necessary CPU instructions. Please refer to 2455dff9a72SAnatoly Burakov :doc:`../nics/overview` for more information. 2465dff9a72SAnatoly Burakov 247682a6454SLiang Ma 248682a6454SLiang MaAPI Overview for Ethernet PMD Power Management 249682a6454SLiang Ma~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 250682a6454SLiang Ma 251682a6454SLiang Ma* **Queue Enable**: Enable specific power scheme for certain queue/port/core. 252682a6454SLiang Ma 253682a6454SLiang Ma* **Queue Disable**: Disable power scheme for certain queue/port/core. 254682a6454SLiang Ma 2559e9e945bSKevin Laatz* **Get Emptypoll Max**: Get the configured number of empty polls to wait before 2569e9e945bSKevin Laatz entering sleep state. 2579e9e945bSKevin Laatz 2589e9e945bSKevin Laatz* **Set Emptypoll Max**: Set the number of empty polls to wait before entering 2599e9e945bSKevin Laatz sleep state. 2609e9e945bSKevin Laatz 2614a8fbc28SKevin Laatz* **Get Pause Duration**: Get the configured duration (microseconds) to be used 2624a8fbc28SKevin Laatz in the Pause callback. 2634a8fbc28SKevin Laatz 2644a8fbc28SKevin Laatz* **Set Pause Duration**: Set the duration of the pause (microseconds) used in 2654a8fbc28SKevin Laatz the Pause mode callback. 2664a8fbc28SKevin Laatz 26742651168SKevin Laatz* **Get Scaling Min Freq**: Get the configured minimum frequency (kHz) to be used 26842651168SKevin Laatz in Frequency Scaling mode. 26942651168SKevin Laatz 27042651168SKevin Laatz* **Set Scaling Min Freq**: Set the minimum frequency (kHz) to be used in Frequency 27142651168SKevin Laatz Scaling mode. 27242651168SKevin Laatz 27342651168SKevin Laatz* **Get Scaling Max Freq**: Get the configured maximum frequency (kHz) to be used 27442651168SKevin Laatz in Frequency Scaling mode. 27542651168SKevin Laatz 27642651168SKevin Laatz* **Set Scaling Max Freq**: Set the maximum frequency (kHz) to be used in Frequency 27742651168SKevin Laatz Scaling mode. 27842651168SKevin Laatz 279*60b8a661STadhg KearneyIntel Uncore API 280*60b8a661STadhg Kearney---------------- 281*60b8a661STadhg Kearney 282*60b8a661STadhg KearneyAbstract 283*60b8a661STadhg Kearney~~~~~~~~ 284*60b8a661STadhg Kearney 285*60b8a661STadhg KearneyUncore is a term used by Intel to describe the functions of a microprocessor 286*60b8a661STadhg Kearneythat are not in the core, but which must be closely connected to the core 287*60b8a661STadhg Kearneyto achieve high performance: L3 cache, on-die memory controller, etc. 288*60b8a661STadhg KearneySignificant power savings can be achieved by reducing the uncore frequency 289*60b8a661STadhg Kearneyto its lowest value. 290*60b8a661STadhg Kearney 291*60b8a661STadhg KearneyThe Linux kernel provides the driver "intel-uncore-frequency" 292*60b8a661STadhg Kearneyto control the uncore frequency limits for x86 platform. 293*60b8a661STadhg KearneyThe driver is available from kernel version 5.6 and above. 294*60b8a661STadhg KearneyAlso CONFIG_INTEL_UNCORE_FREQ_CONTROL will need to be enabled in the kernel, 295*60b8a661STadhg Kearneywhich was added in 5.6. 296*60b8a661STadhg KearneyThis manipulates the context of MSR 0x620, 297*60b8a661STadhg Kearneywhich sets min/max of the uncore for the SKU. 298*60b8a661STadhg Kearney 299*60b8a661STadhg KearneyAPI Overview for Intel Uncore 300*60b8a661STadhg Kearney~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 301*60b8a661STadhg Kearney 302*60b8a661STadhg KearneyOverview of each function in the Intel Uncore API, 303*60b8a661STadhg Kearneywith explanation of what they do. 304*60b8a661STadhg KearneyEach function should not be called in the fast path. 305*60b8a661STadhg Kearney 306*60b8a661STadhg KearneyUncore Power Init 307*60b8a661STadhg Kearney Initialize uncore power, populate frequency array 308*60b8a661STadhg Kearney and record original min & max for die on pkg. 309*60b8a661STadhg Kearney 310*60b8a661STadhg KearneyUncore Power Exit 311*60b8a661STadhg Kearney Exit uncore power, restoring original min & max for die on pkg. 312*60b8a661STadhg Kearney 313*60b8a661STadhg KearneyGet Uncore Power Freq 314*60b8a661STadhg Kearney Get current uncore freq index for die on pkg. 315*60b8a661STadhg Kearney 316*60b8a661STadhg KearneySet Uncore Power Freq 317*60b8a661STadhg Kearney Set min & max uncore freq index for die on pkg 318*60b8a661STadhg Kearney to specified index value (min and max will be the same). 319*60b8a661STadhg Kearney 320*60b8a661STadhg KearneyUncore Power Max 321*60b8a661STadhg Kearney Set min & max uncore freq to maximum frequency index for die on pkg 322*60b8a661STadhg Kearney (min and max will be the same). 323*60b8a661STadhg Kearney 324*60b8a661STadhg KearneyUncore Power Min 325*60b8a661STadhg Kearney Set min & max uncore freq to minimum frequency index for die on pkg 326*60b8a661STadhg Kearney (min and max will be the same). 327*60b8a661STadhg Kearney 328*60b8a661STadhg KearneyGet Num Freqs 329*60b8a661STadhg Kearney Get the number of frequencies in the index array. 330*60b8a661STadhg Kearney 331*60b8a661STadhg KearneyGet Num Pkgs 332*60b8a661STadhg Kearney Get the number of packages (CPU's) on the system. 333*60b8a661STadhg Kearney 334*60b8a661STadhg KearneyGet Num Dies 335*60b8a661STadhg Kearney Get the number of die's on a given package. 336*60b8a661STadhg Kearney 337fc1f2750SBernard IremongerReferences 338fc1f2750SBernard Iremonger---------- 339fc1f2750SBernard Iremonger 340fa77f80fSDavid Hunt* The :doc:`../sample_app_ug/l3_forward_power_man` 341fa77f80fSDavid Hunt chapter in the :doc:`../sample_app_ug/index` section. 342fc1f2750SBernard Iremonger 343fa77f80fSDavid Hunt* The :doc:`../sample_app_ug/vm_power_management` 344fa77f80fSDavid Hunt chapter in the :doc:`../sample_app_ug/index` section. 3455dff9a72SAnatoly Burakov 3465dff9a72SAnatoly Burakov* The :doc:`../nics/overview` chapter in the :doc:`../nics/index` section 347