johnfanv2 / LenovoLegionLinux

Driver and tools for controlling Lenovo Legion laptops in Linux including fan control and power mode.
https://github.com/johnfanv2/LenovoLegionLinux
GNU General Public License v2.0
1.52k stars 55 forks source link

Create legion-linux-onresume.service #176

Closed st0nie closed 6 months ago

st0nie commented 6 months ago

Some modifications, such as the changes made by ryzenadj, cannot be preserved after the machine goes through the suspend-resume cycle. Therefore, we can create a file to allow the Legion service to automatically start once the machine resumes.

st0nie commented 6 months ago

sudo mv this_file_path /usr/lib/systemd/system-sleep/legion to make it working require systemd, of course tested on my machine

st0nie commented 6 months ago

Now I create legion-linux-onresume.service and it seems better Just enable the service,legion-linux will auto restart on system resume

st0nie commented 6 months ago

The reason why I use restart instead of try-restart is that legion-linux.service will be inactive after a while, and try-restart only restart service which is active

st0nie commented 6 months ago

cc @MrDuartePT

MrDuartePT commented 6 months ago

That why I noticed some times systemd was degraded and the service failed to start. Thanks to find a solution I will just need to do some changes to the packaging.

st0nie commented 6 months ago

That why I noticed some times systemd was degraded and the service failed to start. Thanks to find a solution I will just need to do some changes to the packaging.

IDK whether the fancurve-set will preserve its modification But changes made by ryzenadj will 100% lost after resume

st0nie commented 6 months ago

https://gist.github.com/amanjeev/69eeb3a37aadb403542a16903fd60cbb

We can also introduce a timer to ensure the cpu tune is working

MrDuartePT commented 6 months ago

I giving a look now and my service was failing because I change to a kernel without the kernel module install. This seems to be a bug only with ryzenadj since the fan curve mantain after a suspend.

Well I also thinking of use the legion_cli.py as deamon instead of a seperate bash script, but we can add this systemd service in the mid time. The ryzenadj support just exist because some of cpu limit stuff in the gui dosen't work in some older model, so user can use ryzenadj to also set cpu option (and ryzenadj have more option), but it can be edit to other tool if you are using intel.

st0nie commented 6 months ago

Well I also thinking of use the legion_cli.py as deamon instead of a seperate bash script, but we can add this systemd

legion-linux.service as a daemon is probably better than now Now this is a script and we cannot make sure it is really working after we exec it. If it is a daemon, we can do some check after /sys/firmware/acpi/platform_profile changed and or pluged off the AC After all, daemon is simpler for user, they just need to enable the service, and legion-linux daemon do all the things

MrDuartePT commented 6 months ago

just a quick note also work in /usr/lib/systemd/system/legion-linux-onresume.service

mrduarte@GentooLegion ~/mrduarte-github/guru/sys-firmware/lenovolegionlinux (dev) $ systemctl status legion-linux-onresume.service
○ legion-linux-onresume.service - Restart legion-linux on resume
     Loaded: loaded (/usr/lib/systemd/system/legion-linux-onresume.service; enabled; preset: disabled)
     Active: inactive (dead)

Mar 10 18:09:06 GentooLegion systemd[1]: Finished Restart legion-linux on resume.
Mar 10 18:09:11 GentooLegion systemd[1]: Stopping Restart legion-linux on resume...
Mar 10 18:09:11 GentooLegion systemd[1]: legion-linux-onresume.service: Deactivated successfully.
Mar 10 18:09:11 GentooLegion systemd[1]: Stopped Restart legion-linux on resume.
mrduarte@GentooLegion ~/mrduarte-github/guru/sys-firmware/lenovolegionlinux (dev) $ systemctl status legion-linux.service
○ legion-linux.service - Apply Fan Curve to Lenovo Legion Laptop depending on Power State and Charger Mode (LenovoLegi>
     Loaded: loaded (/usr/lib/systemd/system/legion-linux.service; enabled; preset: disabled)
     Active: inactive (dead) since Sun 2024-03-10 18:09:12 WET; 10s ago
   Duration: 672ms
TriggeredBy: ● legion-linux.path
    Process: 85712 ExecStart=/usr/bin/fancurve-set (code=exited, status=0/SUCCESS)
   Main PID: 85712 (code=exited, status=0/SUCCESS)
        CPU: 663ms

Mar 10 18:09:11 GentooLegion systemd[1]: Starting Apply Fan Curve to Lenovo Legion Laptop depending on Power State and>
Mar 10 18:09:11 GentooLegion systemd[1]: Started Apply Fan Curve to Lenovo Legion Laptop depending on Power State and >
Mar 10 18:09:11 GentooLegion fancurve-set[85712]: Applying Performance Mode Profile 龍  -> charger...
Mar 10 18:09:12 GentooLegion fancurve-set[85730]: Successfully wrote preset /etc/legion_linux//performance-ac to hardw>
Mar 10 18:09:12 GentooLegion systemd[1]: legion-linux.service: Deactivated successfully.
mrduarte@GentooLegion ~/mrduarte-github/guru/sys-firmware/lenovolegionlinux (dev) $