svn commit: r349029 - head/sys/kern

Alexander Motin mav at FreeBSD.org
Fri Jun 14 01:09:11 UTC 2019


Author: mav
Date: Fri Jun 14 01:09:10 2019
New Revision: 349029
URL: https://svnweb.freebsd.org/changeset/base/349029

Log:
  Update td_runtime of running thread on each statclock().
  
  Normally td_runtime is updated on context switch, but there are some kernel
  threads that due to high absolute priority may run for many seconds without
  context switches (yes, that is bad, but that is true), which means their
  td_runtime was not updated all that time, that made them invisible for top
  other then as some general CPU usage.
  
  MFC after:	1 week
  Sponsored by:	iXsystems, Inc.

Modified:
  head/sys/kern/kern_clock.c

Modified: head/sys/kern/kern_clock.c
==============================================================================
--- head/sys/kern/kern_clock.c	Fri Jun 14 00:30:52 2019	(r349028)
+++ head/sys/kern/kern_clock.c	Fri Jun 14 01:09:10 2019	(r349029)
@@ -644,6 +644,7 @@ statclock(int cnt, int usermode)
 	struct proc *p;
 	long rss;
 	long *cp_time;
+	uint64_t runtime, new_switchtime;
 
 	td = curthread;
 	p = td->td_proc;
@@ -699,6 +700,17 @@ statclock(int cnt, int usermode)
 	    "prio:%d", td->td_priority, "stathz:%d", (stathz)?stathz:hz);
 	SDT_PROBE2(sched, , , tick, td, td->td_proc);
 	thread_lock_flags(td, MTX_QUIET);
+
+	/*
+	 * Compute the amount of time during which the current
+	 * thread was running, and add that to its total so far.
+	 */
+	new_switchtime = cpu_ticks();
+	runtime = new_switchtime - PCPU_GET(switchtime);
+	td->td_runtime += runtime;
+	td->td_incruntime += runtime;
+	PCPU_SET(switchtime, new_switchtime);
+
 	for ( ; cnt > 0; cnt--)
 		sched_clock(td);
 	thread_unlock(td);


More information about the svn-src-head mailing list