svn commit: r347646 - head/sys/ddb

Ryan Libby rlibby at FreeBSD.org
Thu May 16 05:29:56 UTC 2019


Author: rlibby
Date: Thu May 16 05:29:54 2019
New Revision: 347646
URL: https://svnweb.freebsd.org/changeset/base/347646

Log:
  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

Modified:
  head/sys/ddb/db_ps.c

Modified: head/sys/ddb/db_ps.c
==============================================================================
--- head/sys/ddb/db_ps.c	Thu May 16 04:24:08 2019	(r347645)
+++ head/sys/ddb/db_ps.c	Thu May 16 05:29:54 2019	(r347646)
@@ -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);
 	}
 }
 


More information about the svn-src-head mailing list