amd-pstate.rst 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. ===============================================
  4. ``amd-pstate`` CPU Performance Scaling Driver
  5. ===============================================
  6. :Copyright: |copy| 2021 Advanced Micro Devices, Inc.
  7. :Author: Huang Rui <ray.huang@amd.com>
  8. Introduction
  9. ===================
  10. ``amd-pstate`` is the AMD CPU performance scaling driver that introduces a
  11. new CPU frequency control mechanism on modern AMD APU and CPU series in
  12. Linux kernel. The new mechanism is based on Collaborative Processor
  13. Performance Control (CPPC) which provides finer grain frequency management
  14. than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using
  15. the ACPI P-states driver to manage CPU frequency and clocks with switching
  16. only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a
  17. flexible, low-latency interface for the Linux kernel to directly
  18. communicate the performance hints to hardware.
  19. ``amd-pstate`` leverages the Linux kernel governors such as ``schedutil``,
  20. ``ondemand``, etc. to manage the performance hints which are provided by
  21. CPPC hardware functionality that internally follows the hardware
  22. specification (for details refer to AMD64 Architecture Programmer's Manual
  23. Volume 2: System Programming [1]_). Currently, ``amd-pstate`` supports basic
  24. frequency control function according to kernel governors on some of the
  25. Zen2 and Zen3 processors, and we will implement more AMD specific functions
  26. in future after we verify them on the hardware and SBIOS.
  27. AMD CPPC Overview
  28. =======================
  29. Collaborative Processor Performance Control (CPPC) interface enumerates a
  30. continuous, abstract, and unit-less performance value in a scale that is
  31. not tied to a specific performance state / frequency. This is an ACPI
  32. standard [2]_ which software can specify application performance goals and
  33. hints as a relative target to the infrastructure limits. AMD processors
  34. provide the low latency register model (MSR) instead of an AML code
  35. interpreter for performance adjustments. ``amd-pstate`` will initialize a
  36. ``struct cpufreq_driver`` instance, ``amd_pstate_driver``, with the callbacks
  37. to manage each performance update behavior. ::
  38. Highest Perf ------>+-----------------------+ +-----------------------+
  39. | | | |
  40. | | | |
  41. | | Max Perf ---->| |
  42. | | | |
  43. | | | |
  44. Nominal Perf ------>+-----------------------+ +-----------------------+
  45. | | | |
  46. | | | |
  47. | | | |
  48. | | | |
  49. | | | |
  50. | | | |
  51. | | Desired Perf ---->| |
  52. | | | |
  53. | | | |
  54. | | | |
  55. | | | |
  56. | | | |
  57. | | | |
  58. | | | |
  59. | | | |
  60. | | | |
  61. Lowest non- | | | |
  62. linear perf ------>+-----------------------+ +-----------------------+
  63. | | | |
  64. | | Lowest perf ---->| |
  65. | | | |
  66. Lowest perf ------>+-----------------------+ +-----------------------+
  67. | | | |
  68. | | | |
  69. | | | |
  70. 0 ------>+-----------------------+ +-----------------------+
  71. AMD P-States Performance Scale
  72. .. _perf_cap:
  73. AMD CPPC Performance Capability
  74. --------------------------------
  75. Highest Performance (RO)
  76. .........................
  77. This is the absolute maximum performance an individual processor may reach,
  78. assuming ideal conditions. This performance level may not be sustainable
  79. for long durations and may only be achievable if other platform components
  80. are in a specific state; for example, it may require other processors to be in
  81. an idle state. This would be equivalent to the highest frequencies
  82. supported by the processor.
  83. Nominal (Guaranteed) Performance (RO)
  84. ......................................
  85. This is the maximum sustained performance level of the processor, assuming
  86. ideal operating conditions. In the absence of an external constraint (power,
  87. thermal, etc.), this is the performance level the processor is expected to
  88. be able to maintain continuously. All cores/processors are expected to be
  89. able to sustain their nominal performance state simultaneously.
  90. Lowest non-linear Performance (RO)
  91. ...................................
  92. This is the lowest performance level at which nonlinear power savings are
  93. achieved, for example, due to the combined effects of voltage and frequency
  94. scaling. Above this threshold, lower performance levels should be generally
  95. more energy efficient than higher performance levels. This register
  96. effectively conveys the most efficient performance level to ``amd-pstate``.
  97. Lowest Performance (RO)
  98. ........................
  99. This is the absolute lowest performance level of the processor. Selecting a
  100. performance level lower than the lowest nonlinear performance level may
  101. cause an efficiency penalty but should reduce the instantaneous power
  102. consumption of the processor.
  103. AMD CPPC Performance Control
  104. ------------------------------
  105. ``amd-pstate`` passes performance goals through these registers. The
  106. register drives the behavior of the desired performance target.
  107. Minimum requested performance (RW)
  108. ...................................
  109. ``amd-pstate`` specifies the minimum allowed performance level.
  110. Maximum requested performance (RW)
  111. ...................................
  112. ``amd-pstate`` specifies a limit the maximum performance that is expected
  113. to be supplied by the hardware.
  114. Desired performance target (RW)
  115. ...................................
  116. ``amd-pstate`` specifies a desired target in the CPPC performance scale as
  117. a relative number. This can be expressed as percentage of nominal
  118. performance (infrastructure max). Below the nominal sustained performance
  119. level, desired performance expresses the average performance level of the
  120. processor subject to hardware. Above the nominal performance level,
  121. the processor must provide at least nominal performance requested and go higher
  122. if current operating conditions allow.
  123. Energy Performance Preference (EPP) (RW)
  124. .........................................
  125. This attribute provides a hint to the hardware if software wants to bias
  126. toward performance (0x0) or energy efficiency (0xff).
  127. Key Governors Support
  128. =======================
  129. ``amd-pstate`` can be used with all the (generic) scaling governors listed
  130. by the ``scaling_available_governors`` policy attribute in ``sysfs``. Then,
  131. it is responsible for the configuration of policy objects corresponding to
  132. CPUs and provides the ``CPUFreq`` core (and the scaling governors attached
  133. to the policy objects) with accurate information on the maximum and minimum
  134. operating frequencies supported by the hardware. Users can check the
  135. ``scaling_cur_freq`` information comes from the ``CPUFreq`` core.
  136. ``amd-pstate`` mainly supports ``schedutil`` and ``ondemand`` for dynamic
  137. frequency control. It is to fine tune the processor configuration on
  138. ``amd-pstate`` to the ``schedutil`` with CPU CFS scheduler. ``amd-pstate``
  139. registers the adjust_perf callback to implement performance update behavior
  140. similar to CPPC. It is initialized by ``sugov_start`` and then populates the
  141. CPU's update_util_data pointer to assign ``sugov_update_single_perf`` as the
  142. utilization update callback function in the CPU scheduler. The CPU scheduler
  143. will call ``cpufreq_update_util`` and assigns the target performance according
  144. to the ``struct sugov_cpu`` that the utilization update belongs to.
  145. Then, ``amd-pstate`` updates the desired performance according to the CPU
  146. scheduler assigned.
  147. .. _processor_support:
  148. Processor Support
  149. =======================
  150. The ``amd-pstate`` initialization will fail if the ``_CPC`` entry in the ACPI
  151. SBIOS does not exist in the detected processor. It uses ``acpi_cpc_valid``
  152. to check the existence of ``_CPC``. All Zen based processors support the legacy
  153. ACPI hardware P-States function, so when ``amd-pstate`` fails initialization,
  154. the kernel will fall back to initialize the ``acpi-cpufreq`` driver.
  155. There are two types of hardware implementations for ``amd-pstate``: one is
  156. `Full MSR Support <perf_cap_>`_ and another is `Shared Memory Support
  157. <perf_cap_>`_. It can use the :c:macro:`X86_FEATURE_CPPC` feature flag to
  158. indicate the different types. (For details, refer to the Processor Programming
  159. Reference (PPR) for AMD Family 19h Model 51h, Revision A1 Processors [3]_.)
  160. ``amd-pstate`` is to register different ``static_call`` instances for different
  161. hardware implementations.
  162. Currently, some of the Zen2 and Zen3 processors support ``amd-pstate``. In the
  163. future, it will be supported on more and more AMD processors.
  164. Full MSR Support
  165. -----------------
  166. Some new Zen3 processors such as Cezanne provide the MSR registers directly
  167. while the :c:macro:`X86_FEATURE_CPPC` CPU feature flag is set.
  168. ``amd-pstate`` can handle the MSR register to implement the fast switch
  169. function in ``CPUFreq`` that can reduce the latency of frequency control in
  170. interrupt context. The functions with a ``pstate_xxx`` prefix represent the
  171. operations on MSR registers.
  172. Shared Memory Support
  173. ----------------------
  174. If the :c:macro:`X86_FEATURE_CPPC` CPU feature flag is not set, the
  175. processor supports the shared memory solution. In this case, ``amd-pstate``
  176. uses the ``cppc_acpi`` helper methods to implement the callback functions
  177. that are defined on ``static_call``. The functions with the ``cppc_xxx`` prefix
  178. represent the operations of ACPI CPPC helpers for the shared memory solution.
  179. AMD P-States and ACPI hardware P-States always can be supported in one
  180. processor. But AMD P-States has the higher priority and if it is enabled
  181. with :c:macro:`MSR_AMD_CPPC_ENABLE` or ``cppc_set_enable``, it will respond
  182. to the request from AMD P-States.
  183. User Space Interface in ``sysfs`` - Per-policy control
  184. ======================================================
  185. ``amd-pstate`` exposes several global attributes (files) in ``sysfs`` to
  186. control its functionality at the system level. They are located in the
  187. ``/sys/devices/system/cpu/cpufreq/policyX/`` directory and affect all CPUs. ::
  188. root@hr-test1:/home/ray# ls /sys/devices/system/cpu/cpufreq/policy0/*amd*
  189. /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_highest_perf
  190. /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_lowest_nonlinear_freq
  191. /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_max_freq
  192. ``amd_pstate_highest_perf / amd_pstate_max_freq``
  193. Maximum CPPC performance and CPU frequency that the driver is allowed to
  194. set, in percent of the maximum supported CPPC performance level (the highest
  195. performance supported in `AMD CPPC Performance Capability <perf_cap_>`_).
  196. In some ASICs, the highest CPPC performance is not the one in the ``_CPC``
  197. table, so we need to expose it to sysfs. If boost is not active, but
  198. still supported, this maximum frequency will be larger than the one in
  199. ``cpuinfo``. On systems that support preferred core, the driver will have
  200. different values for some cores than others and this will reflect the values
  201. advertised by the platform at bootup.
  202. This attribute is read-only.
  203. ``amd_pstate_lowest_nonlinear_freq``
  204. The lowest non-linear CPPC CPU frequency that the driver is allowed to set,
  205. in percent of the maximum supported CPPC performance level. (Please see the
  206. lowest non-linear performance in `AMD CPPC Performance Capability
  207. <perf_cap_>`_.)
  208. This attribute is read-only.
  209. ``amd_pstate_hw_prefcore``
  210. Whether the platform supports the preferred core feature and it has been
  211. enabled. This attribute is read-only.
  212. ``amd_pstate_prefcore_ranking``
  213. The performance ranking of the core. This number doesn't have any unit, but
  214. larger numbers are preferred at the time of reading. This can change at
  215. runtime based on platform conditions. This attribute is read-only.
  216. ``energy_performance_available_preferences``
  217. A list of all the supported EPP preferences that could be used for
  218. ``energy_performance_preference`` on this system.
  219. These profiles represent different hints that are provided
  220. to the low-level firmware about the user's desired energy vs efficiency
  221. tradeoff. ``default`` represents the epp value is set by platform
  222. firmware. This attribute is read-only.
  223. ``energy_performance_preference``
  224. The current energy performance preference can be read from this attribute.
  225. and user can change current preference according to energy or performance needs
  226. Please get all support profiles list from
  227. ``energy_performance_available_preferences`` attribute, all the profiles are
  228. integer values defined between 0 to 255 when EPP feature is enabled by platform
  229. firmware, if EPP feature is disabled, driver will ignore the written value
  230. This attribute is read-write.
  231. ``boost``
  232. The `boost` sysfs attribute provides control over the CPU core
  233. performance boost, allowing users to manage the maximum frequency limitation
  234. of the CPU. This attribute can be used to enable or disable the boost feature
  235. on individual CPUs.
  236. When the boost feature is enabled, the CPU can dynamically increase its frequency
  237. beyond the base frequency, providing enhanced performance for demanding workloads.
  238. On the other hand, disabling the boost feature restricts the CPU to operate at the
  239. base frequency, which may be desirable in certain scenarios to prioritize power
  240. efficiency or manage temperature.
  241. To manipulate the `boost` attribute, users can write a value of `0` to disable the
  242. boost or `1` to enable it, for the respective CPU using the sysfs path
  243. `/sys/devices/system/cpu/cpuX/cpufreq/boost`, where `X` represents the CPU number.
  244. Other performance and frequency values can be read back from
  245. ``/sys/devices/system/cpu/cpuX/acpi_cppc/``, see :ref:`cppc_sysfs`.
  246. ``amd-pstate`` vs ``acpi-cpufreq``
  247. ======================================
  248. On the majority of AMD platforms supported by ``acpi-cpufreq``, the ACPI tables
  249. provided by the platform firmware are used for CPU performance scaling, but
  250. only provide 3 P-states on AMD processors.
  251. However, on modern AMD APU and CPU series, hardware provides the Collaborative
  252. Processor Performance Control according to the ACPI protocol and customizes this
  253. for AMD platforms. That is, fine-grained and continuous frequency ranges
  254. instead of the legacy hardware P-states. ``amd-pstate`` is the kernel
  255. module which supports the new AMD P-States mechanism on most of the future AMD
  256. platforms. The AMD P-States mechanism is the more performance and energy
  257. efficiency frequency management method on AMD processors.
  258. ``amd-pstate`` Driver Operation Modes
  259. ======================================
  260. ``amd_pstate`` CPPC has 3 operation modes: autonomous (active) mode,
  261. non-autonomous (passive) mode and guided autonomous (guided) mode.
  262. Active/passive/guided mode can be chosen by different kernel parameters.
  263. - In autonomous mode, platform ignores the desired performance level request
  264. and takes into account only the values set to the minimum, maximum and energy
  265. performance preference registers.
  266. - In non-autonomous mode, platform gets desired performance level
  267. from OS directly through Desired Performance Register.
  268. - In guided-autonomous mode, platform sets operating performance level
  269. autonomously according to the current workload and within the limits set by
  270. OS through min and max performance registers.
  271. Active Mode
  272. ------------
  273. ``amd_pstate=active``
  274. This is the low-level firmware control mode which is implemented by ``amd_pstate_epp``
  275. driver with ``amd_pstate=active`` passed to the kernel in the command line.
  276. In this mode, ``amd_pstate_epp`` driver provides a hint to the hardware if software
  277. wants to bias toward performance (0x0) or energy efficiency (0xff) to the CPPC firmware.
  278. then CPPC power algorithm will calculate the runtime workload and adjust the realtime
  279. cores frequency according to the power supply and thermal, core voltage and some other
  280. hardware conditions.
  281. Passive Mode
  282. ------------
  283. ``amd_pstate=passive``
  284. It will be enabled if the ``amd_pstate=passive`` is passed to the kernel in the command line.
  285. In this mode, ``amd_pstate`` driver software specifies a desired QoS target in the CPPC
  286. performance scale as a relative number. This can be expressed as percentage of nominal
  287. performance (infrastructure max). Below the nominal sustained performance level,
  288. desired performance expresses the average performance level of the processor subject
  289. to the Performance Reduction Tolerance register. Above the nominal performance level,
  290. processor must provide at least nominal performance requested and go higher if current
  291. operating conditions allow.
  292. Guided Mode
  293. -----------
  294. ``amd_pstate=guided``
  295. If ``amd_pstate=guided`` is passed to kernel command line option then this mode
  296. is activated. In this mode, driver requests minimum and maximum performance
  297. level and the platform autonomously selects a performance level in this range
  298. and appropriate to the current workload.
  299. ``amd-pstate`` Preferred Core
  300. =================================
  301. The core frequency is subjected to the process variation in semiconductors.
  302. Not all cores are able to reach the maximum frequency respecting the
  303. infrastructure limits. Consequently, AMD has redefined the concept of
  304. maximum frequency of a part. This means that a fraction of cores can reach
  305. maximum frequency. To find the best process scheduling policy for a given
  306. scenario, OS needs to know the core ordering informed by the platform through
  307. highest performance capability register of the CPPC interface.
  308. ``amd-pstate`` preferred core enables the scheduler to prefer scheduling on
  309. cores that can achieve a higher frequency with lower voltage. The preferred
  310. core rankings can dynamically change based on the workload, platform conditions,
  311. thermals and ageing.
  312. The priority metric will be initialized by the ``amd-pstate`` driver. The ``amd-pstate``
  313. driver will also determine whether or not ``amd-pstate`` preferred core is
  314. supported by the platform.
  315. ``amd-pstate`` driver will provide an initial core ordering when the system boots.
  316. The platform uses the CPPC interfaces to communicate the core ranking to the
  317. operating system and scheduler to make sure that OS is choosing the cores
  318. with highest performance firstly for scheduling the process. When ``amd-pstate``
  319. driver receives a message with the highest performance change, it will
  320. update the core ranking and set the cpu's priority.
  321. ``amd-pstate`` Preferred Core Switch
  322. =====================================
  323. Kernel Parameters
  324. -----------------
  325. ``amd-pstate`` peferred core`` has two states: enable and disable.
  326. Enable/disable states can be chosen by different kernel parameters.
  327. Default enable ``amd-pstate`` preferred core.
  328. ``amd_prefcore=disable``
  329. For systems that support ``amd-pstate`` preferred core, the core rankings will
  330. always be advertised by the platform. But OS can choose to ignore that via the
  331. kernel parameter ``amd_prefcore=disable``.
  332. User Space Interface in ``sysfs`` - General
  333. ===========================================
  334. Global Attributes
  335. -----------------
  336. ``amd-pstate`` exposes several global attributes (files) in ``sysfs`` to
  337. control its functionality at the system level. They are located in the
  338. ``/sys/devices/system/cpu/amd_pstate/`` directory and affect all CPUs.
  339. ``status``
  340. Operation mode of the driver: "active", "passive", "guided" or "disable".
  341. "active"
  342. The driver is functional and in the ``active mode``
  343. "passive"
  344. The driver is functional and in the ``passive mode``
  345. "guided"
  346. The driver is functional and in the ``guided mode``
  347. "disable"
  348. The driver is unregistered and not functional now.
  349. This attribute can be written to in order to change the driver's
  350. operation mode or to unregister it. The string written to it must be
  351. one of the possible values of it and, if successful, writing one of
  352. these values to the sysfs file will cause the driver to switch over
  353. to the operation mode represented by that string - or to be
  354. unregistered in the "disable" case.
  355. ``prefcore``
  356. Preferred core state of the driver: "enabled" or "disabled".
  357. "enabled"
  358. Enable the ``amd-pstate`` preferred core.
  359. "disabled"
  360. Disable the ``amd-pstate`` preferred core
  361. This attribute is read-only to check the state of preferred core set
  362. by the kernel parameter.
  363. ``cpupower`` tool support for ``amd-pstate``
  364. ===============================================
  365. ``amd-pstate`` is supported by the ``cpupower`` tool, which can be used to dump
  366. frequency information. Development is in progress to support more and more
  367. operations for the new ``amd-pstate`` module with this tool. ::
  368. root@hr-test1:/home/ray# cpupower frequency-info
  369. analyzing CPU 0:
  370. driver: amd-pstate
  371. CPUs which run at the same hardware frequency: 0
  372. CPUs which need to have their frequency coordinated by software: 0
  373. maximum transition latency: 131 us
  374. hardware limits: 400 MHz - 4.68 GHz
  375. available cpufreq governors: ondemand conservative powersave userspace performance schedutil
  376. current policy: frequency should be within 400 MHz and 4.68 GHz.
  377. The governor "schedutil" may decide which speed to use
  378. within this range.
  379. current CPU frequency: Unable to call hardware
  380. current CPU frequency: 4.02 GHz (asserted by call to kernel)
  381. boost state support:
  382. Supported: yes
  383. Active: yes
  384. AMD PSTATE Highest Performance: 166. Maximum Frequency: 4.68 GHz.
  385. AMD PSTATE Nominal Performance: 117. Nominal Frequency: 3.30 GHz.
  386. AMD PSTATE Lowest Non-linear Performance: 39. Lowest Non-linear Frequency: 1.10 GHz.
  387. AMD PSTATE Lowest Performance: 15. Lowest Frequency: 400 MHz.
  388. Diagnostics and Tuning
  389. =======================
  390. Trace Events
  391. --------------
  392. There are two static trace events that can be used for ``amd-pstate``
  393. diagnostics. One of them is the ``cpu_frequency`` trace event generally used
  394. by ``CPUFreq``, and the other one is the ``amd_pstate_perf`` trace event
  395. specific to ``amd-pstate``. The following sequence of shell commands can
  396. be used to enable them and see their output (if the kernel is
  397. configured to support event tracing). ::
  398. root@hr-test1:/home/ray# cd /sys/kernel/tracing/
  399. root@hr-test1:/sys/kernel/tracing# echo 1 > events/amd_cpu/enable
  400. root@hr-test1:/sys/kernel/tracing# cat trace
  401. # tracer: nop
  402. #
  403. # entries-in-buffer/entries-written: 47827/42233061 #P:2
  404. #
  405. # _-----=> irqs-off
  406. # / _----=> need-resched
  407. # | / _---=> hardirq/softirq
  408. # || / _--=> preempt-depth
  409. # ||| / delay
  410. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  411. # | | | |||| | |
  412. <idle>-0 [015] dN... 4995.979886: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=15 changed=false fast_switch=true
  413. <idle>-0 [007] d.h.. 4995.979893: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=7 changed=false fast_switch=true
  414. cat-2161 [000] d.... 4995.980841: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=0 changed=false fast_switch=true
  415. sshd-2125 [004] d.s.. 4995.980968: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=4 changed=false fast_switch=true
  416. <idle>-0 [007] d.s.. 4995.980968: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=7 changed=false fast_switch=true
  417. <idle>-0 [003] d.s.. 4995.980971: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=3 changed=false fast_switch=true
  418. <idle>-0 [011] d.s.. 4995.980996: amd_pstate_perf: amd_min_perf=85 amd_des_perf=85 amd_max_perf=166 cpu_id=11 changed=false fast_switch=true
  419. The ``cpu_frequency`` trace event will be triggered either by the ``schedutil`` scaling
  420. governor (for the policies it is attached to), or by the ``CPUFreq`` core (for the
  421. policies with other scaling governors).
  422. Tracer Tool
  423. -------------
  424. ``amd_pstate_tracer.py`` can record and parse ``amd-pstate`` trace log, then
  425. generate performance plots. This utility can be used to debug and tune the
  426. performance of ``amd-pstate`` driver. The tracer tool needs to import intel
  427. pstate tracer.
  428. Tracer tool located in ``linux/tools/power/x86/amd_pstate_tracer``. It can be
  429. used in two ways. If trace file is available, then directly parse the file
  430. with command ::
  431. ./amd_pstate_trace.py [-c cpus] -t <trace_file> -n <test_name>
  432. Or generate trace file with root privilege, then parse and plot with command ::
  433. sudo ./amd_pstate_trace.py [-c cpus] -n <test_name> -i <interval> [-m kbytes]
  434. The test result can be found in ``results/test_name``. Following is the example
  435. about part of the output. ::
  436. common_cpu common_secs common_usecs min_perf des_perf max_perf freq mperf apef tsc load duration_ms sample_num elapsed_time common_comm
  437. CPU_005 712 116384 39 49 166 0.7565 9645075 2214891 38431470 25.1 11.646 469 2.496 kworker/5:0-40
  438. CPU_006 712 116408 39 49 166 0.6769 8950227 1839034 37192089 24.06 11.272 470 2.496 kworker/6:0-1264
  439. Unit Tests for amd-pstate
  440. -------------------------
  441. ``amd-pstate-ut`` is a test module for testing the ``amd-pstate`` driver.
  442. * It can help all users to verify their processor support (SBIOS/Firmware or Hardware).
  443. * Kernel can have a basic function test to avoid the kernel regression during the update.
  444. * We can introduce more functional or performance tests to align the result together, it will benefit power and performance scale optimization.
  445. 1. Test case descriptions
  446. 1). Basic tests
  447. Test prerequisite and basic functions for the ``amd-pstate`` driver.
  448. +---------+--------------------------------+------------------------------------------------------------------------------------+
  449. | Index | Functions | Description |
  450. +=========+================================+====================================================================================+
  451. | 1 | amd_pstate_ut_acpi_cpc_valid || Check whether the _CPC object is present in SBIOS. |
  452. | | || |
  453. | | || The detail refer to `Processor Support <processor_support_>`_. |
  454. +---------+--------------------------------+------------------------------------------------------------------------------------+
  455. | 2 | amd_pstate_ut_check_enabled || Check whether AMD P-State is enabled. |
  456. | | || |
  457. | | || AMD P-States and ACPI hardware P-States always can be supported in one processor. |
  458. | | | But AMD P-States has the higher priority and if it is enabled with |
  459. | | | :c:macro:`MSR_AMD_CPPC_ENABLE` or ``cppc_set_enable``, it will respond to the |
  460. | | | request from AMD P-States. |
  461. +---------+--------------------------------+------------------------------------------------------------------------------------+
  462. | 3 | amd_pstate_ut_check_perf || Check if the each performance values are reasonable. |
  463. | | || highest_perf >= nominal_perf > lowest_nonlinear_perf > lowest_perf > 0. |
  464. +---------+--------------------------------+------------------------------------------------------------------------------------+
  465. | 4 | amd_pstate_ut_check_freq || Check if the each frequency values and max freq when set support boost mode |
  466. | | | are reasonable. |
  467. | | || max_freq >= nominal_freq > lowest_nonlinear_freq > min_freq > 0 |
  468. | | || If boost is not active but supported, this maximum frequency will be larger than |
  469. | | | the one in ``cpuinfo``. |
  470. +---------+--------------------------------+------------------------------------------------------------------------------------+
  471. 2). Tbench test
  472. Test and monitor the cpu changes when running tbench benchmark under the specified governor.
  473. These changes include desire performance, frequency, load, performance, energy etc.
  474. The specified governor is ondemand or schedutil.
  475. Tbench can also be tested on the ``acpi-cpufreq`` kernel driver for comparison.
  476. 3). Gitsource test
  477. Test and monitor the cpu changes when running gitsource benchmark under the specified governor.
  478. These changes include desire performance, frequency, load, time, energy etc.
  479. The specified governor is ondemand or schedutil.
  480. Gitsource can also be tested on the ``acpi-cpufreq`` kernel driver for comparison.
  481. #. How to execute the tests
  482. We use test module in the kselftest frameworks to implement it.
  483. We create ``amd-pstate-ut`` module and tie it into kselftest.(for
  484. details refer to Linux Kernel Selftests [4]_).
  485. 1). Build
  486. + open the :c:macro:`CONFIG_X86_AMD_PSTATE` configuration option.
  487. + set the :c:macro:`CONFIG_X86_AMD_PSTATE_UT` configuration option to M.
  488. + make project
  489. + make selftest ::
  490. $ cd linux
  491. $ make -C tools/testing/selftests
  492. + make perf ::
  493. $ cd tools/perf/
  494. $ make
  495. 2). Installation & Steps ::
  496. $ make -C tools/testing/selftests install INSTALL_PATH=~/kselftest
  497. $ cp tools/perf/perf /usr/bin/perf
  498. $ sudo ./kselftest/run_kselftest.sh -c amd-pstate
  499. 3). Specified test case ::
  500. $ cd ~/kselftest/amd-pstate
  501. $ sudo ./run.sh -t basic
  502. $ sudo ./run.sh -t tbench
  503. $ sudo ./run.sh -t tbench -m acpi-cpufreq
  504. $ sudo ./run.sh -t gitsource
  505. $ sudo ./run.sh -t gitsource -m acpi-cpufreq
  506. $ ./run.sh --help
  507. ./run.sh: illegal option -- -
  508. Usage: ./run.sh [OPTION...]
  509. [-h <help>]
  510. [-o <output-file-for-dump>]
  511. [-c <all: All testing,
  512. basic: Basic testing,
  513. tbench: Tbench testing,
  514. gitsource: Gitsource testing.>]
  515. [-t <tbench time limit>]
  516. [-p <tbench process number>]
  517. [-l <loop times for tbench>]
  518. [-i <amd tracer interval>]
  519. [-m <comparative test: acpi-cpufreq>]
  520. 4). Results
  521. + basic
  522. When you finish test, you will get the following log info ::
  523. $ dmesg | grep "amd_pstate_ut" | tee log.txt
  524. [12977.570663] amd_pstate_ut: 1 amd_pstate_ut_acpi_cpc_valid success!
  525. [12977.570673] amd_pstate_ut: 2 amd_pstate_ut_check_enabled success!
  526. [12977.571207] amd_pstate_ut: 3 amd_pstate_ut_check_perf success!
  527. [12977.571212] amd_pstate_ut: 4 amd_pstate_ut_check_freq success!
  528. + tbench
  529. When you finish test, you will get selftest.tbench.csv and png images.
  530. The selftest.tbench.csv file contains the raw data and the drop of the comparative test.
  531. The png images shows the performance, energy and performan per watt of each test.
  532. Open selftest.tbench.csv :
  533. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  534. + Governor | Round | Des-perf | Freq | Load | Performance | Energy | Performance Per Watt |
  535. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  536. + Unit | | | GHz | | MB/s | J | MB/J |
  537. +=================================================+==============+==========+=========+==========+=============+=========+======================+
  538. + amd-pstate-ondemand | 1 | | | | 2504.05 | 1563.67 | 158.5378 |
  539. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  540. + amd-pstate-ondemand | 2 | | | | 2243.64 | 1430.32 | 155.2941 |
  541. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  542. + amd-pstate-ondemand | 3 | | | | 2183.88 | 1401.32 | 154.2860 |
  543. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  544. + amd-pstate-ondemand | Average | | | | 2310.52 | 1465.1 | 156.1268 |
  545. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  546. + amd-pstate-schedutil | 1 | 165.329 | 1.62257 | 99.798 | 2136.54 | 1395.26 | 151.5971 |
  547. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  548. + amd-pstate-schedutil | 2 | 166 | 1.49761 | 99.9993 | 2100.56 | 1380.5 | 150.6377 |
  549. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  550. + amd-pstate-schedutil | 3 | 166 | 1.47806 | 99.9993 | 2084.12 | 1375.76 | 149.9737 |
  551. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  552. + amd-pstate-schedutil | Average | 165.776 | 1.53275 | 99.9322 | 2107.07 | 1383.84 | 150.7399 |
  553. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  554. + acpi-cpufreq-ondemand | 1 | | | | 2529.9 | 1564.4 | 160.0997 |
  555. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  556. + acpi-cpufreq-ondemand | 2 | | | | 2249.76 | 1432.97 | 155.4297 |
  557. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  558. + acpi-cpufreq-ondemand | 3 | | | | 2181.46 | 1406.88 | 153.5060 |
  559. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  560. + acpi-cpufreq-ondemand | Average | | | | 2320.37 | 1468.08 | 156.4741 |
  561. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  562. + acpi-cpufreq-schedutil | 1 | | | | 2137.64 | 1385.24 | 152.7723 |
  563. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  564. + acpi-cpufreq-schedutil | 2 | | | | 2107.05 | 1372.23 | 152.0138 |
  565. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  566. + acpi-cpufreq-schedutil | 3 | | | | 2085.86 | 1365.35 | 151.2433 |
  567. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  568. + acpi-cpufreq-schedutil | Average | | | | 2110.18 | 1374.27 | 152.0136 |
  569. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  570. + acpi-cpufreq-ondemand VS acpi-cpufreq-schedutil | Comprison(%) | | | | -9.0584 | -6.3899 | -2.8506 |
  571. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  572. + amd-pstate-ondemand VS amd-pstate-schedutil | Comprison(%) | | | | 8.8053 | -5.5463 | -3.4503 |
  573. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  574. + acpi-cpufreq-ondemand VS amd-pstate-ondemand | Comprison(%) | | | | -0.4245 | -0.2029 | -0.2219 |
  575. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  576. + acpi-cpufreq-schedutil VS amd-pstate-schedutil | Comprison(%) | | | | -0.1473 | 0.6963 | -0.8378 |
  577. +-------------------------------------------------+--------------+----------+---------+----------+-------------+---------+----------------------+
  578. + gitsource
  579. When you finish test, you will get selftest.gitsource.csv and png images.
  580. The selftest.gitsource.csv file contains the raw data and the drop of the comparative test.
  581. The png images shows the performance, energy and performan per watt of each test.
  582. Open selftest.gitsource.csv :
  583. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  584. + Governor | Round | Des-perf | Freq | Load | Time | Energy | Performance Per Watt |
  585. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  586. + Unit | | | GHz | | s | J | 1/J |
  587. +=================================================+==============+==========+==========+==========+=============+=========+======================+
  588. + amd-pstate-ondemand | 1 | 50.119 | 2.10509 | 23.3076 | 475.69 | 865.78 | 0.001155027 |
  589. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  590. + amd-pstate-ondemand | 2 | 94.8006 | 1.98771 | 56.6533 | 467.1 | 839.67 | 0.001190944 |
  591. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  592. + amd-pstate-ondemand | 3 | 76.6091 | 2.53251 | 43.7791 | 467.69 | 855.85 | 0.001168429 |
  593. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  594. + amd-pstate-ondemand | Average | 73.8429 | 2.20844 | 41.2467 | 470.16 | 853.767 | 0.001171279 |
  595. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  596. + amd-pstate-schedutil | 1 | 165.919 | 1.62319 | 98.3868 | 464.17 | 866.8 | 0.001153668 |
  597. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  598. + amd-pstate-schedutil | 2 | 165.97 | 1.31309 | 99.5712 | 480.15 | 880.4 | 0.001135847 |
  599. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  600. + amd-pstate-schedutil | 3 | 165.973 | 1.28448 | 99.9252 | 481.79 | 867.02 | 0.001153375 |
  601. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  602. + amd-pstate-schedutil | Average | 165.954 | 1.40692 | 99.2944 | 475.37 | 871.407 | 0.001147569 |
  603. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  604. + acpi-cpufreq-ondemand | 1 | | | | 2379.62 | 742.96 | 0.001345967 |
  605. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  606. + acpi-cpufreq-ondemand | 2 | | | | 441.74 | 817.49 | 0.001223256 |
  607. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  608. + acpi-cpufreq-ondemand | 3 | | | | 455.48 | 820.01 | 0.001219497 |
  609. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  610. + acpi-cpufreq-ondemand | Average | | | | 425.613 | 793.487 | 0.001260260 |
  611. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  612. + acpi-cpufreq-schedutil | 1 | | | | 459.69 | 838.54 | 0.001192548 |
  613. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  614. + acpi-cpufreq-schedutil | 2 | | | | 466.55 | 830.89 | 0.001203528 |
  615. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  616. + acpi-cpufreq-schedutil | 3 | | | | 470.38 | 837.32 | 0.001194286 |
  617. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  618. + acpi-cpufreq-schedutil | Average | | | | 465.54 | 835.583 | 0.001196769 |
  619. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  620. + acpi-cpufreq-ondemand VS acpi-cpufreq-schedutil | Comprison(%) | | | | 9.3810 | 5.3051 | -5.0379 |
  621. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  622. + amd-pstate-ondemand VS amd-pstate-schedutil | Comprison(%) | 124.7392 | -36.2934 | 140.7329 | 1.1081 | 2.0661 | -2.0242 |
  623. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  624. + acpi-cpufreq-ondemand VS amd-pstate-ondemand | Comprison(%) | | | | 10.4665 | 7.5968 | -7.0605 |
  625. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  626. + acpi-cpufreq-schedutil VS amd-pstate-schedutil | Comprison(%) | | | | 2.1115 | 4.2873 | -4.1110 |
  627. +-------------------------------------------------+--------------+----------+----------+----------+-------------+---------+----------------------+
  628. Reference
  629. ===========
  630. .. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming,
  631. https://www.amd.com/system/files/TechDocs/24593.pdf
  632. .. [2] Advanced Configuration and Power Interface Specification,
  633. https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf
  634. .. [3] Processor Programming Reference (PPR) for AMD Family 19h Model 51h, Revision A1 Processors
  635. https://www.amd.com/system/files/TechDocs/56569-A1-PUB.zip
  636. .. [4] Linux Kernel Selftests,
  637. https://www.kernel.org/doc/html/latest/dev-tools/kselftest.html