Skip to contentSkip to conversation

ACPI / ACPICA: Avoid executing _PRW twice for all devices

PATCH Superseded Rafael J. Wysocki 2 participants 11 messages Jul 4, 2010 – Jul 7, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ACPI / ACPICA: Avoid executing _PRW twice for all devices

Hi,

Following our recent IRC discussion I thought I'd bite the bullet and prepare a patch to remove the execution of _PRW from ACPICA and there it goes.

The series is on top of the patch I sent a couple of days ago:
https://patchwork.kernel.org/patch/110076/

[1/3] - Drops the code to walk the namespace in search of _PRW and adds
acpi_gpe_can_wake() so that the host OS can disable wakeup GPEs previously enabled unconditionally by the ACPICA initialization code. This basically reproduces the current behavior except that the GPEs are temporarily enabled before acpi_bus_extract_wakeup_device_power_package() runs for all devices with _PRW referring to them.

[2/3] - Simplifies code in acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.

[3/3] - Changes acpi_gpe_wakeup() to return error code for the GPEs whose
ACPI_GPE_CAN_WAKE flags are not set.

Please apply.

Rafael

#1 lore raw

PATCH 1/3 ACPI / ACPICA: Do not execute _PRW methods during initialization

From: Rafael J. Wysocki <[email protected]>

Currently, during initialization ACPICA walks the entire ACPI namespace in search of any device objects with associated _PRW methods. All of the _PRW methods found are executed in the process to extract the GPE information returned by them, so that the GPEs in question can be marked as "able to wakeup" (more precisely, the ACPI_GPE_CAN_WAKE flag is set for them). The only purpose of this exercise is to avoid enabling the CAN_WAKE GPEs automatically, even if there are _Lxx/_Exx methods associated with them. However, it is both costly and unnecessary, because the host OS has to execute the _PRW methods anyway to check which devices can wake up the system from sleep states. Moreover, it then uses full information returned by _PRW, including the GPE information, so it can take care of disabling the GPEs if necessary.

Remove the code that walks the namespace and executes _PRW from ACPICA and modify comments to reflect that change. Make acpi_bus_set_run_wake_flags() disable GPEs for wakeup devices so that they don't cause spurious wakeup events to be signaled. This not only reduces the complexity of the ACPICA initialization code, but in some cases it should reduce the kernel boot time as well.

Unfortunately, for this purpose we need a new ACPICA function, acpi_gpe_can_wake(), to be called by the host OS in order to disable the GPEs that can wake up the system and were previously enabled by acpi_ev_initialize_gpe_block() or acpi_ev_update_gpes() (such a GPE should be disabled only once, because the initialization code enables it only once, but it may be pointed to by _PRW for multiple devices and that's why the additional function is necessary).

---
 drivers/acpi/acpica/acglobal.h  |    7 -
 drivers/acpi/acpica/evevent.c   |    5 
 drivers/acpi/acpica/evgpeblk.c  |   47 --------
 drivers/acpi/acpica/evgpeinit.c |  235 ++--------------------------------------
 drivers/acpi/acpica/evxfevnt.c  |   55 +++++++++
 drivers/acpi/acpica/exconfig.c  |    2 
 drivers/acpi/acpica/utxface.c   |    8 -
 drivers/acpi/osl.c              |   20 ---
 drivers/acpi/scan.c             |    2 
 include/acpi/acpixf.h           |    3 
 10 files changed, 85 insertions(+), 299 deletions(-)
drivers/acpi/scan.c +2 -0
Index: linux-2.6/drivers/acpi/scan.c
===================================================================
@@ -740,6 +740,8 @@ acpi_bus_extract_wakeup_device_power_pac
 		device->wakeup.resources.handles[i] = element->reference.handle;
 	}
 
+	acpi_gpe_can_wake(device->wakeup.gpe_device, device->wakeup.gpe_number);
+
 	return AE_OK;
 }
 
drivers/acpi/acpica/evgpeinit.c +17 -218

280 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +5 -42

73 lines not on this page · raw message

drivers/acpi/acpica/evxfevnt.c +54 -1

67 lines not on this page · raw message

drivers/acpi/acpica/utxface.c +2 -6
Index: linux-2.6/drivers/acpi/acpica/utxface.c
===================================================================
@@ -293,12 +293,8 @@ acpi_status acpi_initialize_objects(u32 
 	 * Complete the GPE initialization for the GPE blocks defined in the FADT
 	 * (GPE block 0 and 1).
 	 *
-	 * Note1: This is where the _PRW methods are executed for the GPEs. These
-	 * methods can only be executed after the SCI and Global Lock handlers are
-	 * installed and initialized.
-	 *
-	 * Note2: Currently, there seems to be no need to run the _REG methods
-	 * before execution of the _PRW methods and enabling of the GPEs.
+	 * NOTE: Currently, there seems to be no need to run the _REG methods
+	 * before enabling the GPEs.
 	 */
 	if (!(flags & ACPI_NO_EVENT_INIT)) {
 		status = acpi_ev_install_fadt_gpes();
drivers/acpi/acpica/evevent.c +2 -3
Index: linux-2.6/drivers/acpi/acpica/evevent.c
===================================================================
@@ -102,9 +102,8 @@ acpi_status acpi_ev_initialize_events(vo
  * RETURN:      Status
  *
  * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks
- *              (0 and 1). This causes the _PRW methods to be run, so the HW
- *              must be fully initialized at this point, including global lock
- *              support.
+ *              (0 and 1). The HW must be fully initialized at this point,
+ *              including global lock support.
  *
  ******************************************************************************/
 
drivers/acpi/acpica/exconfig.c +1 -1
Index: linux-2.6/drivers/acpi/acpica/exconfig.c
===================================================================
@@ -120,7 +120,7 @@ acpi_ex_add_table(u32 table_index,
 	acpi_ns_exec_module_code_list();
 	acpi_ex_enter_interpreter();
 
-	/* Update GPEs for any new _PRW or _Lxx/_Exx methods. Ignore errors */
+	/* Update GPEs for any new _Lxx/_Exx methods. Ignore errors */
 
 	status = acpi_tb_get_owner_id(table_index, &owner_id);
 	if (ACPI_SUCCESS(status)) {
include/acpi/acpixf.h +2 -1
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -63,7 +63,6 @@ extern u32 acpi_dbg_layer;
 extern u8 acpi_gbl_enable_interpreter_slack;
 extern u8 acpi_gbl_all_methods_serialized;
 extern u8 acpi_gbl_create_osi_method;
-extern u8 acpi_gbl_leave_wake_gpes_disabled;
 extern u8 acpi_gbl_use_default_register_widths;
 extern acpi_name acpi_gbl_trace_method_name;
 extern u32 acpi_gbl_trace_flags;
@@ -288,6 +287,8 @@ acpi_status acpi_enable_gpe(acpi_handle 
 
 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
 
+acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number);
+
 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status
drivers/acpi/acpica/acglobal.h +0 -7
Index: linux-2.6/drivers/acpi/acpica/acglobal.h
===================================================================
@@ -100,13 +100,6 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_all_methods
 u8 ACPI_INIT_GLOBAL(acpi_gbl_create_osi_method, TRUE);
 
 /*
- * Disable wakeup GPEs during runtime? Default is TRUE because WAKE and
- * RUNTIME GPEs should never be shared, and WAKE GPEs should typically only
- * be enabled just before going to sleep.
- */
-u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
-
-/*
  * Optionally use default values for the ACPI register widths. Set this to
  * TRUE to use the defaults, if an FADT contains incorrect widths/lengths.
  */
drivers/acpi/osl.c +0 -20
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1064,26 +1064,6 @@ static int __init acpi_serialize_setup(c
 
 __setup("acpi_serialize", acpi_serialize_setup);
 
-/*
- * Wake and Run-Time GPES are expected to be separate.
- * We disable wake-GPEs at run-time to prevent spurious
- * interrupts.
- *
- * However, if a system exists that shares Wake and
- * Run-time events on the same GPE this flag is available
- * to tell Linux to keep the wake-time GPEs enabled at run-time.
- */
-static int __init acpi_wake_gpes_always_on_setup(char *str)
-{
-	printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
-
-	acpi_gbl_leave_wake_gpes_disabled = FALSE;
-
-	return 1;
-}
-
-__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
-
 /* Check of resource interference between native drivers and ACPI
  * OperationRegions (SystemIO and System Memory only).
  * IO ports and memory declared in ACPI might be used by the ACPI subsystem
#2 lore raw

PATCH 1/3 ACPI / ACPICA: Do not execute _PRW methods during initialization

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Currently, during initialization ACPICA walks the entire ACPI namespace in search of any device objects with associated _PRW methods. All of the _PRW methods found are executed in the process to extract the GPE information returned by them, so that the GPEs in question can be marked as "able to wakeup" (more precisely, the ACPI_GPE_CAN_WAKE flag is set for them). The only purpose of this exercise is to avoid enabling the CAN_WAKE GPEs automatically, even if there are _Lxx/_Exx methods associated with them. However, it is both costly and unnecessary, because the host OS has to execute the _PRW methods anyway to check which devices can wake up the system from sleep states. Moreover, it then uses full information returned by _PRW, including the GPE information, so it can take care of disabling the GPEs if necessary.

Remove the code that walks the namespace and executes _PRW from ACPICA and modify comments to reflect that change. Make acpi_bus_set_run_wake_flags() disable GPEs for wakeup devices so that they don't cause spurious wakeup events to be signaled. This not only reduces the complexity of the ACPICA initialization code, but in some cases it should reduce the kernel boot time as well.

Unfortunately, for this purpose we need a new ACPICA function, acpi_gpe_can_wake(), to be called by the host OS in order to disable the GPEs that can wake up the system and were previously enabled by acpi_ev_initialize_gpe_block() or acpi_ev_update_gpes() (such a GPE should be disabled only once, because the initialization code enables it only once, but it may be pointed to by _PRW for multiple devices and that's why the additional function is necessary).

---
 drivers/acpi/acpica/acglobal.h  |    7 -
 drivers/acpi/acpica/evevent.c   |    5 
 drivers/acpi/acpica/evgpeblk.c  |   47 --------
 drivers/acpi/acpica/evgpeinit.c |  235 ++--------------------------------------
 drivers/acpi/acpica/evxfevnt.c  |   55 +++++++++
 drivers/acpi/acpica/exconfig.c  |    2 
 drivers/acpi/acpica/utxface.c   |    8 -
 drivers/acpi/osl.c              |   20 ---
 drivers/acpi/scan.c             |    2 
 include/acpi/acpixf.h           |    3 
 10 files changed, 85 insertions(+), 299 deletions(-)
drivers/acpi/scan.c +2 -0
Index: linux-2.6/drivers/acpi/scan.c
===================================================================
@@ -740,6 +740,8 @@ acpi_bus_extract_wakeup_device_power_pac
 		device->wakeup.resources.handles[i] = element->reference.handle;
 	}
 
+	acpi_gpe_can_wake(device->wakeup.gpe_device, device->wakeup.gpe_number);
+
 	return AE_OK;
 }
 
drivers/acpi/acpica/evgpeinit.c +17 -218

280 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +5 -42

73 lines not on this page · raw message

drivers/acpi/acpica/evxfevnt.c +54 -1

67 lines not on this page · raw message

drivers/acpi/acpica/utxface.c +2 -6
Index: linux-2.6/drivers/acpi/acpica/utxface.c
===================================================================
@@ -293,12 +293,8 @@ acpi_status acpi_initialize_objects(u32 
 	 * Complete the GPE initialization for the GPE blocks defined in the FADT
 	 * (GPE block 0 and 1).
 	 *
-	 * Note1: This is where the _PRW methods are executed for the GPEs. These
-	 * methods can only be executed after the SCI and Global Lock handlers are
-	 * installed and initialized.
-	 *
-	 * Note2: Currently, there seems to be no need to run the _REG methods
-	 * before execution of the _PRW methods and enabling of the GPEs.
+	 * NOTE: Currently, there seems to be no need to run the _REG methods
+	 * before enabling the GPEs.
 	 */
 	if (!(flags & ACPI_NO_EVENT_INIT)) {
 		status = acpi_ev_install_fadt_gpes();
drivers/acpi/acpica/evevent.c +2 -3
Index: linux-2.6/drivers/acpi/acpica/evevent.c
===================================================================
@@ -102,9 +102,8 @@ acpi_status acpi_ev_initialize_events(vo
  * RETURN:      Status
  *
  * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks
- *              (0 and 1). This causes the _PRW methods to be run, so the HW
- *              must be fully initialized at this point, including global lock
- *              support.
+ *              (0 and 1). The HW must be fully initialized at this point,
+ *              including global lock support.
  *
  ******************************************************************************/
 
drivers/acpi/acpica/exconfig.c +1 -1
Index: linux-2.6/drivers/acpi/acpica/exconfig.c
===================================================================
@@ -120,7 +120,7 @@ acpi_ex_add_table(u32 table_index,
 	acpi_ns_exec_module_code_list();
 	acpi_ex_enter_interpreter();
 
-	/* Update GPEs for any new _PRW or _Lxx/_Exx methods. Ignore errors */
+	/* Update GPEs for any new _Lxx/_Exx methods. Ignore errors */
 
 	status = acpi_tb_get_owner_id(table_index, &owner_id);
 	if (ACPI_SUCCESS(status)) {
include/acpi/acpixf.h +2 -1
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -63,7 +63,6 @@ extern u32 acpi_dbg_layer;
 extern u8 acpi_gbl_enable_interpreter_slack;
 extern u8 acpi_gbl_all_methods_serialized;
 extern u8 acpi_gbl_create_osi_method;
-extern u8 acpi_gbl_leave_wake_gpes_disabled;
 extern u8 acpi_gbl_use_default_register_widths;
 extern acpi_name acpi_gbl_trace_method_name;
 extern u32 acpi_gbl_trace_flags;
@@ -288,6 +287,8 @@ acpi_status acpi_enable_gpe(acpi_handle 
 
 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
 
+acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number);
+
 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status
drivers/acpi/acpica/acglobal.h +0 -7
Index: linux-2.6/drivers/acpi/acpica/acglobal.h
===================================================================
@@ -100,13 +100,6 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_all_methods
 u8 ACPI_INIT_GLOBAL(acpi_gbl_create_osi_method, TRUE);
 
 /*
- * Disable wakeup GPEs during runtime? Default is TRUE because WAKE and
- * RUNTIME GPEs should never be shared, and WAKE GPEs should typically only
- * be enabled just before going to sleep.
- */
-u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
-
-/*
  * Optionally use default values for the ACPI register widths. Set this to
  * TRUE to use the defaults, if an FADT contains incorrect widths/lengths.
  */
drivers/acpi/osl.c +0 -20
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1064,26 +1064,6 @@ static int __init acpi_serialize_setup(c
 
 __setup("acpi_serialize", acpi_serialize_setup);
 
-/*
- * Wake and Run-Time GPES are expected to be separate.
- * We disable wake-GPEs at run-time to prevent spurious
- * interrupts.
- *
- * However, if a system exists that shares Wake and
- * Run-time events on the same GPE this flag is available
- * to tell Linux to keep the wake-time GPEs enabled at run-time.
- */
-static int __init acpi_wake_gpes_always_on_setup(char *str)
-{
-	printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
-
-	acpi_gbl_leave_wake_gpes_disabled = FALSE;
-
-	return 1;
-}
-
-__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
-
 /* Check of resource interference between native drivers and ACPI
  * OperationRegions (SystemIO and System Memory only).
  * IO ports and memory declared in ACPI might be used by the ACPI subsystem
#3 lore raw

PATCH 2/3 ACPI / ACPICA: Simplify acpi_ev_initialize_gpe_block()

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Simplify the main loop in acpi_ev_initialize_gpe_block() by rearranging code and removing the "enabled" label that is not necessary any more.

---
 drivers/acpi/acpica/evgpeblk.c |   21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/acpi/acpica/evgpeblk.c +8 -13
Index: linux-2.6/drivers/acpi/acpica/evgpeblk.c
===================================================================
@@ -472,26 +472,21 @@ acpi_ev_initialize_gpe_block(struct acpi
 			gpe_event_info = &gpe_block->event_info[gpe_index];
 			gpe_number = gpe_index + gpe_block->block_base_number;
 
-			/*
-			 * If the GPE has already been enabled for runtime
-			 * signaling, make sure it remains enabled, but do not
-			 * increment its reference counter.
-			 */
-			if (gpe_event_info->runtime_count) {
-				status = acpi_ev_enable_gpe(gpe_event_info);
-				goto enabled;
-			}
-
 			/* Ignore GPEs that have no corresponding _Lxx/_Exx method */
 
 			if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
 				continue;
 			}
 
-			/* Enable this GPE */
+			/*
+			 * If the GPE has already been enabled for runtime
+			 * signaling, make sure it remains enabled, but do not
+			 * increment its reference counter.
+			 */
+			status = gpe_event_info->runtime_count ?
+				acpi_ev_enable_gpe(gpe_event_info) :
+				acpi_enable_gpe(gpe_device, gpe_number);
 
-			status = acpi_enable_gpe(gpe_device, gpe_number);
- enabled:
 			if (ACPI_FAILURE(status)) {
 				ACPI_EXCEPTION((AE_INFO, status,
 						"Could not enable GPE 0x%02X",
#4 lore raw

PATCH 2/3 ACPI / ACPICA: Simplify acpi_ev_initialize_gpe_block()

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Simplify the main loop in acpi_ev_initialize_gpe_block() by rearranging code and removing the "enabled" label that is not necessary any more.

---
 drivers/acpi/acpica/evgpeblk.c |   21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/acpi/acpica/evgpeblk.c +8 -13
Index: linux-2.6/drivers/acpi/acpica/evgpeblk.c
===================================================================
@@ -472,26 +472,21 @@ acpi_ev_initialize_gpe_block(struct acpi
 			gpe_event_info = &gpe_block->event_info[gpe_index];
 			gpe_number = gpe_index + gpe_block->block_base_number;
 
-			/*
-			 * If the GPE has already been enabled for runtime
-			 * signaling, make sure it remains enabled, but do not
-			 * increment its reference counter.
-			 */
-			if (gpe_event_info->runtime_count) {
-				status = acpi_ev_enable_gpe(gpe_event_info);
-				goto enabled;
-			}
-
 			/* Ignore GPEs that have no corresponding _Lxx/_Exx method */
 
 			if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
 				continue;
 			}
 
-			/* Enable this GPE */
+			/*
+			 * If the GPE has already been enabled for runtime
+			 * signaling, make sure it remains enabled, but do not
+			 * increment its reference counter.
+			 */
+			status = gpe_event_info->runtime_count ?
+				acpi_ev_enable_gpe(gpe_event_info) :
+				acpi_enable_gpe(gpe_device, gpe_number);
 
-			status = acpi_enable_gpe(gpe_device, gpe_number);
- enabled:
 			if (ACPI_FAILURE(status)) {
 				ACPI_EXCEPTION((AE_INFO, status,
 						"Could not enable GPE 0x%02X",
#5 lore raw

PATCH 3/3 ACPI / ACPICA: Fail acpi_gpe_wakeup() if ACPI_GPE_CAN_WAKE is unset

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make acpi_gpe_wakeup() return error code for GPEs whose ACPI_GPE_CAN_WAKE flag is not set. This way acpi_gpe_wakeup() will only wake for the GPEs reported by the host OS as "wakeup" ones with the help of acpi_gpe_can_wake().

---
 drivers/acpi/acpica/evxfevnt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/evxfevnt.c +1 -1
Index: linux-2.6/drivers/acpi/acpica/evxfevnt.c
===================================================================
@@ -236,7 +236,7 @@ acpi_status acpi_gpe_wakeup(acpi_handle 
 	/* Ensure that we have a valid GPE number */
 
 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
-	if (!gpe_event_info) {
+	if (!gpe_event_info || !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
 		status = AE_BAD_PARAMETER;
 		goto unlock_and_exit;
 	}
#6 lore raw

PATCH 3/3 ACPI / ACPICA: Fail acpi_gpe_wakeup() if ACPI_GPE_CAN_WAKE is unset

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Make acpi_gpe_wakeup() return error code for GPEs whose ACPI_GPE_CAN_WAKE flag is not set. This way acpi_gpe_wakeup() will only wake for the GPEs reported by the host OS as "wakeup" ones with the help of acpi_gpe_can_wake().

---
 drivers/acpi/acpica/evxfevnt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/evxfevnt.c +1 -1
Index: linux-2.6/drivers/acpi/acpica/evxfevnt.c
===================================================================
@@ -236,7 +236,7 @@ acpi_status acpi_gpe_wakeup(acpi_handle 
 	/* Ensure that we have a valid GPE number */
 
 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
-	if (!gpe_event_info) {
+	if (!gpe_event_info || !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
 		status = AE_BAD_PARAMETER;
 		goto unlock_and_exit;
 	}