Enerji İdarəetməsi
Enerji Problemi
graph TB
Power[Power Consumption] --> Dynamic[Dynamic Power<br/>Switching activity]
Power --> Static[Static Power<br/>Leakage]
Dynamic --> Formula1[P = α × C × V² × f]
Static --> Formula2[P = V × I_leakage]
Formula1 --> Alpha[α: Activity factor]
Formula1 --> Cap[C: Capacitance]
Formula1 --> Volt[V: Voltage]
Formula1 --> Freq[f: Frequency]
Dynamic Power:
P_dynamic = α × C × V² × f
α: Activity factor (0-1, işləyən transistorlar)
C: Capacitance (load)
V: Voltage
f: Frequency
V² → Voltage-ın kvadratik təsiri!
Static Power (Leakage):
P_static = V × I_leakage
Modern CPUs: Static power ~30-50% of total
Reason: Smaller transistors → more leakage
Total Power:
P_total = P_dynamic + P_static
Reducing voltage → Reduces both!
Dynamic Voltage and Frequency Scaling (DVFS)
DVFS Əsasları
graph LR
High[High Performance<br/>High V, High f<br/>High Power] --> Medium[Medium<br/>Medium V, Medium f<br/>Medium Power]
Medium --> Low[Low Performance<br/>Low V, Low f<br/>Low Power]
Low -.Workload increases.-> High
High -.Workload decreases.-> Low
Əsas prinsipler:
Frequency ↓ → Performance ↓ (linear)
Voltage ↓ → Power ↓ (quadratic!)
Example:
Freq: 3 GHz → 1.5 GHz (50% performance)
Voltage: 1.2V → 0.9V
Power: 1.2² → 0.9² = 1.44 → 0.81 (44% power savings!)
Voltage-Frequency Relationship
graph TB
V1[Voltage 1.2V] --> F1[Max Freq: 3 GHz]
V2[Voltage 1.0V] --> F2[Max Freq: 2 GHz]
V3[Voltage 0.8V] --> F3[Max Freq: 1 GHz]
Note1[Higher voltage → faster switching]
Note2[Lower voltage → slower, but saves power]
Critical path delay:
Delay ∝ V / (V - V_threshold)²
Lower voltage → longer delay → lower max frequency
P-states (Performance States)
P-states - CPU frequency və voltage levels (işləyərkən).
graph TB
P0[P0: Turbo Boost<br/>3.8 GHz, 1.35V<br/>Highest performance<br/>Highest power] --> P1[P1: Base<br/>3.0 GHz, 1.2V]
P1 --> P2[P2<br/>2.0 GHz, 1.0V]
P2 --> P3[P3<br/>1.5 GHz, 0.9V]
P3 --> Pn[Pn: Lowest<br/>800 MHz, 0.8V<br/>Lowest performance<br/>Lowest power]
P-state Məlumatları
# Linux - P-state info
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
# Output: 3800000 3000000 2000000 1500000 800000 (kHz)
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
# Current frequency
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# powersave, performance, ondemand, conservative, schedutil
P-state Governors (Linux)
graph TB
Governors[CPU Freq Governors] --> Performance[performance<br/>Always max frequency]
Governors --> Powersave[powersave<br/>Always min frequency]
Governors --> Ondemand[ondemand<br/>Dynamic based on load]
Governors --> Conservative[conservative<br/>Gradual freq changes]
Governors --> Schedutil[schedutil<br/>Scheduler-driven<br/>Modern default]
ondemand:
// Pseudo-code
if (cpu_load > 80%) {
set_frequency(max_frequency);
} else {
scale_frequency_proportionally(cpu_load);
}
schedutil:
// Integrated with scheduler
frequency = f(utilization, deadline, priorities);
// More responsive than ondemand
Intel P-state Driver
# Check driver
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver
# intel_pstate or acpi-cpufreq
# Intel P-state modes
cat /sys/devices/system/cpu/intel_pstate/status
# active, passive, off
# Turbo enable/disable
cat /sys/devices/system/cpu/intel_pstate/no_turbo
# 0 = turbo enabled, 1 = disabled
# Min/Max performance percentage
echo 50 > /sys/devices/system/cpu/intel_pstate/min_perf_pct
echo 100 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
AMD P-state Driver
# AMD P-state (newer CPUs)
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver
# amd-pstate or acpi-cpufreq
# Similar interface to Intel
C-states (Idle States)
C-states - CPU idle (işləməyərkən) enerji qənaəti.
graph TB
C0[C0: Running<br/>Active execution<br/>Full power] --> C1[C1: Halt<br/>Clock gated<br/>~1µs wake-up]
C1 --> C2[C2: Stop Clock<br/>PLL running<br/>~10µs wake-up]
C2 --> C3[C3: Sleep<br/>L1/L2 flushed<br/>~100µs wake-up]
C3 --> C6[C6: Deep Sleep<br/>Core powered off<br/>~1ms wake-up]
C6 -.Wake up.-> C0
style C0 fill:#f66
style C1 fill:#fc6
style C2 fill:#ff6
style C3 fill:#6f6
style C6 fill:#6cf
C-state Levels
| State | Name | Power | Wake latency | What's off/on |
|---|---|---|---|---|
| C0 | Operating | 100% | 0 | Everything on |
| C1 | Halt | ~90% | ~1 µs | Clock gated, instant wake |
| C2 | Stop-Clock | ~70% | ~10 µs | PLL on, caches on |
| C3 | Sleep | ~40% | ~100 µs | L1/L2 flushed to L3 |
| C6 | Deep Sleep | ~10% | ~1 ms | Core power off, L3 on |
| C7 | Deeper Sleep | ~5% | ~2 ms | LLC (L3) flushed |
| C8/C10 | Package C-states | ~1-2% | ~5 ms | Entire package sleep |
C-state Məlumatları
# List available C-states
ls /sys/devices/system/cpu/cpu0/cpuidle/
# state0 state1 state2 state3 ...
# C-state info
cat /sys/devices/system/cpu/cpu0/cpuidle/state3/name
# C6
cat /sys/devices/system/cpu/cpu0/cpuidle/state3/latency
# 200 (microseconds)
cat /sys/devices/system/cpu/cpu0/cpuidle/state3/power
# 0 (relative power consumption)
# Usage statistics
cat /sys/devices/system/cpu/cpu0/cpuidle/state3/time
# Total time spent in this state (microseconds)
cat /sys/devices/system/cpu/cpu0/cpuidle/state3/usage
# Number of times entered
Disable C-states (for latency-sensitive apps)
# Disable C-states deeper than C1
for state in /sys/devices/system/cpu/cpu*/cpuidle/state*/disable; do
if [[ $(basename $(dirname $state)) != "state0" ]] && \
[[ $(basename $(dirname $state)) != "state1" ]]; then
echo 1 > $state
fi
done
# Or via kernel parameter
# Add to GRUB: intel_idle.max_cstate=1
C-state Governor
# cpuidle governor
cat /sys/devices/system/cpu/cpuidle/current_governor
# menu, ladder, teo
# menu: Default, heuristic-based
# ladder: Simple, step-by-step
# teo: Timer events oriented (modern)
Turbo Boost / Turbo Core
Temporarily exceed base frequency.
graph TB
Base[Base Frequency<br/>3.0 GHz<br/>All cores, sustained] --> Turbo[Turbo Boost<br/>Up to 4.5 GHz<br/>Few cores, temporary]
Turbo --> Conditions{Conditions}
Conditions --> Power[Power budget<br/>TDP not exceeded]
Conditions --> Thermal[Temperature<br/>Below threshold]
Conditions --> Current[Current<br/>Below limit]
Conditions --> Cores[Core count<br/>Fewer active cores<br/>→ Higher boost]
Intel Turbo Boost
Intel Core i7-12700K:
- Base: 3.6 GHz (P-cores)
- Turbo: Up to 5.0 GHz (single core)
- All-core turbo: ~4.7 GHz
Depends on:
- Power (TDP: 125W base, 190W turbo)
- Thermal (< 100°C)
- Number of active cores
AMD Precision Boost
AMD Ryzen 9 7950X:
- Base: 4.5 GHz
- Boost: Up to 5.7 GHz
Precision Boost 2: More fine-grained control
Precision Boost Overdrive (PBO): User-configurable limits
Thermal Management
graph TB
Temp[Temperature] --> T1[< 70°C<br/>Normal operation<br/>Full performance]
T1 --> T2[70-90°C<br/>Thermal monitoring<br/>Turbo limited]
T2 --> T3[90-100°C<br/>Throttling<br/>Reduce frequency]
T3 --> T4[> 100°C<br/>Critical<br/>Emergency shutdown]
style T1 fill:#6f6
style T2 fill:#ff6
style T3 fill:#f96
style T4 fill:#f66
Thermal Throttling
T_junction (max): 100°C (typical for modern CPUs)
If temp > threshold:
1. Reduce frequency (P-state down)
2. Reduce voltage
3. Insert idle cycles (clock modulation)
4. Last resort: Shutdown (prevent damage)
Thermal Sensors
# Linux sensors
sensors
# Output:
# coretemp-isa-0000
# Core 0: +45.0°C (high = +80.0°C, crit = +100.0°C)
# Core 1: +47.0°C
# Per-core temperature
cat /sys/class/hwmon/hwmon*/temp*_input
# Temperature in millidegrees (45000 = 45°C)
CPU Cooling Solutions
graph LR
Air[Air Cooling<br/>Heatsink + Fan<br/>~50-80W TDP] --> Liquid[Liquid Cooling<br/>AIO / Custom loop<br/>~200-300W TDP]
Liquid --> Exotic[Exotic<br/>Phase change, LN2<br/>Extreme OC]
Air --> Cheap[Cheaper]
Liquid --> Better[Better cooling]
Exotic --> Expensive[Expensive, impractical]
Race-to-Idle
Philosophy: Finish work quickly, then sleep deeply.
sequenceDiagram
participant Workload
participant CPU
participant Power
Note over Workload: Work arrives
Workload->>CPU: Task
CPU->>CPU: Boost to max frequency
Note over CPU: P0 state<br/>High power, fast
CPU->>Workload: Task complete (fast!)
CPU->>CPU: Deep sleep
Note over CPU: C6 state<br/>Very low power
Note over Power: Average power: LOW<br/>(short high + long low)
Race-to-Idle vs Constant Low
Scenario: Process 1 second of work
Option 1: Constant low frequency (1 GHz)
- Duration: 1 second @ 10W = 10 Joules
- Total: 10 Joules
Option 2: Race-to-idle (3 GHz → C6)
- Duration: 0.33 sec @ 30W + 0.67 sec @ 1W = 10 + 0.67 = 10.67 Joules
- Total: 10.67 Joules
BUT: Option 2 allows deeper sleep states longer
+ Lower latency (finishes faster)
+ Better for bursty workloads
Benefits
- Lower latency - Work completes faster
- Better sleep - More time in deep C-states
- Power efficiency - Deep sleep saves more power
- Responsiveness - UI feels snappier
When NOT to use Race-to-Idle
Sustained workloads (rendering, compilation):
- No idle time to sleep
- Constant high power
→ Better to use moderate frequency
Package C-states (PC-states)
Entire CPU package (all cores) idle.
graph TB
PC0[PC0: Active<br/>At least one core active] --> PC2[PC2: Package idle<br/>All cores in C6<br/>LLC on]
PC2 --> PC6[PC6: Deep<br/>LLC flushed<br/>Package power gated]
PC6 --> PC8[PC8: Deeper<br/>Lower voltage]
PC8 --> PC10[PC10: Deepest<br/>Minimal power<br/>Longest wake-up]
PC10 -.Wake.-> PC0
Requirements for PC6:
- All cores in C6
- GPU idle (integrated graphics)
- I/O idle
# Check package C-state
cat /sys/kernel/debug/pmc_core/package_cstate_show
# PC2: 10%
# PC6: 80%
# PC10: 5%
RAPL (Running Average Power Limit)
Intel enerji monitoring və limiting.
graph TB
RAPL[RAPL Domains] --> PKG[Package<br/>Entire CPU]
RAPL --> PP0[Power Plane 0<br/>CPU cores]
RAPL --> PP1[Power Plane 1<br/>GPU (integrated)]
RAPL --> DRAM[DRAM<br/>Memory]
PKG --> Limit[Power Limit<br/>TDP constraint]
RAPL Monitoring
# Install powercap utils
# Read package power
cat /sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj
# Energy in microjoules
# Power limit
cat /sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw
# Power limit in microwatts
# Set power limit (requires root)
echo 50000000 > /sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw
# 50W limit
RAPL with perf
# Measure power consumption
perf stat -e power/energy-pkg/,power/energy-cores/,power/energy-ram/ ./program
# Output:
# 24.50 Joules power/energy-pkg/
# 20.10 Joules power/energy-cores/
# 4.20 Joules power/energy-ram/
Mobile Power Management
ARM big.LITTLE / DynamIQ
graph TB
Scheduler[OS Scheduler] --> Light[Light tasks<br/>LITTLE cores<br/>Low power]
Scheduler --> Heavy[Heavy tasks<br/>big cores<br/>High performance]
Light --> Example1[Background sync<br/>Music playback<br/>UI idle]
Heavy --> Example2[Gaming<br/>Video encoding<br/>Browsing]
Energy efficiency:
big core (A78): 1.0x performance, 1.0x power
LITTLE core (A55): 0.3x performance, 0.1x power
For light tasks: 3x more energy efficient!
Intel Hybrid (Alder Lake+)
graph TB
ThreadDirector[Thread Director<br/>Hardware hints] --> P[P-cores<br/>Performance<br/>Golden Cove]
ThreadDirector --> E[E-cores<br/>Efficiency<br/>Gracemont]
P --> Foreground[Foreground apps<br/>Games<br/>Heavy workloads]
E --> Background[Background tasks<br/>OS services<br/>Light workloads]
Power Profiling
powertop (Linux)
sudo powertop
# Tabs:
# - Overview: Power consumption estimate
# - Idle stats: C-state residency
# - Frequency stats: P-state usage
# - Device stats: Per-device power
# - Tunables: Optimization suggestions
# Generate HTML report
sudo powertop --html=report.html
# Auto-tune (enable all power savings)
sudo powertop --auto-tune
Intel Power Gadget
# macOS/Windows tool
# Shows:
# - Package power (W)
# - Frequency (GHz)
# - Temperature (°C)
# - Utilization (%)
Battery Life Optimization
# Check wakeups (frequent wakeups prevent deep sleep)
sudo powertop
# Look for processes with high wakeup count
# Reduce wakeups
# - Timer coalescing
# - Batch network I/O
# - Reduce polling
# Laptop mode (Linux)
echo 5 > /proc/sys/vm/laptop_mode
# Reduce disk writes, batch I/O
Performance vs Power Trade-offs
graph TB
Axis[Performance vs Power] --> MaxPerf[Max Performance<br/>Servers, Desktops<br/>Always P0, C-states off]
Axis --> Balanced[Balanced<br/>Laptops<br/>DVFS enabled, moderate C-states]
Axis --> MaxPower[Max Power Savings<br/>Mobile, IoT<br/>Aggressive sleep, low freq]
MaxPerf --> UseCase1[Minimize latency<br/>Predictable performance]
Balanced --> UseCase2[Good performance<br/>Reasonable battery]
MaxPower --> UseCase3[Long battery life<br/>Tolerate latency]
Configuration Examples
Max Performance (Latency-sensitive):
# Disable C-states > C1
intel_idle.max_cstate=1
# Performance governor
cpupower frequency-set -g performance
# Disable turbo (for consistency)
echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo
Balanced (Default):
# Default C-states
# schedutil governor (default)
# Turbo enabled
echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo
Max Power Savings (Battery):
# Enable all C-states
# Powersave governor
cpupower frequency-set -g powersave
# Reduce max frequency
echo 50 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
# Enable powertop recommendations
powertop --auto-tune
Future Trends
1. Finer-grained Power Control
Modern: Per-core DVFS
Future: Per-cluster, per-instruction domain
2. AI-based Power Management
Machine learning predicts workload
→ Proactive frequency/C-state selection
→ Better than reactive governors
3. Heterogeneous Integration
CPU + GPU + NPU + DSP on same package
→ Route tasks to most efficient processor
4. Better Race-to-Idle
Faster wake-up from deep sleep
→ More aggressive deep sleep
→ Better average power
Best Practices
Development
-
Profile power consumption
perf stat -e power/energy-pkg/ ./app -
Reduce wakeups
// BAD: Frequent polling
while (true) {
check_status();
usleep(10000); // Wake every 10ms
}
// GOOD: Event-driven
poll(fds, nfds, -1); // Sleep until event -
Batch operations
// Process multiple items per wake-up
// Allows longer sleep periods -
Use hardware acceleration
// Hardware decoders use less power than software
System Administration
-
Choose right governor
- Desktop:
schedutilorondemand - Server:
performance(if latency critical) - Laptop:
powersaveorschedutil
- Desktop:
-
Monitor thermals
watch -n 1 sensors -
Check power limits
cat /sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw -
Verify C-state residency
# Should spend most idle time in deep C-states
sudo powertop -
Tune for workload
- Batch jobs: Max performance
- Interactive: Balanced
- Idle servers: Power savings
Əlaqəli Mövzular
- CPU Architecture: Frequency, voltage domains
- Modern Architectures: big.LITTLE, hybrid P/E cores
- Performance: Power-performance trade-offs
- Thermal Design: Cooling solutions
- Mobile Computing: Battery life optimization