Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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