Skip to contentSkip to conversation

acpi: Avoid dropping rapid hotkey events (or other GPEs) on Asus EeePC

PATCH Applied [email protected] 4 participants 10 messages Aug 20, 2008 – Aug 23, 2008

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

PATCH 2/2 acpi: Avoid dropping rapid hotkey events (or other GPEs) on Asus EeePC

From: Alan Jenkins <[email protected]>

It looks like this EC clears the SMI_EVT bit after every query, even if there are more events pending. The workaround is to repeatedly query the EC until it reports that no events remain.

This fixes a regression in 2.6.26 (from 2.6.25.3). Initially reported as "Asus Eee PC hotkeys stop working if pressed quickly" in bugzilla
<http://bugzilla.kernel.org/show_bug.cgi?id=11089>.

The regression was caused by a recently added check for interrupt storms. The Eee PC triggers this check and switches to polling. When multiple events arrive between polling intervals, only one is fetched from the EC. This causes erroneous behaviour; ultimately events stop being delivered altogether when the EC buffer overflows.

Cc Alexey Starikovskiy <[email protected]>
Cc Maximilian Engelhardt <[email protected]>
Cc Henrique de Moraes Holschuh <[email protected]>
Cc Andi Kleen <[email protected]>

---

 drivers/acpi/ec.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/acpi/ec.c renamed from drivers/acpi/ec.c~acpi-avoid-dropping-rapid-hotkey-events-or-other-gpes-on-asus-eeepc +13 -5
diff -puN drivers/acpi/ec.c~acpi-avoid-dropping-rapid-hotkey-events-or-other-gpes-on-asus-eeepc drivers/acpi/ec.c
@@ -486,14 +486,10 @@ void acpi_ec_remove_query_handler(struct
 
 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
 
-static void acpi_ec_gpe_query(void *ec_cxt)
+static void acpi_ec_gpe_run_handler(struct acpi_ec *ec, u8 value)
 {
-	struct acpi_ec *ec = ec_cxt;
-	u8 value = 0;
 	struct acpi_ec_query_handler *handler, copy;
 
-	if (!ec || acpi_ec_query(ec, &value))
-		return;
 	mutex_lock(&ec->lock);
 	list_for_each_entry(handler, &ec->list, node) {
 		if (value == handler->query_bit) {
@@ -511,6 +507,18 @@ static void acpi_ec_gpe_query(void *ec_c
 	mutex_unlock(&ec->lock);
 }
 
+static void acpi_ec_gpe_query(void *ec_cxt)
+{
+	struct acpi_ec *ec = ec_cxt;
+	u8 value = 0;
+
+	if (!ec)
+		return;
+
+	while (!acpi_ec_query(ec, &value))
+		acpi_ec_gpe_run_handler(ec, value);
+}
+
 static u32 acpi_ec_gpe_handler(void *data)
 {
 	acpi_status status = AE_OK;

_

#1 lore raw

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Regards,
Alex.

Quoted 65 lines · [email protected] wrote:

From: Alan Jenkins <[email protected]>

It looks like this EC clears the SMI_EVT bit after every query, even if there are more events pending. The workaround is to repeatedly query the EC until it reports that no events remain.

This fixes a regression in 2.6.26 (from 2.6.25.3). Initially reported as "Asus Eee PC hotkeys stop working if pressed quickly" in bugzilla
<http://bugzilla.kernel.org/show_bug.cgi?id=11089>.

The regression was caused by a recently added check for interrupt storms. The Eee PC triggers this check and switches to polling. When multiple events arrive between polling intervals, only one is fetched from the EC. This causes erroneous behaviour; ultimately events stop being delivered altogether when the EC buffer overflows.

Cc Alexey Starikovskiy <[email protected]>
Cc Maximilian Engelhardt <[email protected]>
Cc Henrique de Moraes Holschuh <[email protected]>
Cc Andi Kleen <[email protected]>

---

 drivers/acpi/ec.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff -puN drivers/acpi/ec.c~acpi-avoid-dropping-rapid-hotkey-events-or-other-gpes-on-asus-eeepc drivers/acpi/ec.c

drivers/acpi/ec.c renamed from drivers/acpi/ec.c~acpi-avoid-dropping-rapid-hotkey-events-or-other-gpes-on-asus-eeepc +13 -5
@@ -486,14 +486,10 @@ void acpi_ec_remove_query_handler(struct
 
 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
 
-static void acpi_ec_gpe_query(void *ec_cxt)
+static void acpi_ec_gpe_run_handler(struct acpi_ec *ec, u8 value)
 {
-	struct acpi_ec *ec = ec_cxt;
-	u8 value = 0;
 	struct acpi_ec_query_handler *handler, copy;
 
-	if (!ec || acpi_ec_query(ec, &value))
-		return;
 	mutex_lock(&ec->lock);
 	list_for_each_entry(handler, &ec->list, node) {
 		if (value == handler->query_bit) {
@@ -511,6 +507,18 @@ static void acpi_ec_gpe_query(void *ec_c
 	mutex_unlock(&ec->lock);
 }
 
+static void acpi_ec_gpe_query(void *ec_cxt)
+{
+	struct acpi_ec *ec = ec_cxt;
+	u8 value = 0;
+
+	if (!ec)
+		return;
+
+	while (!acpi_ec_query(ec, &value))
+		acpi_ec_gpe_run_handler(ec, value);
+}
+
 static u32 acpi_ec_gpe_handler(void *data)
 {
 	acpi_status status = AE_OK;

_

#2 lore raw
Quoted 3 lines · Alexey Starikovskiy

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Ok I'll skip that one for now. Andrew can you please drop it. The bug will be handled in bugzilla.

-Andi

#4 lore raw
In reply to Alexey Starikovskiy
Quoted 7 lines · Alexey Starikovskiy

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Regards,
Alex.

That's more likely to have been a problem with my other patches, ripping out the QUERY_PENDING flag and GPE polling, with (what were to Alex) predictably bad results.

You're right this patch needs testing on it's own. But the current code is definitely wrong.

If the "GPE polling" workaround is triggered, and there is a series of events > one every 0.5s, the EC buffer can overflow. All it needs is an ACPI hotkey with fast enough autorepeat. And I bet it's not just my EC that breaks horribly when that happens.

Thanks
Alan

#5 lore raw
Quoted 6 lines · Alan Jenkins
Quoted 5 lines · Alexey Starikovskiy

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Quoted 6 lines
Quoted 2 lines

Regards,
Alex.

That's more likely to have been a problem with my other patches, ripping out the QUERY_PENDING flag and GPE polling, with (what were to Alex) predictably bad results.

Hi Alan,
I checked QUERY_PENDING removal, and it makes system with broken EC unusable, so you might stop considering it as an option.

Quoted 8 lines

You're right this patch needs testing on it's own. But the current code is definitely wrong.

If the "GPE polling" workaround is triggered, and there is a series of events > one every 0.5s, the EC buffer can overflow. All it needs is an ACPI hotkey with fast enough autorepeat. And I bet it's not just my EC that breaks horribly when that happens.

Right now I am going to remove automatic switch to poll mode, so user could choose, which EC mode is more tolerable.

Quoted 3 lines

Thanks
Alan

Regards,
Alex.

#6 lore raw
Quoted 10 lines · Alexey Starikovskiy
Quoted 9 lines · Alan Jenkins
Quoted 7 lines · Alexey Starikovskiy

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Regards,
Alex.

Quoted 7 lines
Quoted 3 lines

That's more likely to have been a problem with my other patches, ripping out the QUERY_PENDING flag and GPE polling, with (what were to Alex) predictably bad results.

Hi Alan,
I checked QUERY_PENDING removal, and it makes system with broken EC unusable, so you might stop considering it as an option.

In hindsight, the bad results were predictable to me also. I don't advocate that any more.

Quoted 11 lines
Quoted 8 lines

You're right this patch needs testing on it's own. But the current code is definitely wrong.

If the "GPE polling" workaround is triggered, and there is a series of events > one every 0.5s, the EC buffer can overflow. All it needs is an ACPI hotkey with fast enough autorepeat. And I bet it's not just my EC that breaks horribly when that happens.

Right now I am going to remove automatic switch to poll mode, so user could
choose, which EC mode is more tolerable.

Sounds sensible. Hopefully we're right that most systems with these broken EC's don't want the workaround. I assume you will still notify the user automatically, something like "acpi: ec: GPE storm detected, try booting with ec=poll".

Thanks
Alan

#7 lore raw

Here is the patch.

Please try/review.

Regards,
Alex.

Quoted 8 lines · Alan Jenkins

Sounds sensible. Hopefully we're right that most systems with these broken EC's don't want the workaround. I assume you will still notify the user automatically, something like "acpi: ec: GPE storm detected, try booting with ec=poll".

Thanks
Alan

ACPI: EC: Don't degrade to poll mode at storm automatically.

From: Alexey Starikovskiy <[email protected]>

Not all users of semi-broken EC devices want to degrade to poll mode, so give them right to choose.

---

 Documentation/kernel-parameters.txt |    5 +++++
 drivers/acpi/ec.c                   |   36 +++++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 10 deletions(-)
Documentation/kernel-parameters.txt +5 -0
index a897646..cbde9bc 100644
@@ -675,6 +675,11 @@ and is between 256 and 4096 characters. It is defined in the file
 
 	eata=		[HW,SCSI]
 
+	ec_intr=	[HW,ACPI] ACPI Embedded Controller interrupt mode
+			Format: <int>
+			0: polling mode
+			non-0: interrupt mode (default)
+
 	edd=		[EDD]
 			Format: {"off" | "on" | "skip[mbr]"}
 
drivers/acpi/ec.c +26 -10
index 13593f9..bdc9b6b 100644
@@ -110,6 +110,8 @@ static struct acpi_ec {
 	u8 handlers_installed;
 } *boot_ec, *first_ec;
 
+int acpi_ec_intr = 1; /* Default is interrupt mode */
+
 /* 
  * Some Asus system have exchanged ECDT data/command IO addresses.
  */
@@ -516,12 +518,14 @@ static u32 acpi_ec_gpe_handler(void *data)
 	acpi_status status = AE_OK;
 	struct acpi_ec *ec = data;
 	u8 state = acpi_ec_read_status(ec);
+	static bool warn_done = 0;
 
 	pr_debug(PREFIX "~~~> interrupt\n");
 	atomic_inc(&ec->irq_count);
-	if (atomic_read(&ec->irq_count) > 5) {
-		pr_err(PREFIX "GPE storm detected, disabling EC GPE\n");
-		ec_switch_to_poll_mode(ec);
+	if (!warn_done && atomic_read(&ec->irq_count) > 5) {
+		pr_warning(PREFIX "GPE storm detected, try to use ec_intr=0 "
+			"kernel option, if you see problems with keyboard.\n");
+		warn_done = 1;
 		goto end;
 	}
 	clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
@@ -848,20 +852,21 @@ static int ec_install_handlers(struct acpi_ec *ec)
 	acpi_status status;
 	if (ec->handlers_installed)
 		return 0;
-	status = acpi_install_gpe_handler(NULL, ec->gpe,
+	if (acpi_ec_intr) {
+		status = acpi_install_gpe_handler(NULL, ec->gpe,
 					  ACPI_GPE_EDGE_TRIGGERED,
 					  &acpi_ec_gpe_handler, ec);
-	if (ACPI_FAILURE(status))
-		return -ENODEV;
-
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
+		if (ACPI_FAILURE(status))
+			return -ENODEV;
 
+		acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+		acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
+	}
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
 						    NULL, ec);
-	if (ACPI_FAILURE(status)) {
+	if (ACPI_FAILURE(status) && acpi_ec_intr) {
 		acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
 		return -ENODEV;
 	}
@@ -1047,3 +1052,14 @@ static void __exit acpi_ec_exit(void)
 	return;
 }
 #endif	/* 0 */
+
+static int __init acpi_ec_set_intr_mode(char *str)
+{
+	if (!get_option(&str, &acpi_ec_intr)) {
+		acpi_ec_intr = 0;
+		return 0;
+	}
+	return 1;
+}
+
+__setup("ec_intr=", acpi_ec_set_intr_mode);
#3 lore raw
In reply to Andi Kleen
Quoted 8 lines · On Thu, 21 Aug 2008 14:22:01 +0200 Andi Kleen <[email protected]> wrote:
Quoted 3 lines · Alexey Starikovskiy

Hi Andrew,

As I understand, this patch is wrong according to comment #65 in bug #9998.

Ok I'll skip that one for now. Andrew can you please drop it. The bug will be handled in bugzilla.

Not that I'm mistrustful or anything, but I think I'll hang onto it until I'm told it got fixed..

http://bugzilla.kernel.org/show_bug.cgi?id=11089 is marked resolved, and a duplicate of http://bugzilla.kernel.org/show_bug.cgi?id=10919,
which is marked resolved. Is this all correct??

#8 lore raw
In reply to Alexey Starikovskiy
Quoted 4 lines · Alexey Starikovskiy

Here is the patch.

Please try/review.

Sorry, I can't help with testing this any more. The "bad state" I complained about earlier seems to be permanent now.

I left the laptop with AC and battery disconnected last night. This morning both 2.6.22 and 2.6.24-19-generic (ubuntu) are locking up or rebooting as soon as I press a hotkey. The patch resets the default behaviour back to 2.6.24, so it won't make any difference.

None of these kernels should have the GPE polling problem. There are many people using Ubuntu on the EeePC without complaint; I must have damaged the hardware or firmware.

OTOH 2.6.21.4-eeepc (the pre-installed kernel from Xandros/Asus) is immune. I will work on it, but don't expect anything soon.

Thanks for your help
Alan

#9 lore raw
Quoted 15 lines · Alan Jenkins
Quoted 5 lines · Alexey Starikovskiy

Here is the patch.

Please try/review.

Sorry, I can't help with testing this any more. The "bad state" I complained about earlier seems to be permanent now.

I left the laptop with AC and battery disconnected last night. This morning both 2.6.22 and 2.6.24-19-generic (ubuntu) are locking up or rebooting as soon as I press a hotkey. The patch resets the default behaviour back to 2.6.24, so it won't make any difference.

Quoted 7 lines

None of these kernels should have the GPE polling problem. There are many people using Ubuntu on the EeePC without complaint; I must have damaged the hardware or firmware.

OTOH 2.6.21.4-eeepc (the pre-installed kernel from Xandros/Asus) is immune. I will work on it, but don't expect anything soon.

I was able to bisect this to a config option, X86_UP_IOAPIC. I can get rid of it on all kernels by just booting with noapic.

I was then able to try your patch, which works fine. I see the warning in the kernel log, but no hotkey keypresses are lost.

Thanks
Alan