There are plenty of programs available which can be used to calculate context switch time from user-space. But all of these have several overhead - like overhead of clock_gettime() timer, overhead of read/write operation in pipe.
Is it possible to measure context switch time in Linux kernel space where above overhead won't be there?
May be TWO GLOABL VARIABLES can be added in kernel module which will store the time when context_switch function is called , the time when context_switch is finished.
The challenges I am facing with this approach is context switch function can be called by any process and from any core.
Is it feasible or advisable to add something to struct task_struct or struct rq ?
I am using Ubuntu 16.04 OS .
getpid(or similarly trivial system call) -- switching from user mode to kernel mode and back? Handling a trivial interrupt and returning to user mode? Switching between 2 different processes on the same core? How about 2 different threads of the same process? It's difficult to measure these in part because there are so many initial and subsequent contexts to which one might switch, and hence many different attributes which might be affected by the switch, all of which have effects on the measured time. - Gil Hamiltonsched_setaffinity), then use the x86 timestamp counter (assemblyRDTSCinstruction) to measure elapsed time. That has very little overhead. But then of course you'll need to scale that according to the CPU clock speed to turn it in seconds. - Gil Hamilton