[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250625115643.GE1613376@noisy.programming.kicks-ass.net>
Date: Wed, 25 Jun 2025 13:56:43 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Boqun Feng <boqun.feng@...il.com>
Cc: linux-kernel@...r.kernel.org, rcu@...r.kernel.org, lkmm@...ts.linux.dev,
Ingo Molnar <mingo@...nel.org>, Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>,
Davidlohr Bueso <dave@...olabs.net>,
"Paul E. McKenney" <paulmck@...nel.org>,
Josh Triplett <josh@...htriplett.org>,
Frederic Weisbecker <frederic@...nel.org>,
Neeraj Upadhyay <neeraj.upadhyay@...nel.org>,
Joel Fernandes <joelagnelf@...dia.com>,
Uladzislau Rezki <urezki@...il.com>,
Steven Rostedt <rostedt@...dmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Lai Jiangshan <jiangshanlai@...il.com>,
Zqiang <qiang.zhang@...ux.dev>, Breno Leitao <leitao@...ian.org>,
aeh@...a.com, netdev@...r.kernel.org, edumazet@...gle.com,
jhs@...atatu.com, kernel-team@...a.com,
Erik Lundgren <elundgren@...a.com>
Subject: Re: [PATCH 4/8] shazptr: Avoid synchronize_shaptr() busy waiting
Response is a bit weird because non-linear editing..
On Tue, Jun 24, 2025 at 08:10:57PM -0700, Boqun Feng wrote:
> + /* Whether the scan kthread has been scheduled to scan */
> + bool scheduled;
> +static int __noreturn shazptr_scan_kthread(void *unused)
> +{
> + for (;;) {
> + swait_event_idle_exclusive(shazptr_scan.wq,
> + READ_ONCE(shazptr_scan.scheduled));
This seems weird; why use a whole wait-queue, in exclusive mode no less,
for something that is one known thread.
Also, I think this thing needs to be FREEZABLE, otherwise suspend might
have issues.
Why not just write it like:
for (;;) {
set_current_state(TASK_IDLE | TASK_FREEZABLE);
if (!list_empty(&scan->queue))
break;
schedule();
}
__set_current_state(TASK_RUNNABLE);
for (;;) {
scoped_guard (mutex, scan->lock) {
if (list_empty(scan->queued) &&
list_empty(scan->scanning))
break;
}
shazptr_do_scan(scan);
}
> + shazptr_do_scan(&shazptr_scan);
> +
> + scoped_guard(mutex, &shazptr_scan.lock) {
> + if (list_empty(&shazptr_scan.queued) &&
> + list_empty(&shazptr_scan.scanning))
> + shazptr_scan.scheduled = false;
This condition, why can't we directly use this condition instead of
scheduled?
> + }
> + }
> +}
> +static void synchronize_shazptr_normal(void *ptr)
> +{
> +
> + /* Found blocking slots, prepare to wait. */
> + if (blocking_grp_mask) {
> + struct shazptr_scan *scan = &shazptr_scan;
> + struct shazptr_wait wait = {
> + .blocking_grp_mask = blocking_grp_mask,
> + };
> +
> + INIT_LIST_HEAD(&wait.list);
> + init_completion(&wait.done);
> +
> + scoped_guard(mutex, &scan->lock) {
> + list_add_tail(&wait.list, &scan->queued);
> +
> + if (!scan->scheduled) {
> + WRITE_ONCE(scan->scheduled, true);
> + swake_up_one(&shazptr_scan.wq);
> + }
Or perhaps; just write this like:
bool was_empty = list_empty(&scan->queued);
list_add_tail(&wait.list, &scan->queued);
if (was_empty)
wake_up_process(scan->thread);
> + }
> +
> + wait_for_completion(&wait.done);
> + }
> +}
Powered by blists - more mailing lists