kern/177706: DTrace sched:::off-cpu args[0] should point to newtd

Tiwei Bie kis.twb at
Mon Apr 8 09:50:00 UTC 2013

>Number:         177706
>Category:       kern
>Synopsis:       DTrace sched:::off-cpu args[0] should point to newtd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 08 09:50:00 UTC 2013
>Originator:     Tiwei Bie
>Release:        FreeBSD 9.1-RELEASE-p2
FreeBSD thinkCentre 9.1-RELEASE-p2 FreeBSD 9.1-RELEASE-p2 #2 r+4b79fde-dirty: Mon Apr  8 14:02:34 CST 2013     btw at thinkCentre:/usr/obj/usr/src/sys/CUSTOM  amd64

According to Solaris Dynamic Tracing Guide[1], in off-cpu, args[0] should point to the lwpsinfo_t (in FreeBSD, it is struct thread) structure of the thread that the current CPU will next execute. But in the current implementation (including -CURRENT), args[0] points to the thread that is ending execution.


Using the following scripts can repeat the problem:
#!/usr/sbin/dtrace -s                       

        printf("%19s %19s  %19s %19s",
            "curthread", "curproc", "nextthread", "nextproc");

        printf("%19s %19s  %19s %19s",
            curthread->td_name, curthread->td_proc->p_comm,
            args[0]->td_name, args[1]->p_comm);

Just something like this:

--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -1903,7 +1903,7 @@ sched_switch(struct thread *td, struct thread *newtd, int
                if (PMC_PROC_IS_USING_PMCS(td->td_proc))
                        PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_OUT);
-               SDT_PROBE2(sched, , , off_cpu, td, td->td_proc);
+               SDT_PROBE2(sched, , , off_cpu, newtd, newtd->td_proc);
                TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd;
                sched_pctcpu_update(newtd->td_sched, 0);


More information about the freebsd-bugs mailing list