mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunfeng Ye <yeyunfeng@huawei.com>
To: <tj@kernel.org>, <jiangshanlai@gmail.com>,
	<linux-kernel@vger.kernel.org>
Cc: Shiyuan Hu <hushiyuan@huawei.com>, Hewenliang <hewenliang4@huawei.com>
Subject: workqueue: Only kick a worker after thawed or for an unbound workqueue
Date: Tue, 17 Nov 2020 15:32:56 +0800	[thread overview]
Message-ID: <aaa87d62-b89d-e241-1a6e-01176694616f@huawei.com> (raw)

In realtime scenario, We do not want to have interference on the
isolated cpu cores. but when invoking alloc_workqueue() for percpu wq
on the housekeeping cpu, it kick a kworker on the isolated cpu.

  alloc_workqueue
    pwq_adjust_max_active
      wake_up_worker

The comment in pwq_adjust_max_active() said:
  "Need to kick a worker after thawed or an unbound wq's
   max_active is bumped"

So it is unnecessary to kick a kworker for percpu wq's when
alloc_workqueue. this patch only kick a worker after thawed or for an
unbound workqueue.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 kernel/workqueue.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c41c3c17b86a..80f7bbd4889f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3696,14 +3696,16 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
 }

 /**
- * pwq_adjust_max_active - update a pwq's max_active to the current setting
+ * pwq_adjust_max_active_and_kick - update a pwq's max_active to the current setting
  * @pwq: target pool_workqueue
+ * @force_kick: force to kick a worker
  *
  * If @pwq isn't freezing, set @pwq->max_active to the associated
  * workqueue's saved_max_active and activate delayed work items
  * accordingly.  If @pwq is freezing, clear @pwq->max_active to zero.
  */
-static void pwq_adjust_max_active(struct pool_workqueue *pwq)
+static void pwq_adjust_max_active_and_kick(struct pool_workqueue *pwq,
+					bool force_kick)
 {
 	struct workqueue_struct *wq = pwq->wq;
 	bool freezable = wq->flags & WQ_FREEZABLE;
@@ -3733,9 +3735,10 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)

 		/*
 		 * Need to kick a worker after thawed or an unbound wq's
-		 * max_active is bumped.  It's a slow path.  Do it always.
+		 * max_active is bumped.
 		 */
-		wake_up_worker(pwq->pool);
+		if (force_kick || (wq->flags & WQ_UNBOUND))
+			wake_up_worker(pwq->pool);
 	} else {
 		pwq->max_active = 0;
 	}
@@ -3743,6 +3746,11 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
 	raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
 }

+static void pwq_adjust_max_active(struct pool_workqueue *pwq)
+{
+	pwq_adjust_max_active_and_kick(pwq, false);
+}
+
 /* initialize newly alloced @pwq which is associated with @wq and @pool */
 static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq,
 		     struct worker_pool *pool)
@@ -5252,7 +5260,7 @@ void thaw_workqueues(void)
 	list_for_each_entry(wq, &workqueues, list) {
 		mutex_lock(&wq->mutex);
 		for_each_pwq(pwq, wq)
-			pwq_adjust_max_active(pwq);
+			pwq_adjust_max_active_and_kick(pwq, true);
 		mutex_unlock(&wq->mutex);
 	}

-- 
2.18.4

             reply	other threads:[~2020-11-17  7:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17  7:32 Yunfeng Ye [this message]
2020-11-18  4:06 ` Lai Jiangshan
2020-11-18  6:26   ` Yunfeng Ye
2020-11-18  9:05     ` Yunfeng Ye
2020-11-19  1:58       ` Lai Jiangshan
2020-11-19  2:25         ` Yunfeng Ye

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=aaa87d62-b89d-e241-1a6e-01176694616f@huawei.com \
    --to=yeyunfeng@huawei.com \
    --cc=hewenliang4@huawei.com \
    --cc=hushiyuan@huawei.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.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

all inboxes | Powered by JetHome®