svn commit: r190339 - head/sys/dev/acpica

Jung-uk Kim jkim at FreeBSD.org
Mon Mar 23 15:06:11 PDT 2009


Author: jkim
Date: Mon Mar 23 22:06:09 2009
New Revision: 190339
URL: http://svn.freebsd.org/changeset/base/190339

Log:
  Check whether devd is running before calling resume notifier and
  reshuffle code to reduce unnecessary locking coverage.

Modified:
  head/sys/dev/acpica/acpi.c

Modified: head/sys/dev/acpica/acpi.c
==============================================================================
--- head/sys/dev/acpica/acpi.c	Mon Mar 23 21:32:03 2009	(r190338)
+++ head/sys/dev/acpica/acpi.c	Mon Mar 23 22:06:09 2009	(r190339)
@@ -2336,7 +2336,7 @@ acpi_ReqSleepState(struct acpi_softc *sc
 #endif
 
     /* If devd(8) is not running, immediately enter the sleep state. */
-    if (devctl_process_running() == FALSE) {
+    if (!devctl_process_running()) {
 	ACPI_UNLOCK(acpi);
 	if (ACPI_SUCCESS(acpi_EnterSleepState(sc, sc->acpi_next_sstate))) {
 	    return (0);
@@ -2345,9 +2345,6 @@ acpi_ReqSleepState(struct acpi_softc *sc
 	}
     }
 
-    /* Now notify devd(8) also. */
-    acpi_UserNotify("Suspend", ACPI_ROOT_OBJECT, state);
-
     /*
      * Set a timeout to fire if userland doesn't ack the suspend request
      * in time.  This way we still eventually go to sleep if we were
@@ -2357,6 +2354,10 @@ acpi_ReqSleepState(struct acpi_softc *sc
      */
     callout_reset(&sc->susp_force_to, 10 * hz, acpi_sleep_force, sc);
     ACPI_UNLOCK(acpi);
+
+    /* Now notify devd(8) also. */
+    acpi_UserNotify("Suspend", ACPI_ROOT_OBJECT, state);
+
     return (0);
 #else
     /* This platform does not support acpi suspend/resume. */
@@ -2432,8 +2433,24 @@ acpi_AckSleepState(struct apm_clone_data
 static void
 acpi_sleep_enable(void *arg)
 {
+    struct acpi_softc	*sc = (struct acpi_softc *)arg;
 
-    ((struct acpi_softc *)arg)->acpi_sleep_disabled = 0;
+    ACPI_LOCK(acpi);
+    sc->acpi_sleep_disabled = 0;
+    ACPI_UNLOCK(acpi);
+}
+
+static ACPI_STATUS
+acpi_sleep_disable(struct acpi_softc *sc)
+{
+    ACPI_STATUS		status;
+
+    ACPI_LOCK(acpi);
+    status = sc->acpi_sleep_disabled ? AE_ERROR : AE_OK;
+    sc->acpi_sleep_disabled = 1;
+    ACPI_UNLOCK(acpi);
+
+    return (status);
 }
 
 enum acpi_sleep_state {
@@ -2460,15 +2477,11 @@ acpi_EnterSleepState(struct acpi_softc *
     ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, state);
 
     /* Re-entry once we're suspending is not allowed. */
-    status = AE_OK;
-    ACPI_LOCK(acpi);
-    if (sc->acpi_sleep_disabled) {
-	ACPI_UNLOCK(acpi);
+    status = acpi_sleep_disable(sc);
+    if (ACPI_FAILURE(status)) {
 	printf("acpi: suspend request ignored (not ready yet)\n");
-	return (AE_ERROR);
+	return (status);
     }
-    sc->acpi_sleep_disabled = 1;
-    ACPI_UNLOCK(acpi);
 
 #ifdef SMP
     thread_lock(curthread);
@@ -2557,6 +2570,7 @@ acpi_EnterSleepState(struct acpi_softc *
 	 * shutdown handlers.
 	 */
 	shutdown_nice(RB_POWEROFF);
+	status = AE_OK;
 	break;
     case ACPI_STATE_S0:
     default:
@@ -2580,13 +2594,6 @@ acpi_EnterSleepState(struct acpi_softc *
     if (slp_state >= ACPI_SS_SLEPT)
 	acpi_enable_fixed_events(sc);
 
-    /* Allow another sleep request after a while. */
-    if (state != ACPI_STATE_S5)
-	timeout(acpi_sleep_enable, sc, hz * ACPI_MINIMUM_AWAKETIME);
-
-    /* Run /etc/rc.resume after we are back. */
-    acpi_UserNotify("Resume", ACPI_ROOT_OBJECT, state);
-
     mtx_unlock(&Giant);
 
     /* Warm up timecounter again */
@@ -2599,6 +2606,14 @@ acpi_EnterSleepState(struct acpi_softc *
     thread_unlock(curthread);
 #endif
 
+    /* Allow another sleep request after a while. */
+    if (state != ACPI_STATE_S5)
+	timeout(acpi_sleep_enable, sc, hz * ACPI_MINIMUM_AWAKETIME);
+
+    /* Run /etc/rc.resume after we are back. */
+    if (devctl_process_running())
+	acpi_UserNotify("Resume", ACPI_ROOT_OBJECT, state);
+
     return_ACPI_STATUS (status);
 }
 


More information about the svn-src-all mailing list