From owner-svn-src-all@freebsd.org Tue Apr 24 20:49:17 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 769A1FB2E36; Tue, 24 Apr 2018 20:49:17 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2A95F72287; Tue, 24 Apr 2018 20:49:17 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 25709182E1; Tue, 24 Apr 2018 20:49:17 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3OKnHYc039931; Tue, 24 Apr 2018 20:49:17 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3OKnHE7039930; Tue, 24 Apr 2018 20:49:17 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201804242049.w3OKnHE7039930@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 24 Apr 2018 20:49:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332973 - head/sys/x86/x86 X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/x86/x86 X-SVN-Commit-Revision: 332973 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2018 20:49:17 -0000 Author: kib Date: Tue Apr 24 20:49:16 2018 New Revision: 332973 URL: https://svnweb.freebsd.org/changeset/base/332973 Log: Make the sysctl machdep.idle also a tunable. It is applied before it is possible for idle threads to execute on any CPU, allowing to work around against some bugs. Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/x86/x86/cpu_machdep.c Modified: head/sys/x86/x86/cpu_machdep.c ============================================================================== --- head/sys/x86/x86/cpu_machdep.c Tue Apr 24 20:33:08 2018 (r332972) +++ head/sys/x86/x86/cpu_machdep.c Tue Apr 24 20:49:16 2018 (r332973) @@ -636,13 +636,33 @@ 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 bool +idle_selector(const char *new_idle_name) +{ + int i; + + for (i = 0; idle_tbl[i].id_name != NULL; i++) { + if (strstr(idle_tbl[i].id_name, "mwait") && + (cpu_feature2 & CPUID2_MON) == 0) + continue; + if (strcmp(idle_tbl[i].id_name, "acpi") == 0 && + cpu_idle_hook == NULL) + continue; + if (strcmp(idle_tbl[i].id_name, new_idle_name)) + continue; + cpu_idle_fn = idle_tbl[i].id_fn; + if (bootverbose) + printf("CPU idle set to %s\n", idle_tbl[i].id_name); + return (true); + } + return (false); +} + static int idle_sysctl(SYSCTL_HANDLER_ARGS) { - char buf[16]; - int error; - char *p; - int i; + char buf[16], *p; + int error, i; p = "unknown"; for (i = 0; idle_tbl[i].id_name != NULL; i++) { @@ -655,23 +675,21 @@ idle_sysctl(SYSCTL_HANDLER_ARGS) 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; - if (strcmp(idle_tbl[i].id_name, "acpi") == 0 && - cpu_idle_hook == NULL) - continue; - if (strcmp(idle_tbl[i].id_name, buf)) - continue; - cpu_idle_fn = idle_tbl[i].id_fn; - return (0); - } - return (EINVAL); + 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,