From owner-freebsd-acpi@freebsd.org Tue Sep 22 19:13:40 2015 Return-Path: Delivered-To: freebsd-acpi@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 526BCA07696 for ; Tue, 22 Sep 2015 19:13:40 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2001:1900:2254:206a::19:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx2.freebsd.org", Issuer "Gandi Standard SSL CA 2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3E7651230; Tue, 22 Sep 2015 19:13:40 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from hammer.pct.niksun.com (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx2.freebsd.org (Postfix) with ESMTP id CA782693F1; Tue, 22 Sep 2015 19:13:39 +0000 (UTC) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim Subject: Re: disabling sleep when shutting down To: Colin Percival , Anthony Jenkins , "freebsd-acpi@freebsd.org" References: <55FA3848.7090802@freebsd.org> <55FB233D.2080000@FreeBSD.org> <55FB48E3.20401@freebsd.org> <55FC4F13.3090603@FreeBSD.org> <55FC57F9.3050702@yahoo.com> <55FE5D54.1030806@freebsd.org> Message-ID: <5601A863.5070406@FreeBSD.org> Date: Tue, 22 Sep 2015 15:13:39 -0400 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55FE5D54.1030806@freebsd.org> Content-Type: multipart/mixed; boundary="------------000903080601040909000901" X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Sep 2015 19:13:40 -0000 This is a multi-part message in MIME format. --------------000903080601040909000901 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 > On 09/20/2015 03:16, Colin Percival wrote: >> On 09/18/15 11:29, Anthony Jenkins wrote: >>> Is it possible for /etc/rc.shutdown to complete, but shutdown >>> not occur? If so, there should be a mechanism to restore the >>> ability to suspend. Other than that, I like it. >> >> Hmm... well, rc.shutdown runs before the system drops into >> single-user mode. Which makes me think that maybe we should be >> making the kernel call from inside init instead of from >> rc.shutdown. > > I didn't want to pollute init with arch-dependent hacks. Anyway, > the attached patch should do what you want (not tested). Or a simpler hack with sysctl(3) instead of ioctl(2). Jung-uk Kim -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJWAag9AAoJEHyflib82/FGkmQH/2LM7+pCPkvCq4ljV3UMlLbc YhvVZYr2k/j6CwjknMC0e4trF9Owgwxstnt+T8HDiGuIO553zUFPDTfgKTredv2x UHn48KgyBupnmanT1rBmQs9zg1+yVsmUGl4YgNHTaSjDz6qEB9+Jc+OTMssqBYcP 3DujmU2HWD3XDm9M5hCxyAuzh6anolb/Ev2FePezz81D7atJJoc+yF34tm3Y/Fjh KSybphHzib78qzLsXhz3Tf1LKbdZVBHFobkCTOUovB9bM5YPCT7/8HXSa/TBbvEV 1HLnj9GJX1x5WZIu4ACcsUkmJ2YT/JIwTUcZemw0BvG0usSkZL/G1fdybfgctxk= =qmkC -----END PGP SIGNATURE----- --------------000903080601040909000901 Content-Type: text/x-patch; name="init.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="init.diff" Index: sbin/init/init.c =================================================================== --- sbin/init/init.c (revision 288123) +++ sbin/init/init.c (working copy) @@ -1487,7 +1487,18 @@ static state_func_t death(void) { session_t *sp; +#if defined(__amd64__) || defined(__i386__) + size_t len; + int block, blocked; + /* Temporarily block any suspend requests. */ + len = sizeof(blocked); + block = 1; + if (sysctlbyname("debug.acpi.sleep_blocked", &blocked, &len, + &block, sizeof(block)) == -1) + blocked = 0; +#endif + /* * Also revoke the TTY here. Because runshutdown() may reopen * the TTY whose getty we're killing here, there is no guarantee @@ -1503,6 +1514,13 @@ death(void) /* Try to run the rc.shutdown script within a period of time */ runshutdown(); +#if defined(__amd64__) || defined(__i386__) + /* Unblock suspend requests. */ + if (!blocked) + sysctlbyname("debug.acpi.sleep_blocked", NULL, NULL, + &blocked, sizeof(blocked)); +#endif + return (state_func_t) death_single; } Index: sys/dev/acpica/acpi.c =================================================================== --- sys/dev/acpica/acpi.c (revision 288123) +++ sys/dev/acpica/acpi.c (working copy) @@ -292,6 +292,11 @@ static int acpi_susp_bounce; SYSCTL_INT(_debug_acpi, OID_AUTO, suspend_bounce, CTLFLAG_RW, &acpi_susp_bounce, 0, "Don't actually suspend, just test devices."); +/* Block suspend requests. */ +static int acpi_sleep_blocked; +SYSCTL_INT(_debug_acpi, OID_AUTO, sleep_blocked, CTLFLAG_RW, + &acpi_sleep_blocked, 0, "Ignore any sleep requests."); + /* * ACPI can only be loaded as a module by the loader; activating it after * system bootstrap time is not useful, and can be fatal to the system. @@ -2574,10 +2579,12 @@ acpi_ReqSleepState(struct acpi_softc *sc, int stat if (!acpi_sleep_states[state]) return (EOPNOTSUPP); - /* If a suspend request is already in progress, just return. */ - if (sc->acpi_next_sstate != 0) { + /* + * If a reboot/shutdown/suspend request is already in progress + * or suspend is explicitly disabled, just return. + */ + if (rebooting || sc->acpi_next_sstate != 0 || acpi_sleep_blocked) return (0); - } /* Wait until sleep is enabled. */ while (sc->acpi_sleep_disabled) { --------------000903080601040909000901--