From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: jiangshanlai@gmail.com, torvalds@linux-foundation.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com,
Hillf Danton <hdanton@sina.com>
Subject: Re: [PATCH 4/6] workqueue: Automatically mark CPU-hogging work items CPU_INTENSIVE
Date: Wed, 10 May 2023 17:09:46 +0200 [thread overview]
Message-ID: <20230510150946.GO4253@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20230510030752.542340-5-tj@kernel.org>
On Tue, May 09, 2023 at 05:07:50PM -1000, Tejun Heo wrote:
> @@ -976,24 +981,54 @@ void notrace wq_worker_stopping(struct task_struct *task, bool voluntary)
>
> pool = worker->pool;
>
> - /* Return if preempted before wq_worker_running() was reached */
> - if (worker->sleeping)
> - return;
> + if (!voluntary || task_is_running(task)) {
> + /*
> + * Concurrency-managed @worker is still RUNNING. See if the
> + * current work is hogging CPU stalling other per-cpu work
> + * items. If so, mark @worker CPU_INTENSIVE to exclude it from
> + * concurrency management. @worker->current_* are stable as they
> + * can only be modified by @task which is %current.
> + */
> + if (!worker->current_work ||
> + task->se.sum_exec_runtime - worker->current_at <
> + wq_cpu_intensive_thresh_us * NSEC_PER_USEC)
> + return;
>
> @@ -2348,6 +2382,7 @@ __acquires(&pool->lock)
> worker->current_work = work;
> worker->current_func = work->func;
> worker->current_pwq = pwq;
> + worker->current_at = worker->task->se.sum_exec_runtime;
That only gets updated at scheduling events, it's not a 'running' clock.
> work_data = *work_data_bits(work);
> worker->current_color = get_work_color(work_data);
>
Anyway, it occurs to me that if all you want is to measure long running
works, then would it not be much easier to simply forward the tick?
Something like the below.. Then this tick handler (which will have just
updated ->sum_exec_runtime BTW) can do that above 'work-be-long-running'
check.
Or am I missing something? Seems simpler than hijacking preempt-out.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 944c3ae39861..3484cada9a4a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5632,6 +5632,9 @@ void scheduler_tick(void)
perf_event_task_tick();
+ if (curr->flags & PF_WQ_WORKER)
+ wq_worker_tick(curr);
+
#ifdef CONFIG_SMP
rq->idle_balance = idle_cpu(cpu);
trigger_load_balance(rq);
next prev parent reply other threads:[~2023-05-10 15:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 3:07 [PATCHSET v2 wq/for-6.5] workqueue: Implement automatic CPU intensive detection and add monitoring Tejun Heo
2023-05-10 3:07 ` [PATCH 1/6] workqueue, sched: Notify workqueue of scheduling of RUNNING and preempted tasks Tejun Heo
2023-05-10 3:07 ` [PATCH 2/6] workqueue: Re-order struct worker fields Tejun Heo
2023-05-10 3:07 ` [PATCH 3/6] workqueue: Move worker_set/clr_flags() upwards Tejun Heo
2023-05-10 14:30 ` Linus Torvalds
2023-05-10 18:18 ` Tejun Heo
2023-05-10 3:07 ` [PATCH 4/6] workqueue: Automatically mark CPU-hogging work items CPU_INTENSIVE Tejun Heo
2023-05-10 15:09 ` Peter Zijlstra [this message]
2023-05-10 16:08 ` Tejun Heo
2023-05-10 3:07 ` [PATCH 5/6] workqueue: Report work funcs that trigger automatic CPU_INTENSIVE mechanism Tejun Heo
2023-05-10 3:07 ` [PATCH 6/6] workqueue: Add pwq->stats[] and a monitoring script Tejun Heo
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=20230510150946.GO4253@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=hdanton@sina.com \
--cc=jiangshanlai@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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