Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Aug 2015 20:50:21 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r286701 - in head: share/man/man4 sys/kern
Message-ID:  <201508122050.t7CKoLl6026678@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Wed Aug 12 20:50:20 2015
New Revision: 286701
URL: https://svnweb.freebsd.org/changeset/base/286701

Log:
  If a specific timecounter has been chosen via sysctl, and a new timecounter
  with higher quality registers (presumably in a module that has just been
  loaded), do not undo the user's choice by switching to the new timecounter.
  
  Document that behavior, and also the fact that there is no way to unregister
  a timecounter (and thus no way to unload a module containing one).

Modified:
  head/share/man/man4/timecounters.4
  head/sys/kern/kern_tc.c

Modified: head/share/man/man4/timecounters.4
==============================================================================
--- head/share/man/man4/timecounters.4	Wed Aug 12 20:21:04 2015	(r286700)
+++ head/share/man/man4/timecounters.4	Wed Aug 12 20:50:20 2015	(r286701)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 12, 2014
+.Dd August 12, 2015
 .Dt TIMECOUNTERS 4
 .Os
 .Sh NAME
@@ -96,10 +96,16 @@ compared to others.
 A negative value means this time counter is broken and should not be used.
 .El
 .Pp
-The time management code of the kernel chooses one time counter from that list.
-The current choice can be read and affected via the
+The time management code of the kernel automatically switches to a
+higher-quality time counter when it registers, unless the
 .Va kern.timecounter.hardware
-tunable/sysctl.
+sysctl has been used to choose a specific device.
+.Pp
+There is no way to unregister a time counter once it has registered
+with the kernel.
+If a dynamically loaded module contains a time counter you will not
+be able to unload that module, even if the time counter it contains
+is not the one currently in use.
 .Sh SEE ALSO
 .Xr attimer 4 ,
 .Xr eventtimers 4 ,

Modified: head/sys/kern/kern_tc.c
==============================================================================
--- head/sys/kern/kern_tc.c	Wed Aug 12 20:21:04 2015	(r286700)
+++ head/sys/kern/kern_tc.c	Wed Aug 12 20:50:20 2015	(r286701)
@@ -133,6 +133,8 @@ SYSCTL_PROC(_kern_timecounter, OID_AUTO,
     sysctl_kern_timecounter_adjprecision, "I",
     "Allowed time interval deviation in percents");
 
+static int tc_chosen;	/* Non-zero if a specific tc was chosen via sysctl. */
+
 static void tc_windup(void);
 static void cpu_tick_calibrate(int);
 
@@ -1197,10 +1199,13 @@ tc_init(struct timecounter *tc)
 	    "quality", CTLFLAG_RD, &(tc->tc_quality), 0,
 	    "goodness of time counter");
 	/*
-	 * Never automatically use a timecounter with negative quality.
+	 * Do not automatically switch if the current tc was specifically
+	 * chosen.  Never automatically use a timecounter with negative quality.
 	 * Even though we run on the dummy counter, switching here may be
-	 * worse since this timecounter may not be monotonous.
+	 * worse since this timecounter may not be monotonic.
 	 */
+	if (tc_chosen)
+		return;
 	if (tc->tc_quality < 0)
 		return;
 	if (tc->tc_quality < timecounter->tc_quality)
@@ -1433,9 +1438,12 @@ sysctl_kern_timecounter_hardware(SYSCTL_
 	strlcpy(newname, tc->tc_name, sizeof(newname));
 
 	error = sysctl_handle_string(oidp, &newname[0], sizeof(newname), req);
-	if (error != 0 || req->newptr == NULL ||
-	    strcmp(newname, tc->tc_name) == 0)
+	if (error != 0 || req->newptr == NULL)
 		return (error);
+	/* Record that the tc in use now was specifically chosen. */
+	tc_chosen = 1;
+	if (strcmp(newname, tc->tc_name) == 0)
+		return (0);
 	for (newtc = timecounters; newtc != NULL; newtc = newtc->tc_next) {
 		if (strcmp(newname, newtc->tc_name) != 0)
 			continue;
@@ -1464,7 +1472,7 @@ SYSCTL_PROC(_kern_timecounter, OID_AUTO,
     "Timecounter hardware selected");
 
 
-/* Report or change the active timecounter hardware. */
+/* Report the available timecounter hardware. */
 static int
 sysctl_kern_timecounter_choice(SYSCTL_HANDLER_ARGS)
 {



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