From nobody@FreeBSD.org  Mon Apr  8 09:41:58 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 55484B93
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Apr 2013 09:41:58 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 2BD3BEA4
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Apr 2013 09:41:58 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r389fvpM058958
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 8 Apr 2013 09:41:57 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r389fvji058950;
	Mon, 8 Apr 2013 09:41:57 GMT
	(envelope-from nobody)
Message-Id: <201304080941.r389fvji058950@red.freebsd.org>
Date: Mon, 8 Apr 2013 09:41:57 GMT
From: Tiwei Bie <kis.twb@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: DTrace sched:::off-cpu args[0] should point to newtd
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177706
>Category:       kern
>Synopsis:       [dtrace] [patch] DTrace sched:::off-cpu args[0] should point to newtd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnn
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 08 09:50:00 UTC 2013
>Closed-Date:    Mon Feb 17 05:09:51 UTC 2014
>Last-Modified:  Mon Feb 17 05:09:51 UTC 2014
>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:
Responsible-Changed-From-To: freebsd-bugs->gnn 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Apr 8 16:39:28 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177706 
State-Changed-From-To: open->patched 
State-Changed-By: gnn 
State-Changed-When: Mon Apr 15 17:17:44 UTC 2013 
State-Changed-Why:  
This has been committed to HEAD for sched_ule.c only. 

Committed revision 249514. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177706 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177706: commit references a PR
Date: Mon, 15 Apr 2013 17:21:28 +0000 (UTC)

 Author: gnn
 Date: Mon Apr 15 17:21:02 2013
 New Revision: 249514
 URL: http://svnweb.freebsd.org/changeset/base/249514
 
 Log:
   Point args[0] not at the thread that is ending but at the one that
   is starting.  This is in line with practice in OpenSolaris.
   
   Note that this change is only in ULE and not in the 4BSD scheduler.
   Once this change settles in (MFC timeout has expired) we'll try it out
   on 4BSD as well.
   
   PR:		177706
   Submitted by:	Tiwei Bie
   MFC after:	1 month
 
 Modified:
   head/sys/kern/sched_ule.c
 
 Modified: head/sys/kern/sched_ule.c
 ==============================================================================
 --- head/sys/kern/sched_ule.c	Mon Apr 15 17:20:44 2013	(r249513)
 +++ head/sys/kern/sched_ule.c	Mon Apr 15 17:21:02 2013	(r249514)
 @@ -1930,7 +1930,7 @@ sched_switch(struct thread *td, struct t
  		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);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177706: commit references a PR
Date: Fri, 21 Jun 2013 21:39:06 +0000 (UTC)

 Author: gnn
 Date: Fri Jun 21 21:38:48 2013
 New Revision: 252070
 URL: http://svnweb.freebsd.org/changeset/base/252070
 
 Log:
   MFC: 249514
   Point args[0] not at the thread that is ending but at the one that
   is starting.  This is in line with practice in OpenSolaris.
   
   Note that this change is only in ULE and not in the 4BSD scheduler.
   Once this change settles in (MFC timeout has expired) we'll try it out
   on 4BSD as well.
   
   PR:		177706
   Submitted by:	Tiwei Bie
 
 Modified:
   stable/9/sys/kern/sched_ule.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/kern/sched_ule.c
 ==============================================================================
 --- stable/9/sys/kern/sched_ule.c	Fri Jun 21 20:21:14 2013	(r252069)
 +++ stable/9/sys/kern/sched_ule.c	Fri Jun 21 21:38:48 2013	(r252070)
 @@ -1896,7 +1896,7 @@ sched_switch(struct thread *td, struct t
  		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);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177706: commit references a PR
Date: Sun, 29 Dec 2013 17:08:37 +0000 (UTC)

 Author: markj
 Date: Sun Dec 29 17:08:30 2013
 New Revision: 260043
 URL: http://svnweb.freebsd.org/changeset/base/260043
 
 Log:
   The arguments to sched:::off-cpu are the thread and associated process of
   the thread selected to run, not the currently running thread. This fix has
   already been made for ULE in r252070.
   
   PR:		177706
   MFC after:	1 week
 
 Modified:
   head/sys/kern/sched_4bsd.c
 
 Modified: head/sys/kern/sched_4bsd.c
 ==============================================================================
 --- head/sys/kern/sched_4bsd.c	Sun Dec 29 17:03:45 2013	(r260042)
 +++ head/sys/kern/sched_4bsd.c	Sun Dec 29 17:08:30 2013	(r260043)
 @@ -1032,7 +1032,7 @@ sched_switch(struct thread *td, struct t
  			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);
  
                  /* I feel sleepy */
  		lock_profile_release_lock(&sched_lock.lock_object);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: markj 
State-Changed-When: Mon Feb 17 05:09:50 UTC 2014 
State-Changed-Why:  
This has been fixed in 4BSD and ULE on stable/8, 9 and 10. Thanks for 
the report! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177706 
>Unformatted:
