^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Intel Powerclamp Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) By:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) - Arjan van de Ven <arjan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) - Jacob Pan <jacob.jun.pan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) .. Contents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) (*) Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) - Goals and Objectives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) (*) Theory of Operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) - Idle Injection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) - Calibration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) (*) Performance Analysis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) - Effectiveness and Limitations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) - Power vs Performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) - Scalability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) - Calibration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) - Comparison with Alternative Techniques
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) (*) Usage and Interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) - Generic Thermal Layer (sysfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) - Kernel APIs (TBD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) INTRODUCTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) Consider the situation where a system’s power consumption must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) reduced at runtime, due to power budget, thermal constraint, or noise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) level, and where active cooling is not preferred. Software managed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) passive power reduction must be performed to prevent the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) actions that are designed for catastrophic scenarios.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) Currently, P-states, T-states (clock modulation), and CPU offlining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) are used for CPU throttling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) On Intel CPUs, C-states provide effective power reduction, but so far
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) they’re only used opportunistically, based on workload. With the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) development of intel_powerclamp driver, the method of synchronizing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) idle injection across all online CPU threads was introduced. The goal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) is to achieve forced and controllable C-state residency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) Test/Analysis has been made in the areas of power, performance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) scalability, and user experience. In many cases, clear advantage is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) shown over taking the CPU offline or modulating the CPU clock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) THEORY OF OPERATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) Idle Injection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) On modern Intel processors (Nehalem or later), package level C-state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) residency is available in MSRs, thus also available to the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) These MSRs are::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define MSR_PKG_C2_RESIDENCY 0x60D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define MSR_PKG_C3_RESIDENCY 0x3F8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define MSR_PKG_C6_RESIDENCY 0x3F9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define MSR_PKG_C7_RESIDENCY 0x3FA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) If the kernel can also inject idle time to the system, then a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) closed-loop control system can be established that manages package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) level C-state. The intel_powerclamp driver is conceived as such a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) control system, where the target set point is a user-selected idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ratio (based on power reduction), and the error is the difference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) between the actual package level C-state residency ratio and the target idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ratio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) Injection is controlled by high priority kernel threads, spawned for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) each online CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) These kernel threads, with SCHED_FIFO class, are created to perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) clamping actions of controlled duty ratio and duration. Each per-CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) thread synchronizes its idle time and duration, based on the rounding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) of jiffies, so accumulated errors can be prevented to avoid a jittery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) effect. Threads are also bound to the CPU such that they cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) migrated, unless the CPU is taken offline. In this case, threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) belong to the offlined CPUs will be terminated immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) Running as SCHED_FIFO and relatively high priority, also allows such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) scheme to work for both preemptable and non-preemptable kernels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) Alignment of idle time around jiffies ensures scalability for HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) values. This effect can be better visualized using a Perf timechart.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) The following diagram shows the behavior of kernel thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) kidle_inject/cpu. During idle injection, it runs monitor/mwait idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) for a given "duration", then relinquishes the CPU to other tasks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) until the next time interval.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) The NOHZ schedule tick is disabled during idle time, but interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) are not masked. Tests show that the extra wakeups from scheduler tick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) have a dramatic impact on the effectiveness of the powerclamp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) on large scale systems (Westmere system with 80 processors).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) CPU0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ____________ ____________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) kidle_inject/0 | sleep | mwait | sleep |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) _________| |________| |_______
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) duration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) CPU1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ____________ ____________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) kidle_inject/1 | sleep | mwait | sleep |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) _________| |________| |_______
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) roundup(jiffies, interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) Only one CPU is allowed to collect statistics and update global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) control parameters. This CPU is referred to as the controlling CPU in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) this document. The controlling CPU is elected at runtime, with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) policy that favors BSP, taking into account the possibility of a CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) hot-plug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) In terms of dynamics of the idle control system, package level idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) time is considered largely as a non-causal system where its behavior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cannot be based on the past or current input. Therefore, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) intel_powerclamp driver attempts to enforce the desired idle time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) instantly as given input (target idle ratio). After injection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) powerclamp monitors the actual idle for a given time window and adjust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) the next injection accordingly to avoid over/under correction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) When used in a causal control system, such as a temperature control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) it is up to the user of this driver to implement algorithms where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) past samples and outputs are included in the feedback. For example, a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) PID-based thermal controller can use the powerclamp driver to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) maintain a desired target temperature, based on integral and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) derivative gains of the past samples.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) Calibration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) During scalability testing, it is observed that synchronized actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) among CPUs become challenging as the number of cores grows. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) also true for the ability of a system to enter package level C-states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) To make sure the intel_powerclamp driver scales well, online
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) calibration is implemented. The goals for doing such a calibration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) a) determine the effective range of idle injection ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) b) determine the amount of compensation needed at each target ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) Compensation to each target ratio consists of two parts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) a) steady state error compensation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) This is to offset the error occurring when the system can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) enter idle without extra wakeups (such as external interrupts).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) b) dynamic error compensation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) When an excessive amount of wakeups occurs during idle, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) additional idle ratio can be added to quiet interrupts, by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) slowing down CPU activities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) A debugfs file is provided for the user to examine compensation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) progress and results, such as on a Westmere system::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) [jacob@nex01 ~]$ cat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /sys/kernel/debug/intel_powerclamp/powerclamp_calib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) controlling cpu: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pct confidence steady dynamic (compensation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 0 0 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 1 1 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 2 1 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 3 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 4 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 5 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 6 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 7 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 8 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 30 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 31 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 32 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 33 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 34 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 35 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 36 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 37 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 38 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 39 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 40 3 3 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 41 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 42 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 43 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 44 3 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 45 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 46 3 3 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 47 3 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 48 3 2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 49 3 3 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) Calibration occurs during runtime. No offline method is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) Steady state compensation is used only when confidence levels of all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) adjacent ratios have reached satisfactory level. A confidence level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) is accumulated based on clean data collected at runtime. Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) collected during a period without extra interrupts is considered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) clean.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) To compensate for excessive amounts of wakeup during idle, additional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) idle time is injected when such a condition is detected. Currently,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) we have a simple algorithm to double the injection ratio. A possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) enhancement might be to throttle the offending IRQ, such as delaying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) EOI for level triggered interrupts. But it is a challenge to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) non-intrusive to the scheduler or the IRQ core code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) CPU Online/Offline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) Per-CPU kernel threads are started/stopped upon receiving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) notifications of CPU hotplug activities. The intel_powerclamp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) keeps track of clamping kernel threads, even after they are migrated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) to other CPUs, after a CPU offline event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) Performance Analysis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) This section describes the general performance data collected on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) multiple systems, including Westmere (80P) and Ivy Bridge (4P, 8P).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) Effectiveness and Limitations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) The maximum range that idle injection is allowed is capped at 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) percent. As mentioned earlier, since interrupts are allowed during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) forced idle time, excessive interrupts could result in less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) effectiveness. The extreme case would be doing a ping -f to generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) flooded network interrupts without much CPU acknowledgement. In this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case, little can be done from the idle injection threads. In most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) normal cases, such as scp a large file, applications can be throttled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) by the powerclamp driver, since slowing down the CPU also slows down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) network protocol processing, which in turn reduces interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) When control parameters change at runtime by the controlling CPU, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) may take an additional period for the rest of the CPUs to catch up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) with the changes. During this time, idle injection is out of sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) thus not able to enter package C- states at the expected ratio. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) this effect is minor, in that in most cases change to the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ratio is updated much less frequently than the idle injection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) frequency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) Scalability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) Tests also show a minor, but measurable, difference between the 4P/8P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) Ivy Bridge system and the 80P Westmere server under 50% idle ratio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) More compensation is needed on Westmere for the same amount of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) target idle ratio. The compensation also increases as the idle ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) gets larger. The above reason constitutes the need for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) calibration code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) On the IVB 8P system, compared to an offline CPU, powerclamp can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) achieve up to 40% better performance per watt. (measured by a spin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) counter summed over per CPU counting threads spawned for all running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) CPUs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) Usage and Interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) The powerclamp driver is registered to the generic thermal layer as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) cooling device. Currently, it’s not bound to any thermal zones::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) jacob@chromoly:/sys/class/thermal/cooling_device14$ grep . *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) cur_state:0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) max_state:50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) type:intel_powerclamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) cur_state allows user to set the desired idle percentage. Writing 0 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) cur_state will stop idle injection. Writing a value between 1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) max_state will start the idle injection. Reading cur_state returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) actual and current idle percentage. This may not be the same value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) set by the user in that current idle percentage depends on workload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) and includes natural idle. When idle injection is disabled, reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) cur_state returns value -1 instead of 0 which is to avoid confusing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 100% busy state with the disabled state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) Example usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) - To inject 25% idle time::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) $ sudo sh -c "echo 25 > /sys/class/thermal/cooling_device80/cur_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) If the system is not busy and has more than 25% idle time already,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) then the powerclamp driver will not start idle injection. Using Top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) will not show idle injection kernel threads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) If the system is busy (spin test below) and has less than 25% natural
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) idle time, powerclamp kernel threads will do idle injection. Forced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) idle time is accounted as normal idle in that common code path is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) taken as the idle task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) In this example, 24.1% idle is shown. This helps the system admin or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) user determine the cause of slowdown, when a powerclamp driver is in action::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0 zombie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) Cpu(s): 71.2%us, 4.7%sy, 0.0%ni, 24.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) Mem: 3943228k total, 1689632k used, 2253596k free, 74960k buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) Swap: 4087804k total, 0k used, 4087804k free, 945336k cached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 3352 jacob 20 0 262m 644 428 S 286 0.0 0:17.16 spin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 3341 root -51 0 0 0 0 D 25 0.0 0:01.62 kidle_inject/0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 3344 root -51 0 0 0 0 D 25 0.0 0:01.60 kidle_inject/3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 3342 root -51 0 0 0 0 D 25 0.0 0:01.61 kidle_inject/1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 3343 root -51 0 0 0 0 D 25 0.0 0:01.60 kidle_inject/2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 2935 jacob 20 0 696m 125m 35m S 5 3.3 0:31.11 firefox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 1546 root 20 0 158m 20m 6640 S 3 0.5 0:26.97 Xorg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 2100 jacob 20 0 1223m 88m 30m S 3 2.3 0:23.68 compiz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) Tests have shown that by using the powerclamp driver as a cooling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) device, a PID based userspace thermal controller can manage to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) control CPU temperature effectively, when no other thermal influence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) is added. For example, a UltraBook user can compile the kernel under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) certain temperature (below most active trip points).