Date: Fri, 25 Mar 2016 19:35:29 +0000 (UTC) From: "Conrad E. Meyer" <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297273 - in head/sys: ddb kern sys Message-ID: <201603251935.u2PJZTkK068531@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Fri Mar 25 19:35:29 2016 New Revision: 297273 URL: https://svnweb.freebsd.org/changeset/base/297273 Log: Add td_swinvoltick to track last involuntary context switch Expose in DDB via "show thread." Reviewed by: markj Sponsored by: EMC / Isilon Storage Division Modified: head/sys/ddb/db_ps.c head/sys/kern/kern_synch.c head/sys/sys/proc.h Modified: head/sys/ddb/db_ps.c ============================================================================== --- head/sys/ddb/db_ps.c Fri Mar 25 19:12:44 2016 (r297272) +++ head/sys/ddb/db_ps.c Fri Mar 25 19:35:29 2016 (r297273) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/cons.h> #include <sys/jail.h> #include <sys/kdb.h> +#include <sys/kernel.h> #include <sys/proc.h> #include <sys/sysent.h> #include <sys/systm.h> @@ -302,6 +303,7 @@ DB_SHOW_COMMAND(thread, db_show_thread) struct thread *td; struct lock_object *lock; bool comma; + int delta; /* Determine which thread to examine. */ if (have_addr) @@ -376,6 +378,16 @@ DB_SHOW_COMMAND(thread, db_show_thread) td->td_wchan); db_printf(" priority: %d\n", td->td_priority); db_printf(" container lock: %s (%p)\n", lock->lo_name, lock); + if (td->td_swvoltick != 0) { + delta = (u_int)ticks - (u_int)td->td_swvoltick; + db_printf(" last voluntary switch: %d ms ago\n", + 1000 * delta / hz); + } + if (td->td_swinvoltick != 0) { + delta = (u_int)ticks - (u_int)td->td_swinvoltick; + db_printf(" last involuntary switch: %d ms ago\n", + 1000 * delta / hz); + } } DB_SHOW_COMMAND(proc, db_show_proc) Modified: head/sys/kern/kern_synch.c ============================================================================== --- head/sys/kern/kern_synch.c Fri Mar 25 19:12:44 2016 (r297272) +++ head/sys/kern/kern_synch.c Fri Mar 25 19:35:29 2016 (r297273) @@ -438,8 +438,10 @@ mi_switch(int flags, struct thread *newt if (flags & SW_VOL) { td->td_ru.ru_nvcsw++; td->td_swvoltick = ticks; - } else + } else { td->td_ru.ru_nivcsw++; + td->td_swinvoltick = ticks; + } #ifdef SCHED_STATS SCHED_STAT_INC(sched_switch_stats[flags & SW_TYPE_MASK]); #endif Modified: head/sys/sys/proc.h ============================================================================== --- head/sys/sys/proc.h Fri Mar 25 19:12:44 2016 (r297272) +++ head/sys/sys/proc.h Fri Mar 25 19:35:29 2016 (r297273) @@ -254,6 +254,7 @@ struct thread { int td_slptick; /* (t) Time at sleep. */ int td_blktick; /* (t) Time spent blocked. */ int td_swvoltick; /* (t) Time at last SW_VOL switch. */ + int td_swinvoltick; /* (t) Time at last SW_INVOL switch. */ u_int td_cow; /* (*) Number of copy-on-write faults */ struct rusage td_ru; /* (t) rusage information. */ struct rusage_ext td_rux; /* (t) Internal rusage information. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603251935.u2PJZTkK068531>