xref: /dpdk/doc/guides/prog_guide/power_man.rst (revision b3477a6bae7e889955edd8b82f359868dc0abb01)
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
110dd6fd75bSHuisong LiPM QoS
111dd6fd75bSHuisong Li------
112dd6fd75bSHuisong Li
113dd6fd75bSHuisong LiThe ``/sys/devices/system/cpu/cpuX/power/pm_qos_resume_latency_us``
114dd6fd75bSHuisong Lisysfs interface is used to set and get the resume latency limit
115dd6fd75bSHuisong Lion the cpuX for userspace.
116dd6fd75bSHuisong LiEach cpuidle governor in Linux selects which idle state to enter
117dd6fd75bSHuisong Libased on this CPU resume latency in their idle task.
118dd6fd75bSHuisong Li
119dd6fd75bSHuisong LiThe deeper the idle state, the lower the power consumption,
120dd6fd75bSHuisong Libut the longer the resume time.
121*b3477a6bSHuisong LiSome services are latency sensitive and request a low resume time,
122dd6fd75bSHuisong Lilike interrupt packet receiving mode.
123dd6fd75bSHuisong Li
124dd6fd75bSHuisong LiApplications can set and get the CPU resume latency with
125dd6fd75bSHuisong Li``rte_power_qos_set_cpu_resume_latency()``
126dd6fd75bSHuisong Liand ``rte_power_qos_get_cpu_resume_latency()`` respectively.
127dd6fd75bSHuisong LiApplications can set a strict resume latency (zero value)
128dd6fd75bSHuisong Lito lower the resume latency and get better performance
129dd6fd75bSHuisong Li(instead, the power consumption of platform may increase).
130dd6fd75bSHuisong Li
131dd6fd75bSHuisong Li
132682a6454SLiang MaEthernet PMD Power Management API
133682a6454SLiang Ma---------------------------------
134682a6454SLiang Ma
135682a6454SLiang MaAbstract
136682a6454SLiang Ma~~~~~~~~
137682a6454SLiang Ma
1385dff9a72SAnatoly BurakovExisting power management mechanisms require developers to change application
1395dff9a72SAnatoly Burakovdesign or change code to make use of it. The PMD power management API provides a
1405dff9a72SAnatoly Burakovconvenient alternative by utilizing Ethernet PMD RX callbacks, and triggering
1415dff9a72SAnatoly Burakovpower saving whenever empty poll count reaches a certain number.
142682a6454SLiang Ma
1435dff9a72SAnatoly Burakov* Monitor
1445dff9a72SAnatoly Burakov   This power saving scheme will put the CPU into optimized power state and
1455dff9a72SAnatoly Burakov   monitor the Ethernet PMD RX descriptor address, waking the CPU up whenever
1465dff9a72SAnatoly Burakov   there's new traffic. Support for this scheme may not be available on all
1475dff9a72SAnatoly Burakov   platforms, and further limitations may apply (see below).
148682a6454SLiang Ma
1495dff9a72SAnatoly Burakov* Pause
1505dff9a72SAnatoly Burakov   This power saving scheme will avoid busy polling by either entering
1515dff9a72SAnatoly Burakov   power-optimized sleep state with ``rte_power_pause()`` function, or, if it's
1525dff9a72SAnatoly Burakov   not supported by the underlying platform, use ``rte_pause()``.
153682a6454SLiang Ma
1545dff9a72SAnatoly Burakov* Frequency scaling
1555dff9a72SAnatoly Burakov   This power saving scheme will use ``librte_power`` library functionality to
1565dff9a72SAnatoly Burakov   scale the core frequency up/down depending on traffic volume.
1577580f973SDavid Hunt   The reaction time of the frequency scaling mode is longer
1587580f973SDavid Hunt   than the pause and monitor mode.
159682a6454SLiang Ma
1605dff9a72SAnatoly BurakovThe "monitor" mode is only supported in the following configurations and scenarios:
161682a6454SLiang Ma
1625dff9a72SAnatoly Burakov* On Linux* x86_64, `rte_power_monitor()` requires WAITPKG instruction set being
163f53fe635SAnatoly Burakov  supported by the CPU, while `rte_power_monitor_multi()` requires WAITPKG and
164f53fe635SAnatoly Burakov  RTM instruction sets being supported by the CPU. RTM instruction set may also
165f53fe635SAnatoly Burakov  require booting the Linux with `tsx=on` command line parameter. Please refer
166f53fe635SAnatoly Burakov  to your platform documentation for further information.
1675dff9a72SAnatoly Burakov
1685dff9a72SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that
169f53fe635SAnatoly Burakov  ``rte_power_monitor_multi()`` function is supported by the platform, then
170f53fe635SAnatoly Burakov  monitoring multiple Ethernet Rx queues for traffic will be supported.
171f53fe635SAnatoly Burakov
172f53fe635SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that only
1735dff9a72SAnatoly Burakov  ``rte_power_monitor()`` is supported by the platform, then monitoring will be
1745dff9a72SAnatoly Burakov  limited to a mapping of 1 core 1 queue (thus, each Rx queue will have to be
1755dff9a72SAnatoly Burakov  monitored from a different lcore).
1765dff9a72SAnatoly Burakov
177f53fe635SAnatoly Burakov* If ``rte_cpu_get_intrinsics_support()`` function indicates that neither of the
178f53fe635SAnatoly Burakov  two monitoring functions are supported, then monitor mode will not be supported.
1795dff9a72SAnatoly Burakov
1805dff9a72SAnatoly Burakov* Not all Ethernet drivers support monitoring, even if the underlying
1815dff9a72SAnatoly Burakov  platform may support the necessary CPU instructions. Please refer to
1825dff9a72SAnatoly Burakov  :doc:`../nics/overview` for more information.
1835dff9a72SAnatoly Burakov
184682a6454SLiang Ma
185682a6454SLiang MaAPI Overview for Ethernet PMD Power Management
186682a6454SLiang Ma~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187682a6454SLiang Ma
188682a6454SLiang Ma* **Queue Enable**: Enable specific power scheme for certain queue/port/core.
189682a6454SLiang Ma
190682a6454SLiang Ma* **Queue Disable**: Disable power scheme for certain queue/port/core.
191682a6454SLiang Ma
1929e9e945bSKevin Laatz* **Get Emptypoll Max**: Get the configured number of empty polls to wait before
1939e9e945bSKevin Laatz  entering sleep state.
1949e9e945bSKevin Laatz
1959e9e945bSKevin Laatz* **Set Emptypoll Max**: Set the number of empty polls to wait before entering
1969e9e945bSKevin Laatz  sleep state.
1979e9e945bSKevin Laatz
1984a8fbc28SKevin Laatz* **Get Pause Duration**: Get the configured duration (microseconds) to be used
1994a8fbc28SKevin Laatz  in the Pause callback.
2004a8fbc28SKevin Laatz
2014a8fbc28SKevin Laatz* **Set Pause Duration**: Set the duration of the pause (microseconds) used in
2024a8fbc28SKevin Laatz  the Pause mode callback.
2034a8fbc28SKevin Laatz
20442651168SKevin Laatz* **Get Scaling Min Freq**: Get the configured minimum frequency (kHz) to be used
20542651168SKevin Laatz  in Frequency Scaling mode.
20642651168SKevin Laatz
20742651168SKevin Laatz* **Set Scaling Min Freq**: Set the minimum frequency (kHz) to be used in Frequency
20842651168SKevin Laatz  Scaling mode.
20942651168SKevin Laatz
21042651168SKevin Laatz* **Get Scaling Max Freq**: Get the configured maximum frequency (kHz) to be used
21142651168SKevin Laatz  in Frequency Scaling mode.
21242651168SKevin Laatz
21342651168SKevin Laatz* **Set Scaling Max Freq**: Set the maximum frequency (kHz) to be used in Frequency
21442651168SKevin Laatz  Scaling mode.
21542651168SKevin Laatz
216ebe99d35SSivaprasad TummalaUncore API
217ebe99d35SSivaprasad Tummala----------
21860b8a661STadhg Kearney
21960b8a661STadhg KearneyAbstract
22060b8a661STadhg Kearney~~~~~~~~
22160b8a661STadhg Kearney
22260b8a661STadhg KearneyUncore is a term used by Intel to describe the functions of a microprocessor
22360b8a661STadhg Kearneythat are not in the core, but which must be closely connected to the core
22460b8a661STadhg Kearneyto achieve high performance: L3 cache, on-die memory controller, etc.
22560b8a661STadhg KearneySignificant power savings can be achieved by reducing the uncore frequency
22660b8a661STadhg Kearneyto its lowest value.
22760b8a661STadhg Kearney
228da4d64d0SSivaprasad TummalaIntel Uncore
229da4d64d0SSivaprasad Tummala~~~~~~~~~~~~
230da4d64d0SSivaprasad Tummala
23160b8a661STadhg KearneyThe Linux kernel provides the driver "intel-uncore-frequency"
23260b8a661STadhg Kearneyto control the uncore frequency limits for x86 platform.
23360b8a661STadhg KearneyThe driver is available from kernel version 5.6 and above.
23460b8a661STadhg KearneyAlso CONFIG_INTEL_UNCORE_FREQ_CONTROL will need to be enabled in the kernel,
23560b8a661STadhg Kearneywhich was added in 5.6.
23660b8a661STadhg KearneyThis manipulates the context of MSR 0x620,
23760b8a661STadhg Kearneywhich sets min/max of the uncore for the SKU.
23860b8a661STadhg Kearney
239da4d64d0SSivaprasad TummalaAMD EPYC Uncore
240da4d64d0SSivaprasad Tummala~~~~~~~~~~~~~~~
241da4d64d0SSivaprasad Tummala
242da4d64d0SSivaprasad TummalaOn AMD EPYC platforms, the Host System Management Port (HSMP) kernel module
243da4d64d0SSivaprasad Tummalafacilitates user-level access to HSMP mailboxes,
244da4d64d0SSivaprasad Tummalawhich are implemented by the firmware in the System Management Unit (SMU).
245da4d64d0SSivaprasad TummalaThe AMD HSMP driver is available starting from kernel version 5.18.
246da4d64d0SSivaprasad TummalaPlease ensure that ``CONFIG_AMD_HSMP`` is enabled in your kernel configuration.
247da4d64d0SSivaprasad Tummala
248da4d64d0SSivaprasad TummalaAdditionally, the EPYC System Management Interface In-band Library for Linux
249da4d64d0SSivaprasad Tummalaoffers essential API, enabling user-space software
250da4d64d0SSivaprasad Tummalato effectively manage system functions.
251da4d64d0SSivaprasad Tummala
252ebe99d35SSivaprasad TummalaUncore API Overview
253ebe99d35SSivaprasad Tummala~~~~~~~~~~~~~~~~~~~
25460b8a661STadhg Kearney
255ebe99d35SSivaprasad TummalaOverview of each function in the Uncore API,
25660b8a661STadhg Kearneywith explanation of what they do.
25760b8a661STadhg KearneyEach function should not be called in the fast path.
25860b8a661STadhg Kearney
25960b8a661STadhg KearneyUncore Power Init
26060b8a661STadhg Kearney  Initialize uncore power, populate frequency array
26160b8a661STadhg Kearney  and record original min & max for die on pkg.
26260b8a661STadhg Kearney
26360b8a661STadhg KearneyUncore Power Exit
26460b8a661STadhg Kearney  Exit uncore power, restoring original min & max for die on pkg.
26560b8a661STadhg Kearney
26660b8a661STadhg KearneyGet Uncore Power Freq
26760b8a661STadhg Kearney  Get current uncore freq index for die on pkg.
26860b8a661STadhg Kearney
26960b8a661STadhg KearneySet Uncore Power Freq
27060b8a661STadhg Kearney  Set min & max uncore freq index for die on pkg
27160b8a661STadhg Kearney  to specified index value (min and max will be the same).
27260b8a661STadhg Kearney
27360b8a661STadhg KearneyUncore Power Max
27460b8a661STadhg Kearney  Set min & max uncore freq to maximum frequency index for die on pkg
27560b8a661STadhg Kearney  (min and max will be the same).
27660b8a661STadhg Kearney
27760b8a661STadhg KearneyUncore Power Min
27860b8a661STadhg Kearney  Set min & max uncore freq to minimum frequency index for die on pkg
27960b8a661STadhg Kearney  (min and max will be the same).
28060b8a661STadhg Kearney
28160b8a661STadhg KearneyGet Num Freqs
28260b8a661STadhg Kearney  Get the number of frequencies in the index array.
28360b8a661STadhg Kearney
28460b8a661STadhg KearneyGet Num Pkgs
28560b8a661STadhg Kearney  Get the number of packages (CPU's) on the system.
28660b8a661STadhg Kearney
28760b8a661STadhg KearneyGet Num Dies
28860b8a661STadhg Kearney  Get the number of die's on a given package.
28960b8a661STadhg Kearney
290fc1f2750SBernard IremongerReferences
291fc1f2750SBernard Iremonger----------
292fc1f2750SBernard Iremonger
293fa77f80fSDavid Hunt*   The :doc:`../sample_app_ug/l3_forward_power_man`
294fa77f80fSDavid Hunt    chapter in the :doc:`../sample_app_ug/index` section.
295fc1f2750SBernard Iremonger
296fa77f80fSDavid Hunt*   The :doc:`../sample_app_ug/vm_power_management`
297fa77f80fSDavid Hunt    chapter in the :doc:`../sample_app_ug/index` section.
2985dff9a72SAnatoly Burakov
2995dff9a72SAnatoly Burakov*   The :doc:`../nics/overview` chapter in the :doc:`../nics/index` section
300