Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Apr 2013 09:41:57 GMT
From:      Tiwei Bie <kis.twb@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/177706: DTrace sched:::off-cpu args[0] should point to newtd
Message-ID:  <201304080941.r389fvji058950@red.freebsd.org>
Resent-Message-ID: <201304080950.r389o0c4041894@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 08 09:50:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Tiwei Bie
>Release:        FreeBSD 9.1-RELEASE-p2
>Organization:
zzu(school)
>Environment:
FreeBSD thinkCentre 9.1-RELEASE-p2 FreeBSD 9.1-RELEASE-p2 #2 r+4b79fde-dirty: Mon Apr  8 14:02:34 CST 2013     btw@thinkCentre:/usr/obj/usr/src/sys/CUSTOM  amd64

>Description:
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.

[1] http://docs.oracle.com/cd/E18752_01/html/817-6223/gelro.html

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

dtrace:::BEGIN
{
        printf("%19s %19s  %19s %19s",
            "curthread", "curproc", "nextthread", "nextproc");
}

sched:::off-cpu 
{
        printf("%19s %19s  %19s %19s",
            curthread->td_name, curthread->td_proc->p_comm,
            args[0]->td_name, args[1]->p_comm);
}

>Fix:
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);
 #endif
-               SDT_PROBE2(sched, , , off_cpu, td, td->td_proc);
+               SDT_PROBE2(sched, , , off_cpu, newtd, newtd->td_proc);
                lock_profile_release_lock(&TDQ_LOCKPTR(tdq)->lock_object);
                TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd;
                sched_pctcpu_update(newtd->td_sched, 0);


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304080941.r389fvji058950>