11-10-2018, 02:07 AM
Here's a bit of analysis :-)
Try the commands below to get a sense of the volume of context switches happening for just the MPD process and its associated threads.
1) Get the process (PID) and thread (TID) id's for MPD
ps H -q `pidof -s mpd` -o 'pid,tid,cls,rtprio,comm'
PID TID CLS RTPRIO COMMAND
961 961 TS - mpd
961 965 TS - io
961 966 FF 50 rtio
961 1222 TS - player
961 1223 TS - decoder:flac
961 1248 FF 50 output:ALSA def
2) Monitor the number of CPU context switches by PID/TID from above
watch -n.5 grep ctxt /proc/961/status
watch -n.5 grep ctxt /proc/965/status
watch -n.5 grep ctxt /proc/966/status
watch -n.5 grep ctxt /proc/1222/status
watch -n.5 grep ctxt /proc/1223/status
watch -n.5 grep ctxt /proc/1248/status
What you will see in the command output is the number of voluntary vs involuntary context switches. Here is what that means.
A context switch is voluntary if the process or thread gives up the CPU because it has nothing else to do for example while it is waiting for something external to happen like an I-O interrupt from the audio device requesting more data. A context switch is involuntary if the process or task would like to continue doing work but the OS decides it's time to switch to some other process or thread.
In my example above the MPD process (961) has no CPU context switches shortly after music starts playing. The output:ALSA def thread (1248) will continuously context switch but all are voluntary which suggests its simply waiting for hardware interrupts from the audio device requesting more data, as opposed to being preempted by some other thread or giving up its CPU time slice.
You should see something like below for the output:ALSA def thread where voluntary_ctxt_switches constantly increases while nonvoluntary_ctxt_switches remains 0.
Every 0.5s: grep ctxt /proc/1248/status rp3: Fri Nov 9 20:44:32 2018
voluntary_ctxt_switches: 505754
nonvoluntary_ctxt_switches: 0
-Tim
Try the commands below to get a sense of the volume of context switches happening for just the MPD process and its associated threads.
1) Get the process (PID) and thread (TID) id's for MPD
ps H -q `pidof -s mpd` -o 'pid,tid,cls,rtprio,comm'
PID TID CLS RTPRIO COMMAND
961 961 TS - mpd
961 965 TS - io
961 966 FF 50 rtio
961 1222 TS - player
961 1223 TS - decoder:flac
961 1248 FF 50 output:ALSA def
2) Monitor the number of CPU context switches by PID/TID from above
watch -n.5 grep ctxt /proc/961/status
watch -n.5 grep ctxt /proc/965/status
watch -n.5 grep ctxt /proc/966/status
watch -n.5 grep ctxt /proc/1222/status
watch -n.5 grep ctxt /proc/1223/status
watch -n.5 grep ctxt /proc/1248/status
What you will see in the command output is the number of voluntary vs involuntary context switches. Here is what that means.
A context switch is voluntary if the process or thread gives up the CPU because it has nothing else to do for example while it is waiting for something external to happen like an I-O interrupt from the audio device requesting more data. A context switch is involuntary if the process or task would like to continue doing work but the OS decides it's time to switch to some other process or thread.
In my example above the MPD process (961) has no CPU context switches shortly after music starts playing. The output:ALSA def thread (1248) will continuously context switch but all are voluntary which suggests its simply waiting for hardware interrupts from the audio device requesting more data, as opposed to being preempted by some other thread or giving up its CPU time slice.
You should see something like below for the output:ALSA def thread where voluntary_ctxt_switches constantly increases while nonvoluntary_ctxt_switches remains 0.
Every 0.5s: grep ctxt /proc/1248/status rp3: Fri Nov 9 20:44:32 2018
voluntary_ctxt_switches: 505754
nonvoluntary_ctxt_switches: 0
-Tim