From owner-freebsd-arch@FreeBSD.ORG Fri Dec 23 20:20:19 2011 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3676B10656B9 for ; Fri, 23 Dec 2011 20:20:01 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 9F4968FC0C for ; Fri, 23 Dec 2011 20:20:01 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 555F346B49 for ; Fri, 23 Dec 2011 15:20:01 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D8494B93F for ; Fri, 23 Dec 2011 15:20:00 -0500 (EST) To: arch@freebsd.org From: John Baldwin Date: Fri, 23 Dec 2011 15:20:00 -0500 MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201112231520.00282.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 23 Dec 2011 15:20:00 -0500 (EST) Cc: Subject: Teach KTR_SCHED to handle changing thread names X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2011 20:20:19 -0000 When I use the new schedgraph on 8, I find that it commonly calls almost all threads "sh" or "tcsh" because it only uses the name from the initial fork and never notices when a thread changes its name via exec. This makes traces harder to follow. The patch below adds a hook to clear the cached thread name to force it to be regenerated on the next trace when td_name changes. This makes the traces more usable for me at least. Index: kern/sched_ule.c =================================================================== --- kern/sched_ule.c (revision 225431) +++ kern/sched_ule.c (working copy) @@ -2685,6 +2685,17 @@ #endif } +#ifdef KTR +void +sched_clear_tdname(struct thread *td) +{ + struct td_sched *ts; + + ts = td->td_sched; + ts->ts_name[0] = '\0'; +} +#endif + #ifdef SMP /* Index: kern/kern_thr.c =================================================================== --- kern/kern_thr.c (revision 225431) +++ kern/kern_thr.c (working copy) @@ -532,9 +532,12 @@ ttd = td; else ttd = thread_find(p, uap->id); - if (ttd != NULL) + if (ttd != NULL) { strcpy(ttd->td_name, name); - else +#ifdef KTR + sched_clear_tdname(ttd); +#endif + } else error = ESRCH; PROC_UNLOCK(p); return (error); Index: kern/kern_kthread.c =================================================================== --- kern/kern_kthread.c (revision 225431) +++ kern/kern_kthread.c (working copy) @@ -407,6 +407,9 @@ va_start(ap, fmt); vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); va_end(ap); +#ifdef KTR + sched_clear_tdname(td); +#endif return (0); } va_start(ap, fmt); Index: kern/sched_4bsd.c =================================================================== --- kern/sched_4bsd.c (revision 225431) +++ kern/sched_4bsd.c (working copy) @@ -1611,7 +1611,18 @@ #endif } +#ifdef KTR void +sched_clear_tdname(struct thread *td) +{ + struct td_sched *ts; + + ts = td->td_sched; + ts->ts_name[0] = '\0'; +} +#endif + +void sched_affinity(struct thread *td) { #ifdef SMP Index: kern/kern_exec.c =================================================================== --- kern/kern_exec.c (revision 225431) +++ kern/kern_exec.c (working copy) @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -609,6 +610,9 @@ else if (vn_commname(binvp, p->p_comm, sizeof(p->p_comm)) != 0) bcopy(fexecv_proc_title, p->p_comm, sizeof(fexecv_proc_title)); bcopy(p->p_comm, td->td_name, sizeof(td->td_name)); +#ifdef KTR + sched_clear_tdname(td); +#endif /* * mark as execed, wakeup the process that vforked (if any) and tell Index: sys/sched.h =================================================================== --- sys/sched.h (revision 225431) +++ sys/sched.h (working copy) @@ -139,6 +139,9 @@ * functions. */ char *sched_tdname(struct thread *td); +#ifdef KTR +void sched_clear_tdname(struct thread *td); +#endif static __inline void sched_pin(void) -- John Baldwin