Clean up local changes

This commit is contained in:
root
2025-10-14 23:06:45 +02:00
parent 6b4b9e0b50
commit 795e430228
6 changed files with 9 additions and 406 deletions

View File

@@ -4,22 +4,16 @@ A comprehensive tool suite for optimizing Linux laptop battery life using TLP an
## 🔋 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.
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, and monitoring tools.
## ✨ 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
@@ -66,31 +60,6 @@ cd battery_life
./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
```
@@ -99,18 +68,13 @@ battery_life/
│ ├── 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
── [Documentation files]
└── README.md
```
@@ -255,46 +219,6 @@ Results vary based on:
- 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

View File

@@ -1,163 +0,0 @@
# BIOS Configuration Fix for CPU Frequency Scaling
## Problem Identified
The CPU was stuck at 1.6 GHz and unable to boost to 4.2 GHz despite all software configurations being correct.
## Root Cause
**Intel SpeedStep Technology** was enabled in BIOS with conflicting settings that prevented dynamic frequency scaling from working properly in Linux.
## Solution
### BIOS Settings Changed:
1. **Intel SpeedStep Technology**: `Disabled`
2. **Power Scheme for AC**: Changed from `Balanced` to `Maximum Performance`
### Location in BIOS:
- **Path**: Config → Power → Intel SpeedStep Technology
- **Original Setting**: [Disabled] or with Mode restrictions
- **New Setting**: Disabled (allows Linux kernel to fully control CPU frequencies)
## Results After BIOS Changes
### On AC Power:
-**Minimum Frequency**: 400 MHz (deep idle)
-**Maximum Frequency**: 4200 MHz (full turbo boost)
-**Dynamic Scaling**: Working perfectly
-**Power Consumption**: 6-8W idle, up to 25W+ under load
### On Battery:
-**Minimum Frequency**: 800 MHz (power saving idle)
-**Maximum Frequency**: 2200 MHz (responsive but battery friendly)
-**Dynamic Scaling**: Working with TLP configuration
-**Turbo Boost**: Enabled but capped at 2.2 GHz for better battery life
## Why This Works
When Intel SpeedStep Technology is **enabled** in BIOS:
- BIOS firmware tries to manage CPU frequencies
- This conflicts with Linux kernel's P-state driver
- Results in frequency locks and limited boost capability
When Intel SpeedStep Technology is **disabled** in BIOS:
- Linux kernel has full control via intel_pstate driver
- Dynamic frequency scaling works as intended
- All boost frequencies are accessible
- TLP can properly manage power states
## Current TLP Configuration
### AC Mode (Plugged In):
```bash
CPU_SCALING_MIN_FREQ_ON_AC=800000 # 800 MHz
CPU_SCALING_MAX_FREQ_ON_AC=4200000 # 4.2 GHz (full boost)
CPU_HWP_ON_AC=balance_performance # Responsive performance
CPU_MAX_PERF_ON_AC=100 # Allow 100% performance
CPU_BOOST_ON_AC=1 # Turbo boost enabled
PLATFORM_PROFILE_ON_AC=performance # Maximum performance
```
### Battery Mode (Unplugged):
```bash
CPU_SCALING_MIN_FREQ_ON_BAT=800000 # 800 MHz
CPU_SCALING_MAX_FREQ_ON_BAT=2200000 # 2.2 GHz (limited boost)
CPU_HWP_ON_BAT=balance_power # Power efficient
CPU_MAX_PERF_ON_BAT=52 # Limit to ~52% (2.2 GHz)
CPU_BOOST_ON_BAT=1 # Turbo enabled but limited
PLATFORM_PROFILE_ON_BAT=balanced # Balanced for battery
```
## Testing Your Configuration
### Check Current Frequency:
```bash
cat /proc/cpuinfo | grep "cpu MHz"
```
### Monitor Frequency Scaling:
```bash
sudo ./scripts/monitor-cpu-freq.sh
```
### Check Current Status:
```bash
./scripts/cpu-power-control.sh status
```
### Create CPU Load to Test Boost:
```bash
# Single-core intensive task
timeout 10s bash -c 'while true; do echo "scale=5000; 4*a(1)" | bc -l > /dev/null; done'
# Multi-core intensive task
yes > /dev/null &
yes > /dev/null &
yes > /dev/null &
yes > /dev/null &
# Kill with: killall yes
```
## Recommended BIOS Settings for Linux
For optimal CPU frequency scaling and power management on Linux:
### Power Management Settings:
-**Intel SpeedStep Technology**: `Disabled` (let Linux manage it)
-**Intel Turbo Boost**: `Enabled`
-**CPU Power Management**: `Enabled`
-**Power Scheme (AC)**: `Maximum Performance`
-**Power Scheme (Battery)**: `Battery Optimized` or `Balanced`
### Thermal Settings:
-**Adaptive Thermal Management**: `Enabled` (prevents overheating)
-**Fan Control**: `Auto` or `Automatic`
### Sleep/Idle Settings:
-**C-States**: `Enabled` (allows deep sleep for power saving)
-**Enhanced C-States**: `Enabled`
## Troubleshooting
### If CPU is still stuck at low frequency:
1. **Verify BIOS settings were saved**:
- Reboot and re-enter BIOS
- Check that SpeedStep is still disabled
2. **Check for conflicting power management**:
```bash
systemctl status power-profiles-daemon
# If running, it may conflict with TLP
```
3. **Restart TLP**:
```bash
sudo systemctl restart tlp
```
4. **Check platform profile**:
```bash
cat /sys/firmware/acpi/platform_profile
# Should be "performance" on AC, "balanced" on battery
```
5. **Verify turbo is enabled**:
```bash
cat /sys/devices/system/cpu/intel_pstate/no_turbo
# Should be 0 (turbo enabled)
```
## References
- TLP Documentation: https://linrunner.de/tlp/
- Intel P-state Driver: https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_pstate.html
- ThinkPad BIOS Settings: https://support.lenovo.com/
## Summary
**Problem Solved**: Disabling Intel SpeedStep in BIOS allows Linux full control
**AC Mode**: Full dynamic range 400 MHz - 4.2 GHz
**Battery Mode**: Battery-friendly 800 MHz - 2.2 GHz with turbo boost
**Power Management**: TLP now working as intended

View File

@@ -1,97 +0,0 @@
#!/bin/bash
# Battery Drain Analysis Script
# Identifies processes and settings consuming battery power
echo "=== Battery Drain Analysis ==="
echo ""
# Check if on battery
if [ -f /sys/class/power_supply/AC/online ]; then
AC_STATUS=$(cat /sys/class/power_supply/AC/online)
if [ "$AC_STATUS" -eq 1 ]; then
echo "⚡ System is on AC power"
else
echo "🔋 System is on battery power"
fi
fi
echo ""
echo "=== Top 10 CPU Consumers ==="
ps aux --sort=-%cpu | head -11 | awk '{printf "%-12s %6s %6s %s\n", $1, $2, $3, $11}' | head -11
echo ""
echo "=== Top 10 Memory Consumers ==="
ps aux --sort=-%mem | head -11 | awk '{printf "%-12s %6s %6s %s\n", $1, $2, $4, $11}' | head -11
echo ""
echo "=== Network Activity ==="
if command -v ss >/dev/null 2>&1; then
CONNECTIONS=$(ss -tunap 2>/dev/null | grep ESTAB | wc -l)
echo "Active network connections: $CONNECTIONS"
echo ""
echo "Top network users:"
ss -tunap 2>/dev/null | grep ESTAB | grep -oP 'users:\(\(".*?",pid=\d+' | sort | uniq -c | sort -rn | head -5
fi
echo ""
echo "=== WiFi Power Management ==="
iwconfig 2>&1 | grep -E "wlp|Power Management" | grep -v "no wireless"
echo ""
echo "=== Wakeup Analysis ==="
if command -v powertop >/dev/null 2>&1; then
echo "Running powertop analysis (3 seconds)..."
sudo powertop --time=3 2>&1 | grep -A 20 "Top 10 Power" | head -22
else
echo "Install powertop for detailed wakeup analysis: sudo apt install powertop"
fi
echo ""
echo "=== Browser Tabs Analysis ==="
# Count Brave renderer processes (each is roughly a tab)
BRAVE_RENDERERS=$(ps aux | grep "brave --type=renderer" | grep -v grep | wc -l)
echo "Brave renderer processes: $BRAVE_RENDERERS (≈ number of tabs)"
# Find most CPU-intensive Brave processes
echo ""
echo "Most CPU-intensive Brave tabs:"
ps aux | grep "brave --type=renderer" | grep -v grep | sort -k3 -rn | head -3 | awk '{printf " PID: %6s CPU: %5s%% MEM: %5s%%\n", $2, $3, $4}'
echo ""
echo "=== Recommendations ==="
echo ""
# Check for high CPU usage
HIGH_CPU=$(ps aux --sort=-%cpu | head -2 | tail -1 | awk '{print $3}' | cut -d. -f1)
if [ "$HIGH_CPU" -gt 50 ]; then
TOP_PROCESS=$(ps aux --sort=-%cpu | head -2 | tail -1 | awk '{print $11}')
echo "⚠️ High CPU usage detected: $TOP_PROCESS using $HIGH_CPU%"
echo " Consider closing or suspending this application"
echo ""
fi
# Check for many browser tabs
if [ "$BRAVE_RENDERERS" -gt 20 ]; then
echo "⚠️ Many browser tabs open ($BRAVE_RENDERERS processes)"
echo " Consider using tab suspension extension or closing unused tabs"
echo ""
fi
# Check for Element
if pgrep -x "element-desktop" > /dev/null; then
ELEMENT_CPU=$(ps aux | grep element-desktop | grep -v grep | head -1 | awk '{print $3}' | cut -d. -f1)
if [ "$ELEMENT_CPU" -gt 10 ]; then
echo "⚠️ Element Desktop is using ${ELEMENT_CPU}% CPU"
echo " Consider closing when not actively using Matrix"
echo ""
fi
fi
echo "💡 Quick fixes:"
echo " • Close unused browser tabs"
echo " • Suspend browser tabs with 'The Great Suspender' extension"
echo " • Close Element Desktop if not needed: killall element-desktop"
echo " • Reduce screen brightness"
echo " • Check: ./scripts/cpu-power-control.sh preset balanced"
echo ""

0
scripts/cpu-power-control.sh Executable file → Normal file
View File

View File

@@ -1,61 +0,0 @@
#!/bin/bash
# Real-time CPU Frequency Monitor
# Shows actual CPU frequencies and helps identify boost behavior
echo "=== Real-time CPU Frequency Monitor ==="
echo "Press Ctrl+C to stop"
echo ""
echo "Note: Modern Intel CPUs dynamically adjust frequency based on:"
echo " - Workload type (single vs multi-core)"
echo " - Power limits (TDP)"
echo " - Temperature"
echo " - Energy efficiency preferences"
echo ""
# Check if turbostat is available
if command -v turbostat >/dev/null 2>&1; then
echo "Using turbostat for accurate frequency monitoring..."
echo ""
sudo turbostat --quiet --show Core,CPU,Busy%,Bzy_MHz,PkgWatt --interval 2
else
echo "turbostat not available, using basic monitoring..."
echo ""
echo "Timestamp | CPU0 CPU1 CPU2 CPU3 | Avg MHz | Governor | Temp"
echo "----------------+---------------------------------+---------+-----------+------"
while true; do
TIMESTAMP=$(date +"%H:%M:%S")
# Get frequencies
FREQ0=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
FREQ1=$(cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq)
FREQ2=$(cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq)
FREQ3=$(cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq)
# Convert to MHz
F0=$((FREQ0 / 1000))
F1=$((FREQ1 / 1000))
F2=$((FREQ2 / 1000))
F3=$((FREQ3 / 1000))
# Calculate average
AVG=$(( (F0 + F1 + F2 + F3) / 4 ))
# Get governor
GOV=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
# Get temperature if available
if [ -r "/sys/class/thermal/thermal_zone0/temp" ]; then
TEMP_RAW=$(cat /sys/class/thermal/thermal_zone0/temp)
TEMP=$((TEMP_RAW / 1000))
else
TEMP="N/A"
fi
printf "%s | %4d %4d %4d %4d | %4d MHz | %-9s | %s°C\n" \
"$TIMESTAMP" "$F0" "$F1" "$F2" "$F3" "$AVG" "$GOV" "$TEMP"
sleep 2
done
fi

0
scripts/test-single-core-boost.sh Executable file → Normal file
View File