From: Lv Zheng <lv.zheng@intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Len Brown <len.brown@intel.com>
Cc: Lv Zheng <lv.zheng@intel.com>, Lv Zheng <zetalog@gmail.com>,
<linux-kernel@vger.kernel.org>,
linux-acpi@vger.kernel.org
Subject: [RFC PATCH v3 03/14] ACPI/EC: Cleanup command storm prevention using the new GPE handling model.
Date: Mon, 21 Jul 2014 14:05:17 +0800 [thread overview]
Message-ID: <7bb1c9caec6364ee2b5b8676cbfc8de6f435f3dd.1405922585.git.lv.zheng@intel.com> (raw)
In-Reply-To: <cover.1405922585.git.lv.zheng@intel.com>
This patch deploys the following GPE handling model:
1. acpi_enable_gpe()/acpi_disable_gpe():
This set of APIs are used for EC usage reference counting.
2. acpi_set_gpe(ACPI_GPE_ENABLE)/acpi_set_gpe(ACPI_GPE_DISABLE):
This set of APIs are used for preventing GPE storm.
Note that this patch only converts current storm prevention implementations
using new APIs without correcting them.
For the EC driver, GPE is enabled for the following users:
1. Event monitoring (HW exception):
If we want to query events in interrupt mode, acpi_enable_gpe() is
invoked to allow EVT_SCI IRQs.
2. Command processing (IO request):
When we receive an upper layer command submission, acpi_enable_gpe() is
invoked to allow IBF=0,OBF=1 IRQs.
Comments are updated to reflect this model.
For the EC driver, GPE must be disabled for the following storms:
1. Command errors:
If there are too many IRQs coming during a command processing period and
such IRQs are not related to the event (EVT_SCI),
acpi_set_gpe(ACPI_GPE_DISABLE) is invoked to prevent further storms
during the same command transaction. This is not implemented in a good
style. Currently once command storming is detected, it is enabled for
all follow-up commands. Ideally, we should only enable storm prevention
for the current command so that the next command can try the efficient
interrupt mode again.
This patch doesn't change current logic, the correction will be
implemented by further patches.
2. Event errors:
There are cases that BIOS doesn't provide a _Qxx method for the returned
xx query value, in this case, acpi_set_gpe(ACPI_GPE_DISABLE) need to be
invoked to prevent event IRQ storms.
This patch doesn't implement this logic, such gap will be implemented by
further patches.
3. Pending events:
Though GPE is edge triggered, the underlying firmware may maliciously
trigger GPE when IRQ is indicated. This makes EC GPE more like a level
triggered interrupt. In case of event (EVT_SCI), since the Linux EC
driver responses it (using QR_EC command) in the task context with GPE
enabled, there are chances for a GPE storm to occur before QR_EC is
executed.
If we still want to keep the task context responding logic, for such EC
hardware/firmware, acpi_set_gpe(ACPI_GPE_DISABLE) should be invoked
after EVT_SCI interrupt is indicated and acpi_set_gpe(ACPI_GPE_ENABLE)
should be invoked before the first step of QR_EC has taken place.
This patch doesn't implement this logic, such gap can be implemented by
future patches.
The acpi_set_gpe() should be invoked for an outstanding command,
which means it should be invoked inside of a pair of acpi_enable_gpe()/
acpi_disable_gpe() invocation. This patch thus also moves the storm
prevention logic into acpi_ec_transaction_unlocked(). Note that in order to
make it working, ACPI_REENABLE_GPE should be unset when the storming is
indicated.
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
---
drivers/acpi/ec.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 54bebbb..4c7a81b 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -321,19 +321,35 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
ret = -EINVAL;
goto unlock;
}
+ /* Enable GPE for command processing (IBF=0/OBF=1) */
+ acpi_enable_gpe(NULL, ec->gpe);
/* following two actions should be kept atomic */
ec->curr = t;
pr_debug("***** Command(%s) started *****\n",
acpi_ec_cmd_string(t->command));
+ if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
+ pr_debug("+++++ Polling enabled +++++\n");
+ acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
+ }
start_transaction(ec);
if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
spin_unlock_irqrestore(&ec->lock, tmp);
ret = ec_poll(ec);
spin_lock_irqsave(&ec->lock, tmp);
+ if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
+ acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
+ pr_debug("+++++ Polling disabled +++++\n");
+ } else if (t->irq_count > ec_storm_threshold) {
+ pr_debug("+++++ Polling scheduled (%d GPE) +++++\n",
+ t->irq_count);
+ set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
+ }
pr_debug("***** Command(%s) stopped *****\n",
acpi_ec_cmd_string(t->command));
ec->curr = NULL;
+ /* Disable GPE for command processing (IBF=0/OBF=1) */
+ acpi_disable_gpe(NULL, ec->gpe);
unlock:
spin_unlock_irqrestore(&ec->lock, tmp);
return ret;
@@ -355,26 +371,11 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
goto unlock;
}
}
- /* disable GPE during transaction if storm is detected */
- if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
- /* It has to be disabled, so that it doesn't trigger. */
- acpi_disable_gpe(NULL, ec->gpe);
- }
status = acpi_ec_transaction_unlocked(ec, t);
/* check if we received SCI during transaction */
ec_check_sci_sync(ec, acpi_ec_read_status(ec));
- if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
- msleep(1);
- /* It is safe to enable the GPE outside of the transaction. */
- acpi_enable_gpe(NULL, ec->gpe);
- } else if (t->irq_count > ec_storm_threshold) {
- pr_info("GPE storm detected(%d GPEs), "
- "transactions will use polling mode\n",
- t->irq_count);
- set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
- }
if (ec->global_lock)
acpi_release_global_lock(glk);
unlock:
@@ -509,8 +510,12 @@ static void acpi_ec_start(struct acpi_ec *ec)
unsigned long flags;
spin_lock_irqsave(&ec->lock, flags);
- if (!test_and_set_bit(EC_FLAGS_STARTED, &ec->flags))
+ if (!test_and_set_bit(EC_FLAGS_STARTED, &ec->flags)) {
+ pr_debug("+++++ Starting EC +++++\n");
+ /* Enable GPE for event processing (EVT_SCI=1) */
acpi_enable_gpe(NULL, ec->gpe);
+ pr_info("+++++ EC started +++++\n");
+ }
spin_unlock_irqrestore(&ec->lock, flags);
}
@@ -520,9 +525,12 @@ static void acpi_ec_stop(struct acpi_ec *ec)
spin_lock_irqsave(&ec->lock, flags);
if (acpi_ec_started(ec)) {
+ pr_debug("+++++ Stopping EC +++++\n");
+ /* Disable GPE for event processing (EVT_SCI=1) */
acpi_disable_gpe(NULL, ec->gpe);
clear_bit(EC_FLAGS_STARTED, &ec->flags);
clear_bit(EC_FLAGS_STOPPED, &ec->flags);
+ pr_info("+++++ EC stopped +++++\n");
}
spin_unlock_irqrestore(&ec->lock, flags);
}
@@ -699,13 +707,16 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
{
unsigned long flags;
struct acpi_ec *ec = data;
+ u32 enable = 0;
spin_lock_irqsave(&ec->lock, flags);
if (advance_transaction(ec))
wake_up(&ec->wait);
+ if (!test_bit(EC_FLAGS_GPE_STORM, &ec->flags))
+ enable = ACPI_REENABLE_GPE;
spin_unlock_irqrestore(&ec->lock, flags);
ec_check_sci(ec, acpi_ec_read_status(ec));
- return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE;
+ return ACPI_INTERRUPT_HANDLED | enable;
}
/* --------------------------------------------------------------------------
--
1.7.10
next prev parent reply other threads:[~2014-07-21 6:05 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-18 3:17 [PATCH 0/9] ACPI/EC: Improve " Lv Zheng
2014-06-18 3:17 ` [PATCH 1/9] ACPICA: Events: Reduce indent divergences of events files Lv Zheng
2014-06-18 3:17 ` [PATCH 2/9] ACPICA: Events: Fix an issue that GPE APIs cannot be invoked in atomic context Lv Zheng
2014-06-18 3:17 ` [PATCH 3/9] ACPICA: Events: Introduce acpi_set_gpe()/acpi_finish_gpe() to reduce divergences Lv Zheng
2014-06-18 3:17 ` [PATCH 4/9] ACPICA: Events: Remove acpi_ev_enable_gpe() Lv Zheng
2014-06-18 3:17 ` [PATCH 5/9] ACPICA: Events: Reduce divergences to honor notify handler enabled GPEs Lv Zheng
2014-06-18 3:17 ` [PATCH 6/9] ACPI/EC: Introduce STARTED/STOPPED flags to replace BLOCKED flag Lv Zheng
2014-06-18 3:18 ` [PATCH 7/9] ACPI/EC: Add detailed command/query debugging information Lv Zheng
2014-06-18 3:18 ` [PATCH 8/9] ACPI/EC: Deploy the new GPE handling model Lv Zheng
2014-06-18 3:18 ` [PATCH 9/9] ACPI/EC: Add unit test support for EC driver hotplug Lv Zheng
2014-07-15 3:07 ` [PATCH v2 0/9] ACPICA: Improve GPE handling model Lv Zheng
2014-07-15 3:07 ` [PATCH v2 1/9] ACPICA: Events: Reduce indent divergences of events files Lv Zheng
2014-07-15 3:07 ` [PATCH v2 2/9] ACPICA: Events: Fix an issue that GPE APIs cannot be invoked in atomic context Lv Zheng
2014-07-15 3:07 ` [PATCH v2 3/9] ACPICA: Events: Fix an issue that GPE APIs cannot be invoked in deferred handlers Lv Zheng
2014-07-15 3:07 ` [PATCH v2 4/9] ACPICA: Events: Introduce acpi_set_gpe()/acpi_finish_gpe() to reduce divergences Lv Zheng
2014-07-15 3:07 ` [PATCH v2 5/9] ACPICA: Events: Fix an issue that acpi_set_gpe() cannot unconditionally enable GPEs Lv Zheng
2014-07-15 3:07 ` [PATCH v2 6/9] ACPICA: Events: Fix an issue that status of GPEs are unexpectedly cleared Lv Zheng
2014-07-15 3:07 ` [PATCH v2 7/9] ACPICA: Events: Fix an issue that originally_enabled check is not paired Lv Zheng
2014-07-15 3:08 ` [PATCH v2 8/9] ACPICA: Events: Add a flag to disable internal auto GPE clearing Lv Zheng
2014-07-15 3:08 ` [PATCH v2 9/9] ACPI: Update interrupt handler to honor new ACPI_REENABLE_GPE bit Lv Zheng
2014-07-15 12:25 ` [PATCH v2 0/9] ACPICA: Improve GPE handling model Rafael J. Wysocki
2014-07-16 0:36 ` Zheng, Lv
2014-07-15 3:14 ` [PATCH v2 00/10] ACPI/EC: Add event storm prevention and cleanup command storm prevention Lv Zheng
2014-07-15 3:14 ` [PATCH v2 01/10] ACPI/EC: Introduce STARTED/STOPPED flags to replace BLOCKED flag Lv Zheng
2014-07-15 3:14 ` [PATCH v2 02/10] ACPI/EC: Add detailed command/query debugging information Lv Zheng
2014-07-15 3:14 ` [PATCH v2 03/10] ACPI/EC: Deploy the new GPE handling model Lv Zheng
2014-07-15 3:14 ` [PATCH v2 04/10] ACPI/EC: Refine command storm prevention support Lv Zheng
2014-07-15 3:14 ` [PATCH v2 05/10] ACPI/EC: Add reference counting for query handlers Lv Zheng
2014-07-15 3:15 ` [PATCH v2 06/10] ACPI/EC: Add a warning message to indicate event storms Lv Zheng
2014-07-15 3:15 ` [PATCH v2 07/10] ACPI/EC: Refine event/query debugging messages Lv Zheng
2014-07-15 3:15 ` [PATCH v2 08/10] ACPI/EC: Add command flushing support Lv Zheng
2014-07-15 3:15 ` [PATCH v2 09/10] ACPI/EC: Add event storm prevention support Lv Zheng
2014-07-15 3:15 ` [PATCH v2 10/10] ACPI/EC: Add unit test support for EC driver hotplug Lv Zheng
2014-07-15 7:09 ` [PATCH v2] ACPI/EC: Enable storm prevention mechanisms Lv Zheng
2014-07-16 0:44 ` Andi Kleen
2014-07-16 0:55 ` Zheng, Lv
2014-07-21 6:04 ` [RFC PATCH v3 00/14] ACPI/EC: Add event storm prevention and cleanup command storm prevention Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 01/14] ACPI/EC: Introduce STARTED/STOPPED flags to replace BLOCKED flag Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 02/14] ACPI/EC: Add detailed command/query debugging information Lv Zheng
2014-07-21 6:05 ` Lv Zheng [this message]
2014-07-21 6:05 ` [RFC PATCH v3 04/14] ACPI/EC: Refine command storm prevention support Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 05/14] ACPI/EC: Add reference counting for query handlers Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 06/14] ACPI/EC: Add command flushing support Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 07/14] ACPI/EC: Add a warning message to indicate event storms Lv Zheng
2014-07-21 6:05 ` [RFC PATCH v3 08/14] ACPI/EC: Refine event/query debugging messages Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 09/14] ACPI/EC: Add CPU ID to " Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 10/14] ACPI/EC: Cleanup QR_SC command processing by adding a kernel thread to poll EC events Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 11/14] ACPI/EC: Add event storm prevention support Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 12/14] ACPI/EC: Add GPE reference counting debugging messages Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 13/14] ACPI/EC: Add unit test support for EC driver hotplug Lv Zheng
2014-07-21 6:06 ` [RFC PATCH v3 14/14] ACPI/EC: Cleanup coding style Lv Zheng
2014-07-22 1:11 ` [RFC PATCH v3 00/14] ACPI/EC: Add event storm prevention and cleanup command storm prevention Rafael J. Wysocki
2014-07-22 1:25 ` Zheng, Lv
2014-07-22 22:15 ` Rafael J. Wysocki
2014-07-23 1:31 ` Zheng, Lv
2015-02-05 8:24 ` [PATCH v4 0/6] ACPI / EC: Fix GPE handling related races Lv Zheng
2015-02-05 8:27 ` [PATCH v4 1/6] ACPICA: Events: Introduce ACPI_GPE_DISPATCH_RAW_HANDLER to fix 2 issues for the current GPE APIs Lv Zheng
2015-02-05 8:27 ` [PATCH v4 2/6] ACPICA: Events: Introduce acpi_set_gpe()/acpi_finish_gpe() to reduce divergences Lv Zheng
2015-02-05 8:27 ` [PATCH v4 3/6] ACPICA: Events: Enable APIs to allow interrupt/polling adaptive request based GPE handling model Lv Zheng
2015-02-05 8:27 ` [PATCH v4 4/6] ACPI / EC: Fix several GPE handling issues by deploying ACPI_GPE_DISPATCH_RAW_HANDLER mode Lv Zheng
2015-02-05 8:27 ` [PATCH v4 5/6] ACPI / EC: Reduce ec_poll() by referencing the last register access timestamp Lv Zheng
2015-02-05 8:27 ` [PATCH v4 6/6] ACPI / EC: Update revision due to raw handler mode Lv Zheng
2015-02-05 15:19 ` [PATCH v4 0/6] ACPI / EC: Fix GPE handling related races Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7bb1c9caec6364ee2b5b8676cbfc8de6f435f3dd.1405922585.git.lv.zheng@intel.com \
--to=lv.zheng@intel.com \
--cc=len.brown@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=zetalog@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®