Last active
June 30, 2022 01:42
-
-
Save kitten/cd78d8531873d5dbea48b1d7bdafd271 to your computer and use it in GitHub Desktop.
Add systemd targets and services to set SB2 perf_mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "Creating systemd ac.target." | |
cat > /etc/systemd/system/ac.target << 'EOF' | |
[Unit] | |
Description=On AC power | |
DefaultDependencies=no | |
StopWhenUnneeded=yes | |
EOF | |
echo "Creating systemd battery.target." | |
cat > /etc/systemd/system/battery.target << 'EOF' | |
[Unit] | |
Description=On battery power | |
DefaultDependencies=no | |
StopWhenUnneeded=yes | |
EOF | |
echo "Creating udev rule for systemd targets." | |
cat > /etc/udev/rules.d/99-powertargets.rules << 'EOF' | |
SUBSYSTEM=="power_supply", KERNEL=="ADP1", ATTR{online}=="0", RUN+="/usr/sbin/systemctl start battery.target" | |
SUBSYSTEM=="power_supply", KERNEL=="ADP1", ATTR{online}=="1", RUN+="/usr/sbin/systemctl start ac.target" | |
EOF | |
udevadm control --reload-rules | |
echo "Creating systemd powerdown.service." | |
cat > /etc/systemd/system/powerdown.service << 'EOF' | |
[Unit] | |
Description=Set power state to power-saving on battery | |
[Service] | |
Type=oneshot | |
ExecStart=/bin/bash -c "echo 2 | tee '/sys/devices/platform/MSHW0107:00/perf_mode'; echo 'PERFORMANCE STATE set to battery saver'" | |
[Install] | |
WantedBy=battery.target | |
EOF | |
echo "Creating systemd powerup.service." | |
cat > /etc/systemd/system/powerup.service << 'EOF' | |
[Unit] | |
Description=Set power state to best on AC | |
[Service] | |
Type=oneshot | |
ExecStart=/bin/bash -c "echo 4 | tee '/sys/devices/platform/MSHW0107:00/perf_mode'; echo 'PERFORMANCE STATE set to best'" | |
[Install] | |
WantedBy=ac.target | |
EOF | |
echo "Enabling services." | |
systemctl enable powerdown | |
systemctl enable powerup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment