aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Weisbecker <frederic@kernel.org>2023-11-24 23:32:26 +0100
committerFrederic Weisbecker <frederic@kernel.org>2024-02-08 18:12:17 +0100
commit6a9e7911f2cf487c46e6f5a903b1e63e913a3155 (patch)
tree8004e867a96d5bafe681678605cb96c1385499c8
parenta368a54e2c9aa8807d1a5390711166553d984980 (diff)
downloadlinux-dynticks-cpuidle/polling.tar.gz
cpuidle: Handle TIF_NR_POLLING on behalf of software polling idle statescpuidle/polling
Software polling idle states set again TIF_NR_POLLING and clear it upon exit. This involves error prone duplicated code and wasted cycles performing atomic operations, sometimes RmW fully ordered. To avoid this, benefit instead from the same generic TIF_NR_POLLING handling that is currently in use for hardware monitoring states. Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
-rw-r--r--drivers/cpuidle/cpuidle-powernv.c10
-rw-r--r--drivers/cpuidle/cpuidle-pseries.c11
-rw-r--r--drivers/cpuidle/cpuidle.c2
-rw-r--r--drivers/cpuidle/poll_state.c36
4 files changed, 16 insertions, 43 deletions
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 9ebedd972df0bb..1bf0d22340168c 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -71,8 +71,6 @@ static int snooze_loop(struct cpuidle_device *dev,
{
u64 snooze_exit_time;
- set_thread_flag(TIF_POLLING_NRFLAG);
-
local_irq_enable();
snooze_exit_time = get_tb() + get_snooze_timeout(dev, drv, index);
@@ -81,21 +79,13 @@ static int snooze_loop(struct cpuidle_device *dev,
HMT_very_low();
while (!need_resched()) {
if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time) {
- /*
- * Task has not woken up but we are exiting the polling
- * loop anyway. Require a barrier after polling is
- * cleared to order subsequent test of need_resched().
- */
- clear_thread_flag(TIF_POLLING_NRFLAG);
dev->poll_time_limit = true;
- smp_mb();
break;
}
}
HMT_medium();
ppc64_runlatch_on();
- clear_thread_flag(TIF_POLLING_NRFLAG);
local_irq_disable();
diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index 14db9b7d985d14..79940b7b1b900c 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -39,8 +39,6 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv,
{
u64 snooze_exit_time;
- set_thread_flag(TIF_POLLING_NRFLAG);
-
pseries_idle_prolog();
raw_local_irq_enable();
snooze_exit_time = get_tb() + snooze_timeout;
@@ -50,21 +48,12 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv,
HMT_low();
HMT_very_low();
if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time) {
- /*
- * Task has not woken up but we are exiting the polling
- * loop anyway. Require a barrier after polling is
- * cleared to order subsequent test of need_resched().
- */
dev->poll_time_limit = true;
- clear_thread_flag(TIF_POLLING_NRFLAG);
- smp_mb();
break;
}
}
HMT_medium();
- clear_thread_flag(TIF_POLLING_NRFLAG);
-
raw_local_irq_disable();
pseries_idle_epilog();
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index f8b1379ca8076a..1d3bdd5fbfa499 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -236,7 +236,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
broadcast = false;
}
- polling = target_state->flags & CPUIDLE_FLAG_MWAIT;
+ polling = target_state->flags & (CPUIDLE_FLAG_MWAIT | CPUIDLE_FLAG_POLLING);
/*
* If the target state doesn't poll on need_resched(), this is
diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c
index 9b6d90a726019c..d69936e2517e42 100644
--- a/drivers/cpuidle/poll_state.c
+++ b/drivers/cpuidle/poll_state.c
@@ -13,35 +13,29 @@
static int __cpuidle poll_idle(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
- u64 time_start;
-
- time_start = local_clock_noinstr();
+ u64 time_start = local_clock_noinstr();
+ unsigned int loop_count = 0;
+ u64 limit;
dev->poll_time_limit = false;
raw_local_irq_enable();
- if (!current_set_polling_and_test()) {
- unsigned int loop_count = 0;
- u64 limit;
-
- limit = cpuidle_poll_time(drv, dev);
-
- while (!need_resched()) {
- cpu_relax();
- if (loop_count++ < POLL_IDLE_RELAX_COUNT)
- continue;
-
- loop_count = 0;
- if (local_clock_noinstr() - time_start > limit) {
- dev->poll_time_limit = true;
- break;
- }
+
+ limit = cpuidle_poll_time(drv, dev);
+
+ while (!need_resched()) {
+ cpu_relax();
+ if (loop_count++ < POLL_IDLE_RELAX_COUNT)
+ continue;
+
+ loop_count = 0;
+ if (local_clock_noinstr() - time_start > limit) {
+ dev->poll_time_limit = true;
+ break;
}
}
raw_local_irq_disable();
- current_clr_polling();
-
return index;
}