Skip to contentSkip to conversation

xen-blkback: Use freezable wait_event variants for freezable kthread

PATCH New Kevin Hao 1 participant 1 message Dec 21, 2023

Subsystems (2)
lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH 1/1 xen-blkback: Use freezable wait_event variants for freezable kthread

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.

---
 drivers/block/xen-blkback/blkback.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/block/xen-blkback/blkback.c +4 -6
index 4defd7f387c7..bef0f950b257 100644
@@ -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);
Signature · 1 line
2.39.2