The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] softirq: use bit waits instead of var waits.
Date: Wed, 25 Sep 2024 15:31:44 +1000	[thread overview]
Message-ID: <20240925053405.3960701-8-neilb@suse.de> (raw)
In-Reply-To: <20240925053405.3960701-1-neilb@suse.de>

The waiting in softirq.c is always waiting for a bit to be cleared.
This makes the bit wait functions seem more suitable.
By switching over we can rid of all explicit barriers.  We also use
wait_on_bit_lock() to avoid an explicit loop.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 kernel/softirq.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index d082e7840f88..b756d6b3fd09 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -748,10 +748,8 @@ EXPORT_SYMBOL(__tasklet_hi_schedule);
 
 static bool tasklet_clear_sched(struct tasklet_struct *t)
 {
-	if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state)) {
-		wake_up_var(&t->state);
+	if (test_and_clear_wake_up_bit(TASKLET_STATE_SCHED, &t->state))
 		return true;
-	}
 
 	WARN_ONCE(1, "tasklet SCHED state not set: %s %pS\n",
 		  t->use_callback ? "callback" : "func",
@@ -871,8 +869,7 @@ void tasklet_kill(struct tasklet_struct *t)
 	if (in_interrupt())
 		pr_notice("Attempt to kill tasklet from interrupt\n");
 
-	while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
-		wait_var_event(&t->state, !test_bit(TASKLET_STATE_SCHED, &t->state));
+	wait_on_bit_lock(&t->state, TASKLET_STATE_SCHED, TASK_UNINTERRUPTIBLE);
 
 	tasklet_unlock_wait(t);
 	tasklet_clear_sched(t);
@@ -882,16 +879,13 @@ EXPORT_SYMBOL(tasklet_kill);
 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
 void tasklet_unlock(struct tasklet_struct *t)
 {
-	smp_mb__before_atomic();
-	clear_bit(TASKLET_STATE_RUN, &t->state);
-	smp_mb__after_atomic();
-	wake_up_var(&t->state);
+	clear_and_wake_up_bit(TASKLET_STATE_RUN, &t->state);
 }
 EXPORT_SYMBOL_GPL(tasklet_unlock);
 
 void tasklet_unlock_wait(struct tasklet_struct *t)
 {
-	wait_var_event(&t->state, !test_bit(TASKLET_STATE_RUN, &t->state));
+	wait_on_bit(&t->state, TASKLET_STATE_RUN, TASK_UNINTERRUPTIBLE);
 }
 EXPORT_SYMBOL_GPL(tasklet_unlock_wait);
 #endif
-- 
2.46.0


  parent reply	other threads:[~2024-09-25  5:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25  5:31 [PATCH 0/7 v3] Make wake_up_{bit,var} less fragile NeilBrown
2024-09-25  5:31 ` [PATCH 1/7] sched: change wake_up_bit() and related function to expect unsigned long * NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` [PATCH 2/7] sched: Improve documentation for wake_up_bit/wait_on_bit family of functions NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` [PATCH 3/7] sched: Document wait_var_event() family of functions and wake_up_var() NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` [PATCH 4/7] sched: Add test_and_clear_wake_up_bit() and atomic_dec_and_wake_up() NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` [PATCH 5/7] sched: Add wait/wake interface for variable updated under a lock NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` [PATCH 6/7] sched: add wait_var_event_io() NeilBrown
2024-10-08  7:56   ` [tip: sched/core] " tip-bot2 for NeilBrown
2024-09-25  5:31 ` NeilBrown [this message]
2024-10-08  7:56   ` [tip: sched/core] softirq: use bit waits instead of var waits tip-bot2 for NeilBrown
2024-09-26 17:13 ` [PATCH 0/7 v3] Make wake_up_{bit,var} less fragile Thomas Gleixner
2024-09-26 21:14   ` NeilBrown

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=20240925053405.3960701-8-neilb@suse.de \
    --to=neilb@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    /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