0

vmstat provides a counter cs for context switch. As this explains, the context switch can be from one process to another , kernel to user or due to a interrupt being fired. Does the cs give a total of this?If so, is there a way I can get an individual output

doon
  • 119
  • 2
  • 6

3 Answers3

1

Vmstat cs column is displaying, at least on Solaris, voluntary context switches, i.e. those happening when a process (thread really) is releasing the CPU because it has nothing else to do with it, for example waiting for some external event like a pending I/O to finish.

If you want to display involuntary context switches, you can use the mpstat command an look at its icsw column. Here are displayed context switches due to a process being interrupted/preempted because something with a bigger priority requires the CPU.

jlliagre
  • 8,861
  • 18
  • 36
1

I think it may be OS-dependent. On AIX 6.1 you have (http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/vmstat_command.htm):

"(cs is) Number of context switches per second observed in the interval. The physical CPU resource is subdivided into logical time slices of 10 milliseconds each. Assuming a thread is scheduled for execution, it will run until its time slice expires, until it is preempted, or until it voluntarily gives up control of the CPU. When another thread is given control of the CPU, the context or working environment of the previous thread must be saved and the context of the current thread must be loaded. The operating system has a very efficient context switching procedure, so each switch is inexpensive in terms of resources. Any significant increase in context switches, such as when cs is a lot higher than the disk I/O and network packet rate, should be cause for further investigation."

If you have sources of the vmstat on your system you may look inside and try to find out what it does.

Paweł Brodacki
  • 6,511
  • 20
  • 23
0

For Linux, on kernels 2.6.23 and later you can get voluntary and involuntary context switches broken down by process with the command

pidstat -w

justincc
  • 1
  • 2