I've been working on DTrace scripts to figure out exactly what's causing 
CPU wakeups and would like to get your opinion on this one.

Since idle-state-transition is fired by the scheduler, there's no way of 
associating the offender with the transition itself. That is, the thread 
that runs through idle-state is not the same that lead to the 
transition. So I've been working around the following script, which uses 
a global variable to pick up the next thread that goes online after the 
transition.

#!/usr/sbin/dtrace -s
#pragma D option quiet

int up, res;

sdt:::idle-state-transition
/arg0 != 0/
{
        self->start = timestamp;
}

sdt:::idle-state-transition
/arg0 == 0 && self->start/
{
        res = (timestamp - self->start);
        up = 1;
}

syscall:::entry
/up == 1 && pid != 0/
{
        printf("0 %d %d %d %d %d %s %s\n",
                cpu,
                pid,
                tid,
                timestamp,
                res,
                execname,
                probefunc);
        self->start = 0;
        up = 0;
        res = 0;
}


The problem is somewhat obvious. There's no guarantee that the next 
thread is the actual offender. It's very likely, but not guaranteed :(

Any thoughts?

thanks
Rafael

Reply via email to