Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Jul 2019 18:38:41 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r349819 - stable/12/sys/kern
Message-ID:  <201907071838.x67IcfOw069840@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Jul  7 18:38:40 2019
New Revision: 349819
URL: https://svnweb.freebsd.org/changeset/base/349819

Log:
  MFC r349029: 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.

Modified:
  stable/12/sys/kern/kern_clock.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/kern_clock.c
==============================================================================
--- stable/12/sys/kern/kern_clock.c	Sun Jul  7 18:37:46 2019	(r349818)
+++ stable/12/sys/kern/kern_clock.c	Sun Jul  7 18:38:40 2019	(r349819)
@@ -631,6 +631,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;
@@ -686,6 +687,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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907071838.x67IcfOw069840>