Date: Fri, 23 Dec 2011 15:20:00 -0500 From: John Baldwin <jhb@freebsd.org> To: arch@freebsd.org Subject: Teach KTR_SCHED to handle changing thread names Message-ID: <201112231520.00282.jhb@freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/pioctl.h> #include <sys/namei.h> #include <sys/resourcevar.h> +#include <sys/sched.h> #include <sys/sdt.h> #include <sys/sf_buf.h> #include <sys/syscallsubr.h> @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112231520.00282.jhb>