Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 May 2018 08:12:25 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r333164 - stable/11/sys/x86/x86
Message-ID:  <201805020812.w428CPha089497@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed May  2 08:12:25 2018
New Revision: 333164
URL: https://svnweb.freebsd.org/changeset/base/333164

Log:
  MFC r332973:
  Make the sysctl machdep.idle also a tunable.

Modified:
  stable/11/sys/x86/x86/cpu_machdep.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/x86/x86/cpu_machdep.c
==============================================================================
--- stable/11/sys/x86/x86/cpu_machdep.c	Wed May  2 08:00:57 2018	(r333163)
+++ stable/11/sys/x86/x86/cpu_machdep.c	Wed May  2 08:12:25 2018	(r333164)
@@ -667,26 +667,12 @@ idle_sysctl_available(SYSCTL_HANDLER_ARGS)
 SYSCTL_PROC(_machdep, OID_AUTO, idle_available, CTLTYPE_STRING | CTLFLAG_RD,
     0, 0, idle_sysctl_available, "A", "list of available idle functions");
 
-static int
-idle_sysctl(SYSCTL_HANDLER_ARGS)
+static bool
+idle_selector(const char *new_idle_name)
 {
-	char buf[16];
-	int error;
-	char *p;
 	int i;
 
-	p = "unknown";
 	for (i = 0; idle_tbl[i].id_name != NULL; i++) {
-		if (idle_tbl[i].id_fn == cpu_idle_fn) {
-			p = idle_tbl[i].id_name;
-			break;
-		}
-	}
-	strncpy(buf, p, sizeof(buf));
-	error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
-	if (error != 0 || req->newptr == NULL)
-		return (error);
-	for (i = 0; idle_tbl[i].id_name != NULL; i++) {
 		if (strstr(idle_tbl[i].id_name, "mwait") &&
 		    (cpu_feature2 & CPUID2_MON) == 0)
 			continue;
@@ -695,16 +681,48 @@ idle_sysctl(SYSCTL_HANDLER_ARGS)
 		    cpu_idle_hook == NULL)
 			continue;
 #endif
-		if (strcmp(idle_tbl[i].id_name, buf))
+		if (strcmp(idle_tbl[i].id_name, new_idle_name))
 			continue;
 		cpu_idle_fn = idle_tbl[i].id_fn;
-		return (0);
+		if (bootverbose)
+			printf("CPU idle set to %s\n", idle_tbl[i].id_name);
+		return (true);
 	}
-	return (EINVAL);
+	return (false);
 }
 
+static int
+idle_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	char buf[16], *p;
+	int error, i;
+
+	p = "unknown";
+	for (i = 0; idle_tbl[i].id_name != NULL; i++) {
+		if (idle_tbl[i].id_fn == cpu_idle_fn) {
+			p = idle_tbl[i].id_name;
+			break;
+		}
+	}
+	strncpy(buf, p, sizeof(buf));
+	error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
+	if (error != 0 || req->newptr == NULL)
+		return (error);
+	return (idle_selector(buf) ? 0 : EINVAL);
+}
+
 SYSCTL_PROC(_machdep, OID_AUTO, idle, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
     idle_sysctl, "A", "currently selected idle function");
+
+static void
+idle_tun(void *unused __unused)
+{
+	char tunvar[16];
+
+	if (TUNABLE_STR_FETCH("machdep.idle", tunvar, sizeof(tunvar)))
+		idle_selector(tunvar);
+}
+SYSINIT(idle_tun, SI_SUB_CPU, SI_ORDER_MIDDLE, idle_tun, NULL);
 
 static int panic_on_nmi = 1;
 SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RWTUN,



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