Skip to contentSkip to conversation

workqueue: Introduce show_freeze_workqueues_busy

PATCH In review Jungseung Lee 2 participants 3 messages Mar 15, 2023 – Mar 20, 2023 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20230315130515epcas1p40823f20da586c1b5813b41e66e754309@epcas1p4.samsung.com

#1 lore raw

PATCH 1/1 workqueue: Introduce show_freeze_workqueues_busy

Currently show_all_workqueue() is called if freeze fails at the time of freeze the workqueues, which shows the status of all workqueues and of all worker pools. In this cases we may only need to dump state of only workqueues that are freezable and busy.

This patch defines show_freeze_workqueues_busy, which uses show_one_workqueue, a granular function that shows the state of individual workqueues, so that dump only the state of freezable workqueues at that time.

---
 include/linux/workqueue.h |  1 +
 kernel/power/process.c    |  2 +-
 kernel/workqueue.c        | 25 ++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)
include/linux/workqueue.h +1 -0
index 0a10f8e..3d68631 100644
@@ -472,6 +472,7 @@ extern unsigned int work_busy(struct work_struct *work);
 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
 extern void print_worker_info(const char *log_lvl, struct task_struct *task);
 extern void show_all_workqueues(void);
+extern void show_freeze_workqueues_busy(void);
 extern void show_one_workqueue(struct workqueue_struct *wq);
 extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task);
 
kernel/power/process.c +1 -1
index 6c1c7e5..590550f 100644
@@ -93,7 +93,7 @@ static int try_to_freeze_tasks(bool user_only)
 		       todo - wq_busy, wq_busy);
 
 		if (wq_busy)
-			show_all_workqueues();
+			show_freeze_workqueues_busy();
 
 		if (!wakeup || pm_debug_messages_on) {
 			read_lock(&tasklist_lock);
kernel/workqueue.c +24 -1
index de42827..087eedb 100644
@@ -5043,7 +5043,7 @@ static void show_one_worker_pool(struct worker_pool *pool)
 /**
  * show_all_workqueues - dump workqueue state
  *
- * Called from a sysrq handler or try_to_freeze_tasks() and prints out
+ * Called from a sysrq handler and prints out
  * all busy workqueues and pools.
  */
 void show_all_workqueues(void)
@@ -5065,6 +5065,29 @@ void show_all_workqueues(void)
 	rcu_read_unlock();
 }
 
+/**
+ * show_freeze_workqueues_busy - dump freezable workqueue state
+ *
+ * Called from try_to_freeze_tasks() and prints out
+ * all freezable workqueues still busy.
+ */
+void show_freeze_workqueues_busy(void)
+{
+	struct workqueue_struct *wq;
+
+	rcu_read_lock();
+
+	pr_info("Showing freezable workqueues still busy:\n");
+
+	list_for_each_entry_rcu(wq, &workqueues, list) {
+		if (!(wq->flags & WQ_FREEZABLE))
+			continue;
+		show_one_workqueue(wq);
+	}
+
+	rcu_read_unlock();
+}
+
 /* used to show worker information through /proc/PID/{comm,stat,status} */
 void wq_worker_comm(char *buf, size_t size, struct task_struct *task)
 {
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Hello,

A few nits.

kernel/power/process.c static int try_to_freeze_tasks(bool user_only) · line 96

Quoted 10 lines · Jungseung Lee
kernel/power/process.c +1 -1
index 6c1c7e5..590550f 100644
@@ -93,7 +93,7 @@ static int try_to_freeze_tasks(bool user_only)
 		       todo - wq_busy, wq_busy);
 
 		if (wq_busy)
-			show_all_workqueues();
+			show_freeze_workqueues_busy();

Maybe name this show_freezable_workqueues()?

kernel/power/process.c static void show_one_worker_pool(struct worker_pool *pool) · line 5047

Quoted 7 lines
kernel/power/process.c +1 -1
@@ -5043,7 +5043,7 @@ static void show_one_worker_pool(struct worker_pool *pool)
 /**
  * show_all_workqueues - dump workqueue state
  *
- * Called from a sysrq handler or try_to_freeze_tasks() and prints out
+ * Called from a sysrq handler and prints out
  * all busy workqueues and pools.

Can you reflow the comment to 80-col?

kernel/power/process.c static void show_one_worker_pool(struct worker_pool *pool)

Quoted 5 lines
kernel/power/process.c +5 -0
+/**
+ * show_freeze_workqueues_busy - dump freezable workqueue state
+ *
+ * Called from try_to_freeze_tasks() and prints out
+ * all freezable workqueues still busy.

Ditto.

Thanks.

Signature · 1 line
tejun
#3 lore raw

Hi, Tejun

Quoted 41 lines

-----Original Message-----
From: Tejun Heo <[email protected]> On Behalf Of Tejun Heo
Sent: Saturday, March 18, 2023 7:16 AM
To: Jungseung Lee <[email protected]>
Cc: Lai Jiangshan <[email protected]>; Rafael J. Wysocki <[email protected]>; Pavel Machek <[email protected]>; Len Brown <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] workqueue: Introduce show_freeze_workqueues_busy

Hello,

A few nits.

kernel/power/process.c static int try_to_freeze_tasks(bool user_only) · line 96

Quoted 10 lines · Jungseung Lee
kernel/power/process.c index renamed from kernel/power/process.c +0 -0

6c1c7e5..590550f 100644

kernel/power/process.c +1 -1
@@ -93,7 +93,7 @@ static int try_to_freeze_tasks(bool user_only)
 		       todo - wq_busy, wq_busy);
 
 		if (wq_busy)
-			show_all_workqueues();
+			show_freeze_workqueues_busy();

Maybe name this show_freezable_workqueues()?

Quoted 9 lines
kernel/power/process.c +0 -1
@@ -5043,7 +5043,7 @@ static void show_one_worker_pool(struct
 worker_pool *pool)
 /**
  * show_all_workqueues - dump workqueue state
  *
- * Called from a sysrq handler or try_to_freeze_tasks() and prints

out
+ * Called from a sysrq handler and prints out
* all busy workqueues and pools.

Can you reflow the comment to 80-col?

Quoted 8 lines
Quoted 5 lines

+/**
+ * show_freeze_workqueues_busy - dump freezable workqueue state
+ *
+ * Called from try_to_freeze_tasks() and prints out
+ * all freezable workqueues still busy.

Ditto.

Thank you for the review and I will send a new patch including what you mentioned soon

Thanks,

Quoted 4 lines

Thanks.

--
tejun