update 20260413
This commit is contained in:
56
power-management.md
Normal file
56
power-management.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Sway 电源自动管理配置
|
||||
|
||||
## 功能说明
|
||||
|
||||
实现 Sway 环境下根据电源状态自动切换性能模式:
|
||||
- **插电源**:`throughput-performance` (高性能)
|
||||
- **用电池**:`laptop-battery-powersave` (节能降频)
|
||||
|
||||
仅在 Sway 会话生效,不影响 Plasma 的电源管理。
|
||||
|
||||
## 实现方式
|
||||
|
||||
### 1. 自动切换脚本
|
||||
`/usr/local/bin/tuned-auto-switch.sh`
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Only run if Sway is running
|
||||
pgrep -x sway > /dev/null || exit 0
|
||||
|
||||
if [ "$(cat /sys/class/power_supply/AC*/online)" = "1" ]; then
|
||||
tuned-adm profile throughput-performance
|
||||
else
|
||||
tuned-adm profile laptop-battery-powersave
|
||||
fi
|
||||
```
|
||||
|
||||
### 2. Systemd 服务
|
||||
`/etc/systemd/system/tuned-power-switch@.service`
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Switch tuned profile on power change
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/tuned-auto-switch.sh
|
||||
```
|
||||
|
||||
### 3. Udev 规则
|
||||
`/etc/udev/rules.d/99-tuned-power.rules`
|
||||
```
|
||||
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", TAG+="systemd", ENV{SYSTEMD_WANTS}="tuned-power-switch@$kernel.service"
|
||||
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", TAG+="systemd", ENV{SYSTEMD_WANTS}="tuned-power-switch@$kernel.service"
|
||||
```
|
||||
|
||||
## 验证
|
||||
|
||||
查看当前配置:
|
||||
```bash
|
||||
tuned-adm active
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
|
||||
```
|
||||
|
||||
监控切换日志:
|
||||
```bash
|
||||
journalctl -f
|
||||
```
|
||||
Reference in New Issue
Block a user