sched-ext / scx

sched_ext schedulers and tools
https://bit.ly/scx_slack
GNU General Public License v2.0
838 stars 78 forks source link

scx-scheds: Add After=graphical.target into service (third attempt) #392

Closed sirlucjan closed 2 months ago

sirlucjan commented 3 months ago

The second approach to change the policy of launching the systemd service.

The first approach was not successful, but nevertheless the problem with too early loading of the service remained. This time we managed to achieve a working result.

lucjan at cachyos ~ 18:08:30    
❯ systemctl status scx
● scx.service - Start scx_scheduler
     Loaded: loaded (/usr/lib/systemd/system/scx.service; enabled; preset: disabled)
     Active: active (running) since Wed 2024-06-26 18:01:39 CEST; 6min ago
 Invocation: a3d1f5a0843c41cb93acec4578eaa1ea
   Main PID: 683 (scx_rusty)
      Tasks: 13 (limit: 37758)
     Memory: 235.4M (peak: 246M)
        CPU: 627ms
     CGroup: /system.slice/scx.service
             └─683 scx_rusty

cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   repatriate_total: 0 [0.0/s]
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   task_errors_total: 0 [0.0/s]
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO] Gauges:
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   slice_length_us: 1000.00
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO] Histograms:
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   cpu_busy_pct: avg=98.31 min=96.62 max=100.00
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   load_avg node=0: avg=1340.44 min=1262.99 max=1417.88
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   load_avg node=0 dom=0: avg=1340.44 min=1262.99 max=1417.88
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO]   processing_duration_us: avg=148.50 min=148.00 max=149.00
cze 26 18:08:33 cachyos bash[683]: 16:08:33 [INFO] ---
lucjan at cachyos ~ 18:08:34    
❯ cat /usr/lib/systemd/system/scx.service
[Unit]
Description=Start scx_scheduler
ConditionPathIsDirectory=/sys/kernel/sched_ext
StartLimitIntervalSec=30
StartLimitBurst=2
After=graphical.target

[Service]
Type=simple
EnvironmentFile=/etc/default/scx
ExecStart=/bin/bash -c 'exec ${SCX_SCHEDULER_OVERRIDE:-$SCX_SCHEDULER} ${SCX_FLAGS_OVERRIDE:-$SCX_FLAGS} '
Restart=on-failure
StandardError=journal
LogNamespace=sched-ext

[Install]
WantedBy=graphical.target
lucjan at cachyos ~ 18:08:38    
❯ systemctl show -p Requires,Wants,Requisite,BindsTo,PartOf,Before,After scx.service
Requires=systemd-journald@sched-ext.socket systemd-journald-sync@sched-ext.service system.slice systemd-journald-varlink@sched-ext.socket sysinit.target
Requisite=
Wants=
BindsTo=
PartOf=
Before=shutdown.target
After=systemd-journald@sched-ext.socket graphical.target systemd-journald-sync@sched-ext.service system.slice sysinit.target systemd-journald-varlink@sched-ext.socket basic.target

Potential issues

This solution has drawbacks. Simply reloading the service with systemctl daemon-reload or even reboot MAY be not enough. For some users it is required to execute systemctl disable --now scx.service and systemctl enable --now scx.service.

I realize that this is not a good solution, but at the moment I am unable to think of anything else. Feel free to discuss

sirlucjan commented 3 months ago

2024-06-26 19 33 27 discord com b1bcde905e6d 2024-06-26 19 34 04 discord com b2f29d61c7ad

I got a report that on the existing systemd files everything works if scx-scheds-git is used.

sirlucjan commented 3 months ago

I managed to figure everything out and found that: systemctl daemon-reload sometimes does not remove symlinks from /etc/systemd/system/*targets and then you need full disable and enable. Ive changed WantedBy=multi-user.target into WantedBy=graphical.target some time ago https://github.com/sched-ext/scx/pull/332 but it didn't work even with reboot! To change target I HAVE to disable service and enable it again. And only then new symlink was created. For this reason, PR is drafted so far. We need to make sure we need it.

sirlucjan commented 3 months ago

systemctl reenable scx will cause that no matter what change we make to the systemd service, it will always work. Unfortunately, systemctl daemon-reload does not move symlinks between targets, so users who already had this installed will still have to make systemctl enable scx manually (without this commit).

(2/3) Arming ConditionNeedsUpdate...
(3/3) Checking scx_scheduler...
The service is active. Restarting...
Removed '/etc/systemd/system/graphical.target.wants/scx.service'.
Created symlink '/etc/systemd/system/graphical.target.wants/scx.service' → '/usr/lib/systemd/system/scx.service'.
Service has been restarted.
'makepkg -srdi --sign' time: 52:43,17s, cpu: 303%
lucjan at cachyos ~/Pobrane/scx-scheds-git 23:44:20    
❯ systemctl status scx                   
● scx.service - Start scx_scheduler
     Loaded: loaded (/usr/lib/systemd/system/scx.service; enabled; preset: disabled)
     Active: active (running) since Wed 2024-07-03 23:44:20 CEST; 15s ago
 Invocation: 5a3ecc59673b424ca3968a65fbcddf9e
   Main PID: 57401 (scx_bpfland)
      Tasks: 2 (limit: 37758)
     Memory: 6.9M (peak: 17.6M)
        CPU: 81ms
     CGroup: /system.slice/scx.service
             └─57401 scx_bpfland

lip 03 23:44:26 cachyos bash[57401]: 21:44:26 [INFO] running: 1    | unbound: 1    | direct: 3850   | prio: 680    | shared: 607
lip 03 23:44:27 cachyos bash[57401]: 21:44:27 [INFO] running: 1    | unbound: 1    | direct: 4339   | prio: 789    | shared: 632
lip 03 23:44:28 cachyos bash[57401]: 21:44:28 [INFO] running: 1    | unbound: 1    | direct: 4564   | prio: 802    | shared: 645
lip 03 23:44:29 cachyos bash[57401]: 21:44:29 [INFO] running: 1    | unbound: 1    | direct: 4764   | prio: 813    | shared: 655
lip 03 23:44:30 cachyos bash[57401]: 21:44:30 [INFO] running: 1    | unbound: 1    | direct: 4989   | prio: 826    | shared: 670
lip 03 23:44:31 cachyos bash[57401]: 21:44:31 [INFO] running: 1    | unbound: 1    | direct: 5234   | prio: 843    | shared: 679
lip 03 23:44:32 cachyos bash[57401]: 21:44:32 [INFO] running: 1    | unbound: 1    | direct: 5453   | prio: 860    | shared: 691
lip 03 23:44:33 cachyos bash[57401]: 21:44:33 [INFO] running: 1    | unbound: 1    | direct: 7574   | prio: 927    | shared: 912
lip 03 23:44:34 cachyos bash[57401]: 21:44:34 [INFO] running: 1    | unbound: 1    | direct: 7884   | prio: 971    | shared: 934
lip 03 23:44:35 cachyos bash[57401]: 21:44:35 [INFO] running: 1    | unbound: 1    | direct: 8121   | prio: 988    | shared: 947

Sources:

https://serverfault.com/questions/700862/do-systemd-unit-files-have-to-be-reloaded-when-modified

2024-07-03_22 12 57_serverfault com_978e44eb4c62

sirlucjan commented 2 months ago

It seems that for the time being there is no need to change: https://github.com/sched-ext/scx/issues/354#issuecomment-2220245447 However, if necessary, I will return to test.