diff options
author | Ryan Libby <rlibby@FreeBSD.org> | 2019-05-16 05:29:54 +0000 |
---|---|---|
committer | Ryan Libby <rlibby@FreeBSD.org> | 2019-05-16 05:29:54 +0000 |
commit | 64e0efab390f7af3fc6827ac682095fccef06a8a (patch) | |
tree | f289dd08cb9c7321f853c526a1729319b1c56960 /sys/ddb | |
parent | 244081120ede261361f06d736ae7392b1e2e8e9e (diff) | |
download | src-64e0efab390f7af3fc6827ac682095fccef06a8a.tar.gz src-64e0efab390f7af3fc6827ac682095fccef06a8a.zip |
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
Notes
Notes:
svn path=/head/; revision=347646
Diffstat (limited to 'sys/ddb')
-rw-r--r-- | sys/ddb/db_ps.c | 14 |
1 files 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); } } |