Skip to contentSkip to conversation

workqueue: Kick a worker based on the actual activation of delayed works

PATCH Applied Yunfeng Ye 3 participants 3 messages Nov 19, 2020 – Nov 25, 2020 Workqueue

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

PATCH v2 1/1 workqueue: Kick a worker based on the actual activation of delayed works

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's wq when invoking alloc_workqueue(). this patch only kick a worker based on the actual activation of delayed works.

---
 kernel/workqueue.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/workqueue.c +11 -3
index c41c3c17b86a..b3c9d6ef7c69 100644
@@ -3725,17 +3725,25 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
 	 * is updated and visible.
 	 */
 	if (!freezable || !workqueue_freezing) {
+		bool kick = false;
+
 		pwq->max_active = wq->saved_max_active;
 
 		while (!list_empty(&pwq->delayed_works) &&
-		       pwq->nr_active < pwq->max_active)
+		       pwq->nr_active < pwq->max_active) {
 			pwq_activate_first_delayed(pwq);
+			kick = true;
+		}
 
 		/*
 		 * 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. But in realtime scenario, kick a
+		 * worker always will have interference on the isolated
+		 * cpu cores. So do it only based on the actual activation
+		 * of delayed works.
 		 */
-		wake_up_worker(pwq->pool);
+		if (kick)
+			wake_up_worker(pwq->pool);
 	} else {
 		pwq->max_active = 0;
 	}
Signature · 1 line
2.18.4
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Yunfeng Ye

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"

Quoted 5 lines

So it is unnecessary to kick a kworker for percpu's wq when invoking alloc_workqueue(). this patch only kick a worker based on the actual activation of delayed works.

Quoted 39 lines
---
 kernel/workqueue.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/workqueue.c +11 -4
index c41c3c17b86a..b3c9d6ef7c69 100644
@@ -3725,17 +3725,25 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
         * is updated and visible.
         */
        if (!freezable || !workqueue_freezing) {
+               bool kick = false;
+
                pwq->max_active = wq->saved_max_active;
 
                while (!list_empty(&pwq->delayed_works) &&
-                      pwq->nr_active < pwq->max_active)
+                      pwq->nr_active < pwq->max_active) {
                        pwq_activate_first_delayed(pwq);
+                       kick = true;
+               }
 
                /*
                 * 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. But in realtime scenario, kick a
+                * worker always will have interference on the isolated
+                * cpu cores. So do it only based on the actual activation
+                * of delayed works.
                 */
-               wake_up_worker(pwq->pool);
+               if (kick)
+                       wake_up_worker(pwq->pool);
        } else {
                pwq->max_active = 0;
        }
--

2.18.4

maintainer Applied
#2 lore raw
In reply to Yunfeng Ye
Quoted 12 lines · Yunfeng Ye

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"

Quoted 5 lines

So it is unnecessary to kick a kworker for percpu's wq when invoking alloc_workqueue(). this patch only kick a worker based on the actual activation of delayed works.

Applied to wq/for-5.10-fixes w/ minor comment updates.

Thanks.

Signature · 1 line
tejun