Problem statement
I try to make the tuning recommandations provided by PowerTop permanent by writing kernel settings in a script executed in a oneshot systemd service. Scripts contains line such as
[...]
echo 'auto' > '/sys/bus/i2c/devices/i2c-6/device/power/control';
[...]
But for some reason, settings are not applied after startup. Running a systemctl start powertop
manually in a terminal after login properly applies the parameters. I cannot figure out why it work after login, but not at startup.
The approach is inspired from How do I make Powertop changes permanent?
Configuration
The definition of the service in /etc/systemd/system/powertop.service
is as follow
[Unit]
Description=Power tuning based on PowerTOP
[Service]
Type=oneshot
Environment="TERM=dumb"
RemainAfterExit=true
ExecStart=/home/XXXX/Documents/scripts/powertop/powertune.sh
[Install]
WantedBy=multi-user.target
The script writing the kernel configuation is as folow
#!/bin/bash
echo "power tuning"
whoami
echo 'auto' > '/sys/bus/i2c/devices/i2c-6/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-7/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-1/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-2/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-3/device/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:02.0/power/control';
echo 'auto' > '/sys/block/sda/device/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.4/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/ata2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/ata3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.5/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/ata1/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:16.3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:04.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:02:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.6/power/control';
echo 'disabled' > '/sys/bus/usb/devices/1-5.1/power/wakeup';
Verification already done
The service has been properly enabled with systemctl enable powertop
, and I can verify with a systemctl status powertop
that is was indeed exectued at startup.
root@cs0:/etc/systemd/system# systemctl status powertop
● powertop.service - Power tuning based on PowerTOP
Loaded: loaded (/etc/systemd/system/powertop.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2022-11-14 19:36:00 CET; 9s ago
Process: 6584 ExecStart=/home/XXXXX/Documents/scripts/powertop/powertune.sh (code=exited, status=0/SUCCESS)
Main PID: 6584 (code=exited, status=0/SUCCESS)
CPU: 6ms
Nov 14 19:36:00 cs0 systemd[1]: Starting Power tuning based on PowerTOP...
Nov 14 19:36:00 cs0 powertune.sh[6584]: power tuning
Nov 14 19:36:00 cs0 powertune.sh[6585]: root
Nov 14 19:36:00 cs0 systemd[1]: Finished Power tuning based on PowerTOP.
System
- Ubuntu 22.04.1 LTS
- Linux cs0 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Any help would really be appreciated.