Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: How can I trace the context switch event by Dtrace?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I trace the context switch event by Dtrace?

On Dec 4, 2007, at 3:18 AM, perfoptimization-dev- email@hidden wrote:


I want to trace the context switch event and log the id of the thread which is ending/starting the execution. I was required to use Dtrace to log the events so I read the manual doc ( ). The doc said I can use sched provider to fire various probes such as off-cpu and on-cpu. However, on Leopard (build 9A581) I cannot find sched provider.(I used 'sudo dtrace -l' but cannot find sched provider in the output.)

Correct. That deficiency in Leopard is covered by the venerable: <rdar://problem/4487709> dtrace needs a scheduler provider

Therefore, I tried some other probes. I assumed that all context switch events are caused by the kernel API thread_switch. If my assumption is correct, I can use the probe fbt:mach_kernel:thread_switch:entry to trace the context switch event. I would like to check whether my assumption is correct or not.

Incorrect. The mach_kernel:thread_switch: probe is placed on the mach trap that services explicit *user* requests to schedule among its threads. Context switch occurs at a deeper level in the kernel.

Are there any other options I can take?

I use the following in an internal tool. It is unsupported, subject to breakage at any kernel update, YMMV etc. --

       uint64_t        tstamp,
       timer_t         new_timer)

self->swout = (uint32_t)curthread;
* thread_timer_event() is always called with "&thread- >system_timer" passed as new_timer.
* This allows for the nasty hack below where the value of "thread" is recovered by
* subtracting the offset of the system_timer member.

/* uint64_t tstamp sits in arg0:arg1. timer_t new_timer is arg2! */
self->swin = ((uint32_t)arg2 - offsetof(struct thread, system_timer));

/self->swout != self->swin/
	printf("Out 0xx In 0xx\n", self->swout, self->swin);
	self->swin = 0;
	self->swout = 0;

Steve Peters

Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.