Is there any way to execute a block of code in C without suffering a Context Switch?
I have modified perf stat to sample the counters periodically. While this works, it ends up giving me some bad data points such as 0 cycles x instructions.
I believe that the reason for this happening is because of context switching.
Since my code always pulls cycle counter value before instruction counter, if a context switch were to happen after pulling the cycle counter value, and if the process I was profiling executed for some portion of the scheduling quanta, then when I finally pulled the instruction counter value, it would be 'one ahead' of the cycle counter value that I already pulled.
Is there any way to execute the code-block without allowing a context switch to take place?