All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen-blkback: Use freezable wait_event variants for freezable kthread
@ 2023-12-21  3:23 Kevin Hao
  0 siblings, 0 replies; only message in thread
From: Kevin Hao @ 2023-12-21  3:23 UTC (permalink / raw)
  To: Roger Pau Monné, Jens Axboe
  Cc: xen-devel, linux-block, Rafael J. Wysocki, Pavel Machek

A freezable kernel thread can enter frozen state during freezing by
either calling try_to_freeze() or using wait_event_freezable() and its
variants. So for the following snippet of code in a kernel thread loop:
  try_to_freeze();
  wait_event_interruptible();

We can change it to a simple wait_event_freezable() and then eliminate
a function call.

Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
 drivers/block/xen-blkback/blkback.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 4defd7f387c7..bef0f950b257 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -563,20 +563,18 @@ int xen_blkif_schedule(void *arg)
 
 	set_freezable();
 	while (!kthread_should_stop()) {
-		if (try_to_freeze())
-			continue;
 		if (unlikely(vbd->size != vbd_sz(vbd)))
 			xen_vbd_resize(blkif);
 
 		timeout = msecs_to_jiffies(LRU_INTERVAL);
 
-		timeout = wait_event_interruptible_timeout(
+		timeout = wait_event_freezable_timeout(
 			ring->wq,
 			ring->waiting_reqs || kthread_should_stop(),
 			timeout);
 		if (timeout == 0)
 			goto purge_gnt_list;
-		timeout = wait_event_interruptible_timeout(
+		timeout = wait_event_freezable_timeout(
 			ring->pending_free_wq,
 			!list_empty(&ring->pending_free) ||
 			kthread_should_stop(),
@@ -593,8 +591,8 @@ int xen_blkif_schedule(void *arg)
 		if (ret > 0)
 			ring->waiting_reqs = 1;
 		if (ret == -EACCES)
-			wait_event_interruptible(ring->shutdown_wq,
-						 kthread_should_stop());
+			wait_event_freezable(ring->shutdown_wq,
+					     kthread_should_stop());
 
 		if (do_eoi && !ring->waiting_reqs) {
 			xen_irq_lateeoi(ring->irq, eoi_flags);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-21  3:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21  3:23 [PATCH] xen-blkback: Use freezable wait_event variants for freezable kthread Kevin Hao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.