From 61d95603409a5dfcc182ab871c6aa3d8ace051b3 Mon Sep 17 00:00:00 2001 From: rlibby Date: Thu, 16 May 2019 05:29:54 +0000 Subject: [PATCH] db show thread: avoid overflow in tick conversion The previous calculations for displaying the time since last switch easily overflowed, after less than 36 min for hz=1000. Now overflow takes 2000 times longer (as long as ticks takes to wrap). Reviewed by: cem, markj Sponsored by: Dell EMC Isilon Differential revision: https://reviews.freebsd.org/D20273 --- sys/ddb/db_ps.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c index 64f8075e8061..72bf0edd9161 100644 --- a/sys/ddb/db_ps.c +++ b/sys/ddb/db_ps.c @@ -338,8 +338,8 @@ DB_SHOW_COMMAND(thread, db_show_thread) { struct thread *td; struct lock_object *lock; + u_int delta; bool comma; - int delta; /* Determine which thread to examine. */ if (have_addr) @@ -421,14 +421,14 @@ DB_SHOW_COMMAND(thread, db_show_thread) 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); + delta = ticks - td->td_swvoltick; + db_printf(" last voluntary switch: %u.%03u s ago\n", + delta / hz, (delta % hz) * 1000 / 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); + delta = ticks - td->td_swinvoltick; + db_printf(" last involuntary switch: %u.%03u s ago\n", + delta / hz, (delta % hz) * 1000 / hz); } }