- Add battery-drain-analysis.sh: Comprehensive tool to identify battery draining processes - Shows top CPU and memory consumers - Identifies network-intensive applications - Analyzes browser tab usage (counts renderers) - Provides actionable recommendations - Checks WiFi power management status - Update README.md with new features: - Document CPU power management capabilities (400MHz-4.2GHz dynamic scaling) - Add browser optimization tips (tab suspenders, task manager usage) - Add application management best practices - Document new scripts: cpu-power-control.sh, monitor-cpu-freq.sh, battery-drain-analysis.sh - Add BIOS configuration guide reference - Improve battery life tips: - Close heavy browser tabs (can use 77%+ CPU per tab) - Install tab suspender extensions (saves 50-70% browser CPU) - Manage chat applications (Element/Slack/Discord) - Pause file sync services when on battery - Screen brightness recommendations Identified issue: Single browser tab was using 77% CPU, reducing overall browser usage from 268% to 96% CPU
367 lines
10 KiB
Markdown
367 lines
10 KiB
Markdown
# Battery Life Optimizer
|
|
|
|
A comprehensive tool suite for optimizing Linux laptop battery life using TLP and PowerTOP.
|
|
|
|
## 🔋 Overview
|
|
|
|
This repository provides scripts, configurations, and tools to maximize your Linux laptop's battery life through advanced power management. The toolkit includes automated installation scripts, optimized configuration files, CPU power management tools, and real-time monitoring utilities.
|
|
|
|
**Key Achievement**: Dynamic CPU frequency scaling from 400 MHz (idle) to 4.2 GHz (turbo) on AC power, and 400 MHz to 2.2 GHz on battery for optimal battery life while maintaining responsiveness.
|
|
|
|
## ✨ Features
|
|
|
|
- **Dynamic CPU Frequency Scaling**: 400 MHz to 4.2 GHz on AC, 400 MHz to 2.2 GHz on battery
|
|
- **CPU Power Management**: Intel RAPL power limits with preset profiles
|
|
- **Real-time Monitoring**: CPU frequency, power consumption, and battery drain analysis
|
|
- **Automated Installation**: One-command setup for TLP and PowerTOP
|
|
- **Optimized Configurations**: Pre-tuned settings for maximum battery life
|
|
- **Monitoring Tools**: Real-time battery and power consumption monitoring
|
|
- **Power Analysis**: Detailed PowerTOP reports and recommendations
|
|
- **Profile Management**: Easy switching between power profiles
|
|
- **Safety First**: Backup and rollback capabilities
|
|
- **BIOS Configuration Guide**: Documentation for optimal firmware settings
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### 1. Install TLP and PowerTOP
|
|
|
|
```bash
|
|
# Clone or download this repository
|
|
cd battery_life
|
|
|
|
# Run the installation script
|
|
./scripts/install.sh
|
|
```
|
|
|
|
### 2. Monitor Your Battery
|
|
|
|
```bash
|
|
# Show current battery status
|
|
./scripts/battery-monitor.sh
|
|
|
|
# Watch battery status in real-time
|
|
./scripts/battery-monitor.sh --watch
|
|
```
|
|
|
|
### 3. Analyze Power Consumption
|
|
|
|
```bash
|
|
# Generate a PowerTOP report
|
|
./scripts/powertop-analyze.sh
|
|
|
|
# Apply automatic optimizations
|
|
./scripts/powertop-analyze.sh --auto-tune
|
|
```
|
|
|
|
### 4. Manage TLP Settings
|
|
|
|
```bash
|
|
# Show TLP status
|
|
./scripts/tlp-manager.sh
|
|
|
|
# Get optimization recommendations
|
|
./scripts/tlp-manager.sh --recommendations
|
|
|
|
# Switch to power saving profile
|
|
./scripts/tlp-manager.sh --profile powersave
|
|
```
|
|
|
|
### 5. CPU Power Management
|
|
|
|
```bash
|
|
# Show current CPU power status
|
|
./scripts/cpu-power-control.sh status
|
|
|
|
# Apply power presets
|
|
./scripts/cpu-power-control.sh preset dynamic # 400MHz-4.2GHz (recommended)
|
|
./scripts/cpu-power-control.sh preset balanced # 400MHz-2.2GHz (battery)
|
|
./scripts/cpu-power-control.sh preset max-performance # 1.6GHz-4.2GHz
|
|
|
|
# Set custom power limit
|
|
./scripts/cpu-power-control.sh set 25 # Set 25W power limit
|
|
|
|
# Monitor CPU frequencies in real-time
|
|
sudo ./scripts/monitor-cpu-freq.sh
|
|
```
|
|
|
|
### 6. Battery Drain Analysis
|
|
|
|
```bash
|
|
# Analyze what's draining your battery
|
|
./scripts/battery-drain-analysis.sh
|
|
```
|
|
|
|
## 📁 Directory Structure
|
|
|
|
```
|
|
battery_life/
|
|
├── scripts/
|
|
│ ├── install.sh # Installation script
|
|
│ ├── uninstall.sh # Uninstallation script
|
|
│ ├── battery-monitor.sh # Battery status monitor
|
|
│ ├── battery-drain-analysis.sh # Identify battery draining processes
|
|
│ ├── cpu-power-control.sh # CPU power management tool
|
|
│ ├── monitor-cpu-freq.sh # Real-time CPU frequency monitor
|
|
│ ├── powertop-analyze.sh # PowerTOP analysis tool
|
|
│ └── tlp-manager.sh # TLP configuration manager
|
|
├── config/
|
|
│ ├── tlp.conf # Optimized TLP configuration
|
|
│ └── powertop.service # PowerTOP systemd service
|
|
├── docs/
|
|
│ ├── BIOS-FIX.md # BIOS configuration guide
|
|
│ ├── powertop-guide.md # PowerTOP usage guide
|
|
│ └── tlp-configuration.md # TLP configuration details
|
|
└── README.md
|
|
```
|
|
|
|
## 🛠️ Detailed Usage
|
|
|
|
### Installation Script
|
|
|
|
The installation script (`scripts/install.sh`) automatically:
|
|
- Installs TLP and PowerTOP packages
|
|
- Configures systemd services
|
|
- Applies optimized settings
|
|
- Creates backup of existing configurations
|
|
- Installs additional power management tools
|
|
|
|
**Features:**
|
|
- Automatic system detection
|
|
- ThinkPad-specific optimizations
|
|
- Safe installation with rollback options
|
|
- Comprehensive logging
|
|
|
|
### Battery Monitor
|
|
|
|
Real-time battery monitoring with detailed information:
|
|
|
|
```bash
|
|
# Single status check
|
|
./scripts/battery-monitor.sh
|
|
|
|
# Continuous monitoring (updates every 5 seconds)
|
|
./scripts/battery-monitor.sh --watch
|
|
```
|
|
|
|
**Information displayed:**
|
|
- Battery capacity and status
|
|
- Charging/discharging time estimates
|
|
- Power consumption
|
|
- AC adapter status
|
|
- System efficiency metrics
|
|
- Power saving tips
|
|
|
|
### PowerTOP Analysis
|
|
|
|
Generate detailed power consumption reports:
|
|
|
|
```bash
|
|
# Generate 60-second HTML report
|
|
./scripts/powertop-analyze.sh
|
|
|
|
# Custom duration and format
|
|
./scripts/powertop-analyze.sh --duration 120 --format html
|
|
|
|
# Apply automatic optimizations
|
|
./scripts/powertop-analyze.sh --auto-tune
|
|
|
|
# Show latest report in browser
|
|
./scripts/powertop-analyze.sh --show-report
|
|
```
|
|
|
|
**Report formats:**
|
|
- HTML: Interactive web-based reports
|
|
- CSV: Data for spreadsheet analysis
|
|
- TXT: Plain text for terminal viewing
|
|
|
|
### TLP Manager
|
|
|
|
Comprehensive TLP configuration management:
|
|
|
|
```bash
|
|
# Show current TLP status
|
|
./scripts/tlp-manager.sh --status
|
|
|
|
# Display configuration details
|
|
./scripts/tlp-manager.sh --config
|
|
|
|
# Get optimization recommendations
|
|
./scripts/tlp-manager.sh --recommendations
|
|
|
|
# Switch power profiles
|
|
./scripts/tlp-manager.sh --profile powersave|balanced|performance
|
|
|
|
# Force battery/AC mode
|
|
./scripts/tlp-manager.sh --toggle-mode
|
|
```
|
|
|
|
## ⚙️ Configuration Details
|
|
|
|
### TLP Configuration
|
|
|
|
The optimized TLP configuration (`config/tlp.conf`) includes:
|
|
|
|
- **CPU Management**: Aggressive power saving governors
|
|
- **Disk Settings**: Optimized APM levels and timeouts
|
|
- **Graphics**: Power-efficient GPU settings
|
|
- **USB**: Smart autosuspend with device blacklists
|
|
- **Audio**: Power saving for sound devices
|
|
- **Battery Thresholds**: Smart charging limits (ThinkPad)
|
|
- **Radio Devices**: Automatic wireless management
|
|
|
|
### Key Optimizations
|
|
|
|
1. **CPU Scaling**: Uses `powersave` governor on battery
|
|
2. **Frequency Limits**: Reduces max CPU frequency on battery
|
|
3. **Turbo Boost**: Disabled on battery to save power
|
|
4. **Disk Power Management**: Aggressive APM settings
|
|
5. **USB Autosuspend**: Enabled with smart device handling
|
|
6. **Wireless Management**: Auto-disable unused radios
|
|
7. **Battery Charging**: Smart thresholds to extend battery life
|
|
|
|
## 🔧 Customization
|
|
|
|
### Modifying TLP Settings
|
|
|
|
1. Edit the configuration file:
|
|
```bash
|
|
sudo nano /etc/tlp.conf
|
|
```
|
|
|
|
2. Or modify the template and reinstall:
|
|
```bash
|
|
nano config/tlp.conf
|
|
./scripts/install.sh # Will backup and apply new config
|
|
```
|
|
|
|
### Adding Custom Optimizations
|
|
|
|
Create additional scripts in the `scripts/` directory following the existing patterns. All scripts include:
|
|
- Error handling and safety checks
|
|
- Colored output for better readability
|
|
- Comprehensive logging
|
|
- Usage instructions
|
|
|
|
## 📊 Expected Results
|
|
|
|
Typical battery life improvements:
|
|
- **Light usage**: 20-40% improvement
|
|
- **Normal usage**: 15-30% improvement
|
|
- **Heavy usage**: 10-20% improvement
|
|
|
|
Results vary based on:
|
|
- Hardware configuration
|
|
- Usage patterns
|
|
- Existing system settings
|
|
- Battery age and health
|
|
|
|
## 💡 Additional Battery Saving Tips
|
|
|
|
### Browser Optimization
|
|
Browser tabs are often the biggest battery drain. **Recommended actions**:
|
|
|
|
1. **Install a tab suspender extension** (e.g., Suspender MV3, The Great Suspender)
|
|
- Automatically suspends inactive tabs
|
|
- Can save 50-70% of browser CPU usage
|
|
- Dramatically improves battery life
|
|
|
|
2. **Use Brave's Task Manager** (`Shift+Esc`)
|
|
- Identify and close CPU-intensive tabs
|
|
- Look for tabs using >20% CPU
|
|
|
|
3. **Close unused tabs regularly**
|
|
- Each tab consumes memory and CPU
|
|
- Aim for <20 active tabs
|
|
|
|
4. **Disable unnecessary extensions**
|
|
- Some extensions run constantly in background
|
|
- Check `chrome://extensions` regularly
|
|
|
|
### Application Management
|
|
|
|
1. **Close Element/Slack/Discord when not in use**
|
|
- Chat applications can use 15-30% CPU in background
|
|
- Use web versions when occasional access is needed
|
|
|
|
2. **Pause file sync services** (Nextcloud, Syncthing, Dropbox)
|
|
- Manually trigger sync when needed
|
|
- Prevents constant disk and network activity
|
|
|
|
3. **Reduce screen brightness**
|
|
- Screen is often 30-50% of power consumption
|
|
- Every 10% reduction saves significant battery
|
|
|
|
4. **Close VS Code/IDEs when not coding**
|
|
- Language servers and extensions consume CPU
|
|
- Properly exit rather than minimize
|
|
|
|
## 🔍 Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
1. **TLP not starting**: Check service status with `systemctl status tlp`
|
|
2. **PowerTOP requires sudo**: This is normal for hardware access
|
|
3. **Settings not persisting**: Ensure TLP service is enabled
|
|
4. **Conflicts with other power managers**: Disable conflicting services
|
|
|
|
### Debug Information
|
|
|
|
```bash
|
|
# Check TLP status and configuration
|
|
sudo tlp-stat
|
|
|
|
# View TLP service logs
|
|
journalctl -u tlp.service
|
|
|
|
# Test PowerTOP without changes
|
|
sudo powertop --time=10
|
|
```
|
|
|
|
### Getting Help
|
|
|
|
1. Check the logs in `/var/log/` for error messages
|
|
2. Run `tlp-stat` to see current configuration
|
|
3. Use the troubleshooting commands in each script
|
|
4. Review the official documentation:
|
|
- [TLP Documentation](https://linrunner.de/tlp/)
|
|
- [PowerTOP Guide](https://01.org/powertop/)
|
|
|
|
## 🔄 Uninstallation
|
|
|
|
To remove all components:
|
|
|
|
```bash
|
|
./scripts/uninstall.sh
|
|
```
|
|
|
|
This will:
|
|
- Restore original configurations
|
|
- Remove installed packages (with confirmation)
|
|
- Clean up created services
|
|
- Preserve your data and reports
|
|
|
|
## 🤝 Contributing
|
|
|
|
Contributions are welcome! Please:
|
|
1. Test thoroughly on your system
|
|
2. Include error handling and logging
|
|
3. Follow the existing code style
|
|
4. Update documentation as needed
|
|
|
|
## ⚠️ Disclaimer
|
|
|
|
- Test in a safe environment first
|
|
- Some optimizations may reduce performance
|
|
- Hardware compatibility may vary
|
|
- Always backup important data
|
|
- Use at your own risk
|
|
|
|
## 📜 License
|
|
|
|
This project is provided as-is for educational and practical use. Feel free to modify and distribute according to your needs.
|
|
|
|
---
|
|
|
|
**Happy power saving!** 🔋✨
|
|
|
|
For questions or issues, please check the troubleshooting section or create an issue with detailed system information. |