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
This commit is contained in:
Ryan Libby 2019-05-16 05:29:54 +00:00
parent 244081120e
commit 64e0efab39
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=347646

View File

@ -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);
}
}