#1: does anyone know how to detect how many times (and/or the time length) a given thread has been context switched out of the CPU?
#2: are there any tchniques that minimize/eliminate your thread getting context switched?
I would be happy to know the answers to these questions for ANY operating system, not only real ones like solaris and linux, but even (pinch your noise) Windows.
Here is the little bit that I currently know:
#1:
Apparently Solaris records context switch counts; see this discussion:
JMX - Any way to detect thread context switches?
Unfortunately, I too am running a Java program, and so the issue mentioned in that posting about how to figure out the mapping between your Java thread ID and solaris's LWP ID remains for me too.
Is there any functionality in Linux or Windows to what is described in that discussion?
#2:
Well, you can do obvious things, such as run no other programs, disable as many daemons/services as possible.
Is there any other configuration that you can do? I have tried setting my java program's thread priority to max in the hope this would prevent it, but it doesn't seem too.
Is there some version of linux that you can run in which you can muck with the thread scheduler and alter its policies to minimize hot threads from be switched out? (I have a dual core CPU, so if my app's main thread fully occupies one core, the other core is still free to run stuff from the operating system, so I see no reason why my hot thread needs to ever be swapped out--or am I missing something?).
Or maybe a real time OS in which you specify that a thread has to run for a certain length of time completely unmolested?