Power Management System
Overview
The FreeWorld OS power management system provides comprehensive power management capabilities including CPU frequency scaling, suspend/resume, and ACPI state management.
Components
CPU Frequency Scaling (P-States)
Dynamic CPU frequency adjustment:
- Up to 16 P-States: Multiple performance levels
- Dynamic Scaling: Automatic frequency adjustment
- Policy-Based: Performance, Balanced, Power Save modes
- ACPI Integration: P-state enumeration from ACPI _PSS
- Thermal Throttling: Automatic frequency reduction on overheating
CPU Idle States (C-States)
CPU idle management:
- C0: Active (no idle)
- C1: HLT (halt instruction)
- C2: MWAIT (if supported)
- C3: Deep sleep
- Policy-Based: Idle depth based on power policy
- Scheduler Integration: Automatic idle entry when system is idle
System Suspend/Resume
Complete suspend and resume support:
- S1: Standby (CPU stopped, RAM on)
- S2: Standby (CPU off, RAM on)
- S3: Suspend to RAM
- S4: Suspend to disk (hibernate)
- Context Save/Restore: Full CPU state preservation
- Device Restoration: Device state restoration after resume
ACPI Power States
ACPI sleep state management:
- S0: Working (full power)
- S1-S4: Suspend states
- S5: Soft off (shutdown)
- ACPI Integration: FADT/DSDT integration
- PM1a/PM1b Control: ACPI power control registers
Thermal Management
CPU temperature monitoring and throttling:
- Temperature Monitoring: Periodic temperature reading
- Thermal Throttling: Automatic frequency reduction
- Throttle Levels: Graduated throttling based on temperature
- ACPI Integration: Thermal zone support
Power Policies
| Policy | Description |
|---|---|
| Performance | Highest P-state (P0), shallow idle (C1) |
| Balanced | Middle P-state, medium idle (C2) |
| Power Save | Lowest P-state, deep idle (C3) |
Power API
| Function | Description |
|---|---|
power_management_init() |
Initialize power management |
power_set_policy() |
Set power policy |
power_enter_idle() |
Enter CPU idle state |
power_suspend() |
Suspend system |
power_resume() |
Resume system |
power_get_state() |
Get current ACPI state |
power_get_temperature() |
Get CPU temperature |
power_get_p_state() |
Get current P-state |
power_get_c_state() |
Get current C-state |
acpi_enter_sleep_state() |
Enter ACPI sleep state |
Features
- CPU P-states (performance scaling)
- CPU C-states (idle management)
- System suspend (S1-S4)
- System resume
- ACPI sleep states (S0-S5)
- Thermal throttling
- Power policies (Performance, Balanced, Power Save)
- Context save/restore
- CPU temperature monitoring
- Scheduler integration (idle handler)
- Timer integration (thermal handler)
Implementation
Total Lines of Code: ~1,014 lines
kernel/power/power_management.asm(~750 lines) - Power management corekernel/power/acpi_power.asm(~260 lines) - ACPI power integration
Integration
The power management system is integrated with:
- Kernel initialization sequence
- ACPI system (FADT, DSDT)
- Scheduler (idle handler)
- Timer (thermal handler)