Dietpi: process tool applies changes only to the father process

Created on 20 Jul 2018  ยท  15Comments  ยท  Source: MichaIng/DietPi

Creating a feature request:

process tool applies changes only to the father process

process tool applies changes only to the father proces,
this is normal, is it a technical choice? Is that so?

if I assign a cpu (affinity) to a player, only the father process is associated ... the child processes are not ...
I do not know this is normal

Bug

Most helpful comment

Testing https://github.com/Fourdee/DietPi/blob/testing/dietpi/dietpi-process_tool

image

root@DietPi:~# dietpi-process_tool 1

 DietPi-Process_tool
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 Mode: Apply

[  OK  ] DietPi-Process_tool | Cron (26136) : Nice      2
[  OK  ] DietPi-Process_tool | Cron (26136) : Affinity  0
[  OK  ] DietPi-Process_tool | Cron (26136) : Scheduler SCHED_BATCH 0
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Nice      2
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Affinity  1
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Nice      5
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Affinity  3
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Scheduler SCHED_FIFO 30
[  OK  ] DietPi-Process_tool | Completed

parent = 26157
threads = 26157 - 26160

image

root@DietPi:~# taskset -cp 26160
pid 26160's current affinity list: 3
root@DietPi:~# taskset -cp 26159
pid 26159's current affinity list: 3
root@DietPi:~# taskset -cp 26158
pid 26158's current affinity list: 3
root@DietPi:~# taskset -cp 26157
pid 26157's current affinity list: 3
root@DietPi:~# chrt -v -p 26158
pid 26158's current scheduling policy: SCHED_FIFO
pid 26158's current scheduling priority: 30
root@DietPi:~# chrt -v -p 26157
pid 26157's current scheduling policy: SCHED_FIFO
pid 26157's current scheduling priority: 30

@antonellocaroli

Should be good to go ๐Ÿ‘ Many thanks for the ps tip

All 15 comments

@antonellocaroli
Thanks for your report.

This can happen, if the father process and the child processes have different process names. The process tool checks for certain names to handle. Which process is it in your case?

Perhaps we can make the tool more intelligent to always detect all child processes, but we have do dig into it.

in fact I was trying processtool on another distro (gentoo / open-rc), maybe that's the fact.

that dietpi uses system ... and type for squeezelite there is only one process ...
instead I find 4

@antonellocaroli

in fact I was trying processtool on another distro (gentoo / open-rc),

Hi,

All our scripts require Debian currently to function correctly. It's also not advised to use single DietPi scripts, without 1st running PREP on the system, as DietPi is a complete script system and expects/requires additional script functions contained within other files.

Regardless,

We check for all available processes that match aPROCESS_NAME:
https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-process_tool#L74-L75

Then we apply the process tool settings to the PID's pulled from the match:
https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-process_tool#L83

Check ps ax output, that is what we use to obtain available PID's before matching:
https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-process_tool#L59


As mentioned above, we do not support the distro's you are using at this time. As such, i'll mark this as closed, however, please continue discussions if required.

@MichaIng
~Known issue?~

Confirmed:
image

Appears kernel/user-land threads are not applied?


Same PID, different SPID:

root@DietPi:~# ps -T 12371
  PID  SPID TTY      STAT   TIME COMMAND
12371 12371 ?        S<Lsl   0:00 /usr/bin/squeezelite -a 4096 1024 16 0 -C 5 -n DietPi-Squeezelite -f /var/log/sq
12371 12373 ?        SLsl   0:00 /usr/bin/squeezelite -a 4096 1024 16 0 -C 5 -n DietPi-Squeezelite -f /var/log/squ
12371 12374 ?        SLsl   0:00 /usr/bin/squeezelite -a 4096 1024 16 0 -C 5 -n DietPi-Squeezelite -f /var/log/squ
12371 12375 ?        SLsl   0:00 /usr/bin/squeezelite -a 4096 1024 16 0 -C 5 -n DietPi-Squeezelite -f /var/log/squ

Unsure how to determine if SPID uses PID applied values?

root@DietPi:~# ps -lp 12371
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0 12371     1  0  75  -5 -  2570 poll_s ?        00:00:02 squeezelite
root@DietPi:~# ps -lp 12373
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD

@Fourdee
Ah sorry, I remember saw once process tool failing to set nice for a related process (logging daemon, other sub/side process), where the name was totally different. Thought this is related. But hum yeah this is a different case. Didn't know SPID and these kind of sub processes. So far, thinking about webserver, PHP etc, all had different PIDs. Hmm yeah lets investigate and see if we can apply process handling for all children of one PID.

Ok, we can at least renice to SPID directly.

๐Ÿˆฏ๏ธ This works applying to PID group -g:

renice -n 5 -g 12371

image


taskset
-a, --all-tasks operate on all the tasks (threads) for a given pid
same for chrt

๐Ÿˆฏ๏ธ taskset:

requires p and a

root@DietPi:~# taskset -apc 1 12385
pid 12385's current affinity list: 0
pid 12385's new affinity list: 1
#PID
root@DietPi:~# taskset -pc 1 12385
pid 12385's current affinity list: 0-3
pid 12385's new affinity list: 1

#All threads
root@DietPi:~# taskset -ac 1 12385
taskset: failed to execute 12385: No such file or directory

@antonellocaroli

Apologies for slamming the "we dont support your distro" initially. From past experience we have to clearly define what we support, else, it becomes impossible.

Great find on this bug and many thanks for reporting it ๐Ÿ‘

The updated script is available here, which now applies to all child threads:
https://raw.githubusercontent.com/Fourdee/DietPi/926ebe115c8f64b775b39877e621614dce3e3d13/dietpi/dietpi-process_tool

If you could confirm this resolves the issue i'd be grateful.

Thanks for the change,

now everything seems to work, except for affinity that seems to go on the child processes but not on that father.
selection_087

Apologies for slamming the "we dont support your distro" initially. From past experience we have to clearly define what we support, else, it becomes impossible.

No problem!!! I understand perfectly

I generally use something like that:

task_tid=($(ps -C $app -L --no-headers -o tid))

taskset -cp $core ${task_tid[0]}
taskset -cp $core ${task_tid[1]}
taskset -cp $core ${task_tid[2]}
taskset -cp $core ${task_tid[3]}
taskset -cp $core ${task_tid[4]}

now and then from failed
selection_089
selection_090
but this can be a specific problem on my system

Seems the PID group apply fails on some threads/processes:

[  OK  ] DietPi-Process_tool | Plex Media Server (16296) : Affinity  0-3
[  OK  ] DietPi-Process_tool | Plex Media Server (16296) : Scheduler SCHED_OTHER 0
renice: failed to get priority for 16596 (process group ID): No such process
[FAILED] DietPi-Process_tool | Plex DLNA Server (16596) : Nice      0

But works manually afterwards, when setting PID, not group:

root@DietPi:~# renice -n 5 16596
16596 (process ID) old priority 0, new priority 5

~Ok, so we need to apply group to threads, not the parent?~
Maybe simple solution, should be quicker code wise, than checking for every PID vs SPID match:

  • Apply to group first, (process with threads) if fails
  • Apply to PID only (single process)

Useful debug cmd based on @antonellocaroli

ps ax -L --no-headers -o pid -o tid -o nice -o cmd

Testing https://github.com/Fourdee/DietPi/blob/testing/dietpi/dietpi-process_tool

image

root@DietPi:~# dietpi-process_tool 1

 DietPi-Process_tool
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 Mode: Apply

[  OK  ] DietPi-Process_tool | Cron (26136) : Nice      2
[  OK  ] DietPi-Process_tool | Cron (26136) : Affinity  0
[  OK  ] DietPi-Process_tool | Cron (26136) : Scheduler SCHED_BATCH 0
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Nice      2
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Affinity  1
[  OK  ] DietPi-Process_tool | DHCP Client (652) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (487) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (6523) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Nice      3
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Affinity  2
[  OK  ] DietPi-Process_tool | OpenSSH Server (16678) : Scheduler SCHED_OTHER 0
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Nice      5
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Affinity  3
[  OK  ] DietPi-Process_tool | Squeezelite (26157) : Scheduler SCHED_FIFO 30
[  OK  ] DietPi-Process_tool | Completed

parent = 26157
threads = 26157 - 26160

image

root@DietPi:~# taskset -cp 26160
pid 26160's current affinity list: 3
root@DietPi:~# taskset -cp 26159
pid 26159's current affinity list: 3
root@DietPi:~# taskset -cp 26158
pid 26158's current affinity list: 3
root@DietPi:~# taskset -cp 26157
pid 26157's current affinity list: 3
root@DietPi:~# chrt -v -p 26158
pid 26158's current scheduling policy: SCHED_FIFO
pid 26158's current scheduling priority: 30
root@DietPi:~# chrt -v -p 26157
pid 26157's current scheduling policy: SCHED_FIFO
pid 26157's current scheduling priority: 30

@antonellocaroli

Should be good to go ๐Ÿ‘ Many thanks for the ps tip

thank you,

now it seems to work perfectly !!!

great

@antonellocaroli

thank you,
now it seems to work perfectly !!!

Excellent, been testing it locally aswell, all seems good.

I'll mark this as completed. Thanks again for reporting this issue and your assistance ๐Ÿ‘

Personally, I will try to also move the system interrupts (USB and ethernet) on a specific core ....
what do you think?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fourdee picture Fourdee  ยท  86Comments

N3mill0 picture N3mill0  ยท  107Comments

Phil1988 picture Phil1988  ยท  60Comments

Joulinar picture Joulinar  ยท  55Comments

k-plan picture k-plan  ยท  90Comments