Initial commit: Battery Life Optimization toolkit with TLP and PowerTOP
- Complete installation and uninstallation scripts - Optimized TLP configuration for maximum battery life - PowerTOP analysis and auto-tune functionality - Real-time battery monitoring with detailed stats - ThinkPad-specific optimizations and battery thresholds - Comprehensive documentation and usage guides - Tested on ThinkPad T14 Gen 1 with 13% power reduction
This commit is contained in:
331
docs/powertop-guide.md
Normal file
331
docs/powertop-guide.md
Normal file
@@ -0,0 +1,331 @@
|
||||
# PowerTOP Usage Guide
|
||||
|
||||
## Overview
|
||||
|
||||
PowerTOP is a Linux tool to diagnose issues with power consumption and power management. It provides detailed information about power usage by various system components and suggests optimizations.
|
||||
|
||||
## Installation Verification
|
||||
|
||||
After running the installation script, verify PowerTOP is installed:
|
||||
|
||||
```bash
|
||||
# Check PowerTOP version
|
||||
powertop --version
|
||||
|
||||
# Quick test (requires sudo)
|
||||
sudo powertop --time=5
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### Interactive Mode
|
||||
|
||||
```bash
|
||||
# Launch PowerTOP in interactive mode
|
||||
sudo powertop
|
||||
```
|
||||
|
||||
**Navigation:**
|
||||
- `Tab`: Switch between tabs
|
||||
- `Enter`: Toggle tunables
|
||||
- `q`: Quit
|
||||
- Arrow keys: Navigate lists
|
||||
|
||||
### Tabs Overview
|
||||
|
||||
1. **Overview**: General system power consumption
|
||||
2. **Idle stats**: CPU idle state statistics
|
||||
3. **Frequency stats**: CPU frequency usage
|
||||
4. **Device stats**: Individual device power usage
|
||||
5. **Tunables**: Available power optimizations
|
||||
|
||||
## Command Line Usage
|
||||
|
||||
### Generate Reports
|
||||
|
||||
```bash
|
||||
# Generate HTML report (60 seconds)
|
||||
sudo powertop --html=report.html --time=60
|
||||
|
||||
# Generate CSV report
|
||||
sudo powertop --csv=report.csv --time=60
|
||||
|
||||
# Custom duration
|
||||
sudo powertop --html=report.html --time=120
|
||||
```
|
||||
|
||||
### Auto-tune Mode
|
||||
|
||||
```bash
|
||||
# Apply all available optimizations
|
||||
sudo powertop --auto-tune
|
||||
|
||||
# View what would be changed (dry-run)
|
||||
sudo powertop --auto-tune --debug
|
||||
```
|
||||
|
||||
**Note:** Auto-tune changes are temporary and reset on reboot.
|
||||
|
||||
## Using the PowerTOP Analysis Script
|
||||
|
||||
Our custom script (`scripts/powertop-analyze.sh`) provides enhanced functionality:
|
||||
|
||||
### Basic Report Generation
|
||||
|
||||
```bash
|
||||
# Generate 60-second HTML report
|
||||
./scripts/powertop-analyze.sh
|
||||
|
||||
# Custom duration and format
|
||||
./scripts/powertop-analyze.sh --duration 120 --format csv
|
||||
|
||||
# Different output directory
|
||||
./scripts/powertop-analyze.sh --output /tmp/reports
|
||||
```
|
||||
|
||||
### Apply Optimizations
|
||||
|
||||
```bash
|
||||
# Apply PowerTOP auto-tune
|
||||
./scripts/powertop-analyze.sh --auto-tune
|
||||
|
||||
# Quick system summary
|
||||
./scripts/powertop-analyze.sh --quick
|
||||
```
|
||||
|
||||
### View Reports
|
||||
|
||||
```bash
|
||||
# Open latest report in browser
|
||||
./scripts/powertop-analyze.sh --show-report
|
||||
|
||||
# List all generated reports
|
||||
ls -la ~/.battery-optimizer/reports/
|
||||
```
|
||||
|
||||
## Understanding Reports
|
||||
|
||||
### HTML Report Sections
|
||||
|
||||
1. **System Information**
|
||||
- Hardware details
|
||||
- Kernel version
|
||||
- System uptime
|
||||
|
||||
2. **Power Consumption Overview**
|
||||
- Total system power draw
|
||||
- Battery discharge rate
|
||||
- Power source information
|
||||
|
||||
3. **Top Power Consumers**
|
||||
- Applications using most power
|
||||
- Hardware devices consuming power
|
||||
- System services impact
|
||||
|
||||
4. **Processor Information**
|
||||
- CPU frequency usage
|
||||
- Idle state statistics
|
||||
- Core utilization
|
||||
|
||||
5. **Device Power Management**
|
||||
- ASPM status
|
||||
- Runtime PM status
|
||||
- USB autosuspend status
|
||||
|
||||
6. **Tunables**
|
||||
- Available optimizations
|
||||
- Current status (Good/Bad)
|
||||
- Recommended changes
|
||||
|
||||
### Key Metrics to Monitor
|
||||
|
||||
1. **Power Consumption (Watts)**
|
||||
- Lower is better
|
||||
- Typical laptop: 8-15W idle, 25-45W under load
|
||||
|
||||
2. **Wakeups per Second**
|
||||
- Lower is better for battery life
|
||||
- Target: <100 wakeups/second
|
||||
|
||||
3. **CPU Usage**
|
||||
- Identify power-hungry applications
|
||||
- Background processes impact
|
||||
|
||||
## Optimization Categories
|
||||
|
||||
### CPU Optimizations
|
||||
|
||||
```bash
|
||||
# CPU governor (applied by TLP)
|
||||
echo 'powersave' | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
|
||||
# CPU idle states
|
||||
# Managed automatically by kernel
|
||||
```
|
||||
|
||||
### Device Power Management
|
||||
|
||||
```bash
|
||||
# Enable ASPM (PCIe power saving)
|
||||
echo 'powersave' | sudo tee /sys/module/pcie_aspm/parameters/policy
|
||||
|
||||
# Runtime PM for devices
|
||||
echo 'auto' | sudo tee /sys/bus/pci/devices/*/power/control
|
||||
```
|
||||
|
||||
### USB Power Management
|
||||
|
||||
```bash
|
||||
# Enable USB autosuspend
|
||||
echo '1' | sudo tee /sys/module/usbcore/parameters/autosuspend
|
||||
|
||||
# Per-device control
|
||||
echo 'auto' | sudo tee /sys/bus/usb/devices/*/power/control
|
||||
```
|
||||
|
||||
### Audio Power Saving
|
||||
|
||||
```bash
|
||||
# Enable audio power saving
|
||||
echo '1' | sudo tee /sys/module/snd_hda_intel/parameters/power_save
|
||||
```
|
||||
|
||||
## Making Optimizations Permanent
|
||||
|
||||
### Method 1: Systemd Service (Recommended)
|
||||
|
||||
Our installation script creates a PowerTOP service:
|
||||
|
||||
```bash
|
||||
# Check service status
|
||||
systemctl status powertop.service
|
||||
|
||||
# Enable auto-tune on boot
|
||||
sudo systemctl enable powertop.service
|
||||
|
||||
# Manually run auto-tune
|
||||
sudo systemctl start powertop.service
|
||||
```
|
||||
|
||||
### Method 2: Custom Scripts
|
||||
|
||||
Create startup scripts in `/etc/rc.local` or systemd services:
|
||||
|
||||
```bash
|
||||
# Example optimization script
|
||||
#!/bin/bash
|
||||
echo 'auto' > /sys/bus/pci/devices/*/power/control
|
||||
echo 'min_power' > /sys/class/scsi_host/*/link_power_management_policy
|
||||
```
|
||||
|
||||
### Method 3: TLP Integration
|
||||
|
||||
Most PowerTOP optimizations are already included in our TLP configuration.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **PowerTOP requires root privileges**
|
||||
- This is normal for hardware access
|
||||
- Always use `sudo powertop`
|
||||
|
||||
2. **No power consumption data**
|
||||
- Check if running on battery
|
||||
- Ensure ACPI support in kernel
|
||||
- Some virtual machines don't report power data
|
||||
|
||||
3. **Optimizations not persisting**
|
||||
- Use systemd service for permanent changes
|
||||
- Check for conflicting power managers
|
||||
|
||||
### Debug Commands
|
||||
|
||||
```bash
|
||||
# Check kernel power management support
|
||||
ls /sys/class/power_supply/
|
||||
|
||||
# Verify ACPI tables
|
||||
sudo acpidump | head -20
|
||||
|
||||
# Check for power management conflicts
|
||||
systemctl list-units | grep power
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Regular Monitoring
|
||||
|
||||
1. **Weekly Reports**: Generate PowerTOP reports to track trends
|
||||
2. **Before/After Testing**: Measure impact of configuration changes
|
||||
3. **Application Profiling**: Identify power-hungry applications
|
||||
|
||||
### Analysis Workflow
|
||||
|
||||
1. **Baseline Measurement**: Record power consumption before changes
|
||||
2. **Apply Optimizations**: Use systematic approach
|
||||
3. **Measure Impact**: Generate new reports
|
||||
4. **Document Changes**: Keep track of what works
|
||||
|
||||
### Report Interpretation
|
||||
|
||||
1. **Focus on Top Consumers**: Address highest impact items first
|
||||
2. **Check Tunables**: Apply "Bad" recommendations carefully
|
||||
3. **Monitor Trends**: Look for patterns over time
|
||||
4. **Validate Changes**: Ensure functionality isn't compromised
|
||||
|
||||
## Integration with Other Tools
|
||||
|
||||
### With TLP
|
||||
|
||||
PowerTOP and TLP complement each other:
|
||||
- TLP: Provides systematic, persistent power management
|
||||
- PowerTOP: Offers detailed analysis and additional optimizations
|
||||
|
||||
### With System Monitoring
|
||||
|
||||
```bash
|
||||
# Combine with system monitoring
|
||||
./scripts/powertop-analyze.sh &
|
||||
./scripts/battery-monitor.sh --watch
|
||||
```
|
||||
|
||||
### With Performance Tools
|
||||
|
||||
```bash
|
||||
# Monitor performance impact
|
||||
htop &
|
||||
sudo powertop --auto-tune
|
||||
# Check if system remains responsive
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Automated Analysis
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Daily power analysis script
|
||||
DATE=$(date +%Y%m%d)
|
||||
sudo powertop --html=/var/log/powertop_${DATE}.html --time=3600
|
||||
|
||||
# Email report or upload to monitoring system
|
||||
```
|
||||
|
||||
### Custom Reporting
|
||||
|
||||
```bash
|
||||
# Extract specific data from CSV reports
|
||||
awk -F',' 'NR>1 {print $1,$3}' report.csv | sort -k2 -nr | head -10
|
||||
```
|
||||
|
||||
### Integration with Monitoring Systems
|
||||
|
||||
PowerTOP data can be integrated with:
|
||||
- Grafana dashboards
|
||||
- Nagios monitoring
|
||||
- Custom logging systems
|
||||
|
||||
---
|
||||
|
||||
This guide should be used alongside the PowerTOP analysis script provided in this repository for optimal power management.
|
||||
280
docs/tlp-configuration.md
Normal file
280
docs/tlp-configuration.md
Normal file
@@ -0,0 +1,280 @@
|
||||
# TLP Configuration Guide
|
||||
|
||||
## Overview
|
||||
|
||||
TLP (Linux Advanced Power Management) is a feature-rich command line utility for optimizing battery life on Linux laptops. This guide explains the key configuration options and their impact on battery performance.
|
||||
|
||||
## Configuration File Location
|
||||
|
||||
The main configuration file is located at:
|
||||
- `/etc/tlp.conf` (system-wide configuration)
|
||||
- Backup copies are created as `/etc/tlp.conf.backup.YYYYMMDD_HHMMSS`
|
||||
|
||||
## Key Configuration Sections
|
||||
|
||||
### 1. Operation Modes
|
||||
|
||||
```bash
|
||||
# Default operation mode
|
||||
TLP_DEFAULT_MODE=BAT
|
||||
|
||||
# Use persistent mode for consistent behavior
|
||||
TLP_PERSISTENT_DEFAULT=0
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
- `BAT`: Optimizes for battery life
|
||||
- `AC`: Optimizes for AC power (performance)
|
||||
- `DEF`: Uses kernel defaults
|
||||
|
||||
### 2. CPU Power Management
|
||||
|
||||
```bash
|
||||
# CPU frequency governor
|
||||
CPU_SCALING_GOVERNOR_ON_AC=powersave
|
||||
CPU_SCALING_GOVERNOR_ON_BAT=powersave
|
||||
|
||||
# CPU frequency limits
|
||||
CPU_SCALING_MIN_FREQ_ON_BAT=800000
|
||||
CPU_SCALING_MAX_FREQ_ON_BAT=1600000
|
||||
|
||||
# Intel P-state settings
|
||||
CPU_HWP_ON_BAT=power
|
||||
CPU_MAX_PERF_ON_BAT=50
|
||||
CPU_BOOST_ON_BAT=0
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Reduces CPU power consumption by 20-40%
|
||||
- May slightly reduce performance under heavy loads
|
||||
- Automatic scaling based on demand
|
||||
|
||||
### 3. Disk Power Management
|
||||
|
||||
```bash
|
||||
# Advanced Power Management levels
|
||||
DISK_APM_LEVEL_ON_BAT="128 128"
|
||||
|
||||
# IO scheduler optimization
|
||||
DISK_IOSCHED="mq-deadline mq-deadline"
|
||||
|
||||
# AHCI Link Power Management
|
||||
AHCI_ALPM_ON_BAT=min_power
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Reduces disk power consumption
|
||||
- May increase disk access latency slightly
|
||||
- Significant savings for HDDs, moderate for SSDs
|
||||
|
||||
### 4. Graphics Power Management
|
||||
|
||||
```bash
|
||||
# Radeon settings (for AMD GPUs)
|
||||
RADEON_POWER_PROFILE_ON_BAT=low
|
||||
RADEON_DPM_STATE_ON_BAT=battery
|
||||
|
||||
# Intel graphics automatically managed
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Reduces GPU power consumption by 15-30%
|
||||
- Lower graphics performance in games/3D applications
|
||||
- Minimal impact on desktop usage
|
||||
|
||||
### 5. Wireless Device Management
|
||||
|
||||
```bash
|
||||
# WiFi power saving
|
||||
WIFI_PWR_ON_BAT=on
|
||||
|
||||
# Bluetooth management
|
||||
DEVICES_TO_DISABLE_ON_BAT="bluetooth"
|
||||
|
||||
# Wake on LAN
|
||||
WOL_DISABLE=Y
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Reduces wireless power consumption
|
||||
- May affect network performance slightly
|
||||
- Automatic reconnection when needed
|
||||
|
||||
### 6. USB Power Management
|
||||
|
||||
```bash
|
||||
# Enable USB autosuspend
|
||||
USB_AUTOSUSPEND=1
|
||||
|
||||
# Exclude critical devices
|
||||
USB_BLACKLIST_PRINTER=1
|
||||
USB_BLACKLIST_PHONE=0
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Suspends unused USB devices
|
||||
- Saves 0.5-2W per device
|
||||
- Blacklist prevents issues with specific devices
|
||||
|
||||
### 7. Battery Charge Thresholds (ThinkPad)
|
||||
|
||||
```bash
|
||||
# Start charging at 75%
|
||||
START_CHARGE_THRESH_BAT0=75
|
||||
|
||||
# Stop charging at 80%
|
||||
STOP_CHARGE_THRESH_BAT0=80
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Extends battery lifespan significantly
|
||||
- Reduces available capacity slightly
|
||||
- Optimal for plugged-in usage
|
||||
|
||||
## Advanced Optimizations
|
||||
|
||||
### CPU Undervolting
|
||||
|
||||
For advanced users, CPU undervolting can provide additional power savings:
|
||||
|
||||
```bash
|
||||
# EXPERIMENTAL - Use with caution
|
||||
# PHC_CONTROLS="F:V F:V F:V F:V"
|
||||
```
|
||||
|
||||
**Warning:** Only use if you understand the risks. Incorrect values can cause system instability.
|
||||
|
||||
### Custom Scripts
|
||||
|
||||
You can add custom power management commands to:
|
||||
- `/etc/tlp.d/` - Additional configuration files
|
||||
- Systemd services for startup optimizations
|
||||
|
||||
## Monitoring Configuration Impact
|
||||
|
||||
### Check Current Settings
|
||||
|
||||
```bash
|
||||
# Show all TLP settings
|
||||
sudo tlp-stat
|
||||
|
||||
# Show specific components
|
||||
sudo tlp-stat -p # Processor
|
||||
sudo tlp-stat -d # Disks
|
||||
sudo tlp-stat -g # Graphics
|
||||
sudo tlp-stat -u # USB
|
||||
```
|
||||
|
||||
### Measure Power Consumption
|
||||
|
||||
```bash
|
||||
# Before configuration changes
|
||||
sudo powertop --time=60
|
||||
|
||||
# Apply changes
|
||||
sudo tlp start
|
||||
|
||||
# After configuration changes
|
||||
sudo powertop --time=60
|
||||
```
|
||||
|
||||
## Distribution-Specific Notes
|
||||
|
||||
### Ubuntu/Debian
|
||||
- Install with: `sudo apt install tlp tlp-rdw`
|
||||
- May conflict with `power-profiles-daemon`
|
||||
|
||||
### Fedora/RHEL
|
||||
- Install with: `sudo dnf install tlp tlp-rdw`
|
||||
- Disable conflicting services
|
||||
|
||||
### Arch Linux
|
||||
- Install with: `sudo pacman -S tlp`
|
||||
- Enable service: `sudo systemctl enable tlp.service`
|
||||
|
||||
## Laptop-Specific Optimizations
|
||||
|
||||
### ThinkPad
|
||||
- Install additional tools: `tp-smapi-dkms acpi-call-dkms`
|
||||
- Battery threshold support available
|
||||
- Enhanced fan control
|
||||
|
||||
### Dell
|
||||
- Use `i8kutils` for fan control
|
||||
- BIOS settings may override some options
|
||||
|
||||
### HP
|
||||
- Limited hardware support
|
||||
- Focus on software optimizations
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **TLP not applying settings**
|
||||
```bash
|
||||
sudo systemctl enable tlp.service
|
||||
sudo systemctl start tlp.service
|
||||
```
|
||||
|
||||
2. **Settings reset after reboot**
|
||||
- Check if other power managers are active
|
||||
- Ensure TLP service is enabled
|
||||
|
||||
3. **USB devices not working**
|
||||
- Add device IDs to blacklist
|
||||
- Check `lsusb` output for device identification
|
||||
|
||||
### Verification Commands
|
||||
|
||||
```bash
|
||||
# Check TLP service status
|
||||
systemctl status tlp.service
|
||||
|
||||
# Verify configuration syntax
|
||||
sudo tlp-stat -c
|
||||
|
||||
# Test specific settings
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
|
||||
```
|
||||
|
||||
## Performance vs Battery Life
|
||||
|
||||
### Maximum Battery Life Profile
|
||||
- All power saving features enabled
|
||||
- Significant performance reduction acceptable
|
||||
- Target: 30-50% longer battery life
|
||||
|
||||
### Balanced Profile
|
||||
- Moderate power saving
|
||||
- Minimal performance impact
|
||||
- Target: 15-25% longer battery life
|
||||
|
||||
### Performance Profile
|
||||
- Limited power saving
|
||||
- Maximum performance preserved
|
||||
- Target: 5-10% longer battery life
|
||||
|
||||
## Regular Maintenance
|
||||
|
||||
### Monthly Tasks
|
||||
- Review power consumption reports
|
||||
- Check battery health
|
||||
- Update TLP configuration if needed
|
||||
|
||||
### After System Updates
|
||||
- Verify TLP service is still running
|
||||
- Check for configuration file changes
|
||||
- Test critical functionality
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Start Conservative**: Begin with moderate settings and adjust gradually
|
||||
2. **Monitor Impact**: Use PowerTOP to measure actual improvements
|
||||
3. **Document Changes**: Keep track of modifications for troubleshooting
|
||||
4. **Test Thoroughly**: Verify all hardware functions correctly
|
||||
5. **Regular Updates**: Keep TLP and related tools current
|
||||
|
||||
---
|
||||
|
||||
This configuration guide should be used alongside the main installation and monitoring tools provided in this repository.
|
||||
Reference in New Issue
Block a user