Question

I am doing some analysis of a multi-threaded application using the Apple Instruments tools, which give a lot of information I'm trying to make sense out of. I am trying to find a good resource to describe the thread states which are color-coded in the tool. I've been looking into XNU Kernel documentation and books but without much luck.

There is a lot of yellow and purple which correspond to the "preempted" and "supervisor" modes (the full color chart is described in the upper right pop up in the attached image). Given I'm spending so much time in these states as opposed to the "running" state (in blue), I would be particularly interested in knowing what they refer to and whether it is possible/desirable to minimise the time spent in these states.

enter image description here

Was it helpful?

Solution

Preempted = Your thread was runnable, and was ready, willing and able to execute, but was kicked out (context switched) in favor of some other thread. This means that your thread wasn't sleeping on I/O or an event, and was actually doing something CPU-intensive. Due to either quantum expiration or some other thread of greater priority, however, it was forced out of the CPU.

Supervisor = Your thread was in kernel mode. USually, this means the kernel was servicing a system call made by your thread.

Neither of them is strictly bad, but:

Avoiding preemption: Not much you can do here, besides play with your priority - increase your priority using a negative nice value, or , directly, using the setpriority API. You can also use scheduling policies to boost your thread's preference, and cajole the Mach scheduler (the underlying decision maker of threads) to put your threads first, and give them more CPU time.

Avoiding supervisor mode: You might be heavy on the system calls. Again, this isn't necessarily a bad thing.

Hope this helps,

TG

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top