Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 1 | Kernel driver fam15h_power |
| 2 | ========================== |
| 3 | |
| 4 | Supported chips: |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 5 | |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 6 | * AMD Family 15h Processors |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 7 | |
Huang Rui | 5aeb5d2 | 2015-08-27 16:07:37 +0800 | [diff] [blame] | 8 | * AMD Family 16h Processors |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 9 | |
| 10 | Prefix: 'fam15h_power' |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 11 | |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 12 | Addresses scanned: PCI space |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 13 | |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 14 | Datasheets: |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 15 | |
| 16 | - BIOS and Kernel Developer's Guide (BKDG) For AMD Family 15h Processors |
| 17 | - BIOS and Kernel Developer's Guide (BKDG) For AMD Family 16h Processors |
| 18 | - AMD64 Architecture Programmer's Manual Volume 2: System Programming |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 19 | |
Andreas Herrmann | d034fbf | 2012-10-29 18:50:47 +0100 | [diff] [blame] | 20 | Author: Andreas Herrmann <herrmann.der.user@googlemail.com> |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 21 | |
| 22 | Description |
| 23 | ----------- |
| 24 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 25 | 1) Processor TDP (Thermal design power) |
| 26 | |
| 27 | Given a fixed frequency and voltage, the power consumption of a |
| 28 | processor varies based on the workload being executed. Derated power |
| 29 | is the power consumed when running a specific application. Thermal |
| 30 | design power (TDP) is an example of derated power. |
| 31 | |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 32 | This driver permits reading of registers providing power information |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 33 | of AMD Family 15h and 16h processors via TDP algorithm. |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 34 | |
Huang Rui | 5aeb5d2 | 2015-08-27 16:07:37 +0800 | [diff] [blame] | 35 | For AMD Family 15h and 16h processors the following power values can |
| 36 | be calculated using different processor northbridge function |
| 37 | registers: |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 38 | |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 39 | * BasePwrWatts: |
| 40 | Specifies in watts the maximum amount of power |
| 41 | consumed by the processor for NB and logic external to the core. |
| 42 | |
| 43 | * ProcessorPwrWatts: |
| 44 | Specifies in watts the maximum amount of power |
| 45 | the processor can support. |
| 46 | * CurrPwrWatts: |
| 47 | Specifies in watts the current amount of power being |
| 48 | consumed by the processor. |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 49 | |
| 50 | This driver provides ProcessorPwrWatts and CurrPwrWatts: |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 51 | |
Andreas Herrmann | 512d102 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 52 | * power1_crit (ProcessorPwrWatts) |
| 53 | * power1_input (CurrPwrWatts) |
| 54 | |
| 55 | On multi-node processors the calculated value is for the entire |
| 56 | package and not for a single node. Thus the driver creates sysfs |
| 57 | attributes only for internal node0 of a multi-node processor. |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 58 | |
| 59 | 2) Accumulated Power Mechanism |
| 60 | |
| 61 | This driver also introduces an algorithm that should be used to |
| 62 | calculate the average power consumed by a processor during a |
| 63 | measurement interval Tm. The feature of accumulated power mechanism is |
| 64 | indicated by CPUID Fn8000_0007_EDX[12]. |
| 65 | |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 66 | * Tsample: |
| 67 | compute unit power accumulator sample period |
| 68 | |
| 69 | * Tref: |
| 70 | the PTSC counter period |
| 71 | |
| 72 | * PTSC: |
| 73 | performance timestamp counter |
| 74 | |
| 75 | * N: |
| 76 | the ratio of compute unit power accumulator sample period to the |
| 77 | PTSC period |
| 78 | |
| 79 | * Jmax: |
| 80 | max compute unit accumulated power which is indicated by |
| 81 | MaxCpuSwPwrAcc MSR C001007b |
| 82 | |
| 83 | * Jx/Jy: |
| 84 | compute unit accumulated power which is indicated by |
| 85 | CpuSwPwrAcc MSR C001007a |
| 86 | * Tx/Ty: |
| 87 | the value of performance timestamp counter which is indicated |
| 88 | by CU_PTSC MSR C0010280 |
| 89 | |
| 90 | * PwrCPUave: |
| 91 | CPU average power |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 92 | |
| 93 | i. Determine the ratio of Tsample to Tref by executing CPUID Fn8000_0007. |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 94 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 95 | N = value of CPUID Fn8000_0007_ECX[CpuPwrSampleTimeRatio[15:0]]. |
| 96 | |
| 97 | ii. Read the full range of the cumulative energy value from the new |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 98 | MSR MaxCpuSwPwrAcc. |
| 99 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 100 | Jmax = value returned. |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 101 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 102 | iii. At time x, SW reads CpuSwPwrAcc MSR and samples the PTSC. |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 103 | |
| 104 | Jx = value read from CpuSwPwrAcc and Tx = value read from PTSC. |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 105 | |
| 106 | iv. At time y, SW reads CpuSwPwrAcc MSR and samples the PTSC. |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 107 | |
| 108 | Jy = value read from CpuSwPwrAcc and Ty = value read from PTSC. |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 109 | |
| 110 | v. Calculate the average power consumption for a compute unit over |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 111 | time period (y-x). Unit of result is uWatt:: |
| 112 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 113 | if (Jy < Jx) // Rollover has occurred |
| 114 | Jdelta = (Jy + Jmax) - Jx |
| 115 | else |
| 116 | Jdelta = Jy - Jx |
| 117 | PwrCPUave = N * Jdelta * 1000 / (Ty - Tx) |
| 118 | |
| 119 | This driver provides PwrCPUave and interval(default is 10 millisecond |
| 120 | and maximum is 1 second): |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 121 | |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 122 | * power1_average (PwrCPUave) |
| 123 | * power1_average_interval (Interval) |
| 124 | |
| 125 | The power1_average_interval can be updated at /etc/sensors3.conf file |
| 126 | as below: |
| 127 | |
Mauro Carvalho Chehab | b413e3f | 2019-04-17 06:46:15 -0300 | [diff] [blame] | 128 | chip `fam15h_power-*` |
Huang Rui | a6e232f | 2016-04-06 15:44:14 +0800 | [diff] [blame] | 129 | set power1_average_interval 0.01 |
| 130 | |
| 131 | Then save it with "sensors -s". |