linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: qiang.zhang@windriver.com
To: rafael.j.wysocki@intel.com, len.brown@intel.com, pavel@ucw.cz,
	paulmck@kernel.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] PM: sleep: Replace read_lock/unlock(tasklist_lock) with rcu_read_lock/unlock()
Date: Mon,  7 Jun 2021 14:57:43 +0800	[thread overview]
Message-ID: <20210607065743.1596-1-qiang.zhang@windriver.com> (raw)

From: Zqiang <qiang.zhang@windriver.com>

Using rcu_read_lock/unlock() instead of read_lock/unlock(tasklist_lock),
the task list can be traversed in parallel to any list additions or
removals, improve concurrency.

Signed-off-by: Zqiang <qiang.zhang@windriver.com>
---
 kernel/power/process.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/power/process.c b/kernel/power/process.c
index 50cc63534486..0f8dee9ee097 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -48,7 +48,7 @@ static int try_to_freeze_tasks(bool user_only)
 
 	while (true) {
 		todo = 0;
-		read_lock(&tasklist_lock);
+		rcu_read_lock();
 		for_each_process_thread(g, p) {
 			if (p == current || !freeze_task(p))
 				continue;
@@ -56,7 +56,7 @@ static int try_to_freeze_tasks(bool user_only)
 			if (!freezer_should_skip(p))
 				todo++;
 		}
-		read_unlock(&tasklist_lock);
+		rcu_read_unlock();
 
 		if (!user_only) {
 			wq_busy = freeze_workqueues_busy();
@@ -97,13 +97,13 @@ static int try_to_freeze_tasks(bool user_only)
 			show_workqueue_state();
 
 		if (!wakeup || pm_debug_messages_on) {
-			read_lock(&tasklist_lock);
+			rcu_read_lock();
 			for_each_process_thread(g, p) {
 				if (p != current && !freezer_should_skip(p)
 				    && freezing(p) && !frozen(p))
 					sched_show_task(p);
 			}
-			read_unlock(&tasklist_lock);
+			rcu_read_unlock();
 		}
 	} else {
 		pr_cont("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000,
@@ -206,13 +206,13 @@ void thaw_processes(void)
 
 	cpuset_wait_for_hotplug();
 
-	read_lock(&tasklist_lock);
+	rcu_read_lock();
 	for_each_process_thread(g, p) {
 		/* No other threads should have PF_SUSPEND_TASK set */
 		WARN_ON((p != curr) && (p->flags & PF_SUSPEND_TASK));
 		__thaw_task(p);
 	}
-	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 
 	WARN_ON(!(curr->flags & PF_SUSPEND_TASK));
 	curr->flags &= ~PF_SUSPEND_TASK;
@@ -233,12 +233,12 @@ void thaw_kernel_threads(void)
 
 	thaw_workqueues();
 
-	read_lock(&tasklist_lock);
+	rcu_read_lock();
 	for_each_process_thread(g, p) {
 		if (p->flags & PF_KTHREAD)
 			__thaw_task(p);
 	}
-	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 
 	schedule();
 	pr_cont("done.\n");
-- 
2.17.1


             reply	other threads:[~2021-06-07  6:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  6:57 qiang.zhang [this message]
2021-06-07 11:45 ` [PATCH] PM: sleep: Replace read_lock/unlock(tasklist_lock) with rcu_read_lock/unlock() Rafael J. Wysocki
2021-06-07 14:11   ` Zhang, Qiang
2021-06-07 15:41     ` Paul E. McKenney
2021-06-08  2:50       ` Zhang, Qiang
2021-06-08  4:56         ` Paul E. McKenney
2021-06-09  7:04           ` Zhang, Qiang

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=20210607065743.1596-1-qiang.zhang@windriver.com \
    --to=qiang.zhang@windriver.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael.j.wysocki@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).