Total number of context switches
cat /proc/PID/sched|grep nr_switches
Voluntary Context Switches
cat /proc/PID/sched | grep nr_voluntary_switches
Inappropriate context switches
cat /proc/PID/sched|grep nr_involuntary_switches
where PID is the process identifier of the process that you want to control.
However, if you want to get these statistics by correcting (by creating a hook) the linux source, the planning-related code is present in
kernel / SCHED /
folders of the source tree. In particular,
kernel / sched / core.c contains the sched () function, which is the linux scheduler code. The CFS (fully fair scheduler) code, which is one of several schedulers present on Linux, is most commonly used in
/kernel/sched/fair.c
scheduler () is executed when the TIF_NEED_RESCHED flag is set, so find out from which all places set this flag (use cscope in the linux source), which will give you an idea of ββthe types of context switches that occur for the process.
Sahil singh
source share