From 434506223dec728c74ab601d4649861c8ca51e81 Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 8 Mar 2012 19:41:05 +0000 Subject: [PATCH 087/175] Add a new sched_clear_name() method to the scheduler interface to clear the cached name used for KTR_SCHED traces when a thread's name changes. This way KTR_SCHED traces (and thus schedgraph) will notice when a thread's name changes, most commonly via execve(). MFC after: 2 weeks git-svn-id: http://svn.freebsd.org/base/head@232700 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f (cherry picked from commit e5145622e05a6f70254b5580c935b40758bf7491) Signed-off-by: Xin Li --- sys/kern/kern_exec.c | 4 ++++ sys/kern/kern_intr.c | 3 +++ sys/kern/kern_kthread.c | 6 ++++++ sys/kern/kern_thr.c | 3 +++ sys/kern/sched_4bsd.c | 11 +++++++++++ sys/kern/sched_ule.c | 11 +++++++++++ sys/sys/sched.h | 3 +++ 7 files changed, 41 insertions(+) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 4545848..217b636 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -633,6 +634,9 @@ interpret: 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 diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c index b9ed881..08ff34b 100644 --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -180,6 +180,9 @@ ithread_update(struct intr_thread *ithd) /* Update name and priority. */ strlcpy(td->td_name, ie->ie_fullname, sizeof(td->td_name)); +#ifdef KTR + sched_clear_tdname(td); +#endif thread_lock(td); sched_prio(td, pri); thread_unlock(td); diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index bb12469..7d5a54e 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -114,6 +114,9 @@ kproc_create(void (*func)(void *), void *arg, va_start(ap, fmt); vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); va_end(ap); +#ifdef KTR + sched_clear_tdname(td); +#endif /* call the processes' main()... */ cpu_set_fork_handler(td, func, arg); @@ -446,6 +449,9 @@ kproc_kthread_add(void (*func)(void *), void *arg, 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); diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index e997e48..19762a9 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -550,6 +550,9 @@ sys_thr_set_name(struct thread *td, struct thr_set_name_args *uap) if (ttd == NULL) return (ESRCH); strcpy(ttd->td_name, name); +#ifdef KTR + sched_clear_tdname(ttd); +#endif PROC_UNLOCK(p); return (error); } diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 04fda5c..a249cd5 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -1613,6 +1613,17 @@ sched_tdname(struct thread *td) #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) { diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index c6b2d03..8bd2f96 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -2684,6 +2684,17 @@ sched_tdname(struct thread *td) #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 /* diff --git a/sys/sys/sched.h b/sys/sys/sched.h index 4380f78..4b8387c 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -138,6 +138,9 @@ int sched_sizeof_thread(void); * functions. */ char *sched_tdname(struct thread *td); +#ifdef KTR +void sched_clear_tdname(struct thread *td); +#endif static __inline void sched_pin(void) -- 1.7.9.4