You can use /proc/$PID/task
to find all threads of a given process, therefore you can use
$ ls /proc/$PID/task | xargs renice $PRIO
to renice
all threads belonging to a given process.
Same way /proc/$PID/task/$PID/children
can be used to find all child processes (or /proc/$PID/task/*/children
if you want all child processes of all threads of a given process).
$ cat /proc/$PID/task/$PID/children | xargs renice $PRIO
$ cat /proc/$PID/task/*/children | xargs renice $PRIO
I don't have an answer but you might find one amongst the tools, examples and resources written or listed by
Brendan Gregg on the perf
command and Linux kernel ftrace and debugfs.
On my Raspberry Pi these tools were in package perf-tools-unstable
. The perf
command was actually in /usr/bin/perf_3.16
.
Of interest may be this discussion and context-switch benchmark by Benoit Sigoure, and the lat_ctx test from the fairly old lmbench suite.
They may need some work to run on the Pi, for example with tsuna/contextswitch
I edited timectxswws.c
get_iterations()
to while (iterations * ws_pages * 4096UL < 4294967295UL) {
, and removed -march=native -mno-avx
from the Makefile
.
Using perf record
for 10 seconds on the Pi over ssh whilst simultaneously doing while sleep .1;do echo hi;done
in another ssh:
sudo timeout -10 perf_3.16 record -e context-switches -a
sudo perf_3.16 script -f time,pid,comm | less
gives output like this
sleep 29341 2703976.560357:
swapper 0 2703976.562160:
kworker/u8:2 29163 2703976.564901:
swapper 0 2703976.565737:
echo 29342 2703976.565768:
migration/3 19 2703976.567549:
sleep 29343 2703976.570212:
kworker/0:0 28906 2703976.588613:
rcu_preempt 7 2703976.609261:
sleep 29343 2703976.670674:
bash 29066 2703976.671654:
echo 29344 2703976.675065:
sshd 29065 2703976.675454:
swapper 0 2703976.677757:
presumably showing when a context-switch event happened, for which process.
Best Answer
You can view information about your process's context switches in
/proc/<pid>/status
.To see these numbers updating continuously, run
To get just the numbers, run