public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
	Breno Leitao <leitao@debian.org>, Rik van Riel <riel@surriel.com>,
	Anhad Jai Singh <ffledgling@meta.com>,
	Oleg Nesterov <oleg@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Chris Mason <clm@fb.com>, "Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH misc 1/2] workqueue: Add check for clocks going backwards to wq_worker_tick()
Date: Thu,  1 Aug 2024 17:30:45 -0700	[thread overview]
Message-ID: <20240802003046.4134043-1-paulmck@kernel.org> (raw)
In-Reply-To: <d70d1654-fed2-477f-8f4f-f81322784f17@paulmck-laptop>

Experimental, might never go to mainline.

There has been some evidence of clocks going backwards, producing
"workqueue: kfree_rcu_monitor hogged CPU" diagnostics on idle systems
just after a change in clocksource.  This diagnostic commit checks for
this, ignoring differences that would be negative if interpreted as a
signed 64-bit integer.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Rik van Riel <riel@surriel.com>
---
 kernel/workqueue.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 1745ca788ede3..4f7b4b32e6b4e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1482,6 +1482,7 @@ void wq_worker_tick(struct task_struct *task)
 	 * If the current worker is concurrency managed and hogged the CPU for
 	 * longer than wq_cpu_intensive_thresh_us, it's automatically marked
 	 * CPU_INTENSIVE to avoid stalling other concurrency-managed work items.
+	 * If the time is negative, ignore, assuming a backwards clock.
 	 *
 	 * Set @worker->sleeping means that @worker is in the process of
 	 * switching out voluntarily and won't be contributing to
@@ -1491,6 +1492,7 @@ void wq_worker_tick(struct task_struct *task)
 	 * We probably want to make this prettier in the future.
 	 */
 	if ((worker->flags & WORKER_NOT_RUNNING) || READ_ONCE(worker->sleeping) ||
+	    WARN_ON_ONCE((s64)(worker->task->se.sum_exec_runtime - worker->current_at) < 0) ||
 	    worker->task->se.sum_exec_runtime - worker->current_at <
 	    wq_cpu_intensive_thresh_us * NSEC_PER_USEC)
 		return;
-- 
2.40.1


  reply	other threads:[~2024-08-02  0:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02  0:30 [PATCH 0/2] Miscellaneous updates for v6.12' Paul E. McKenney
2024-08-02  0:30 ` Paul E. McKenney [this message]
2024-08-02 16:06   ` [PATCH misc 1/2] workqueue: Add check for clocks going backwards to wq_worker_tick() Rik van Riel
2024-08-02 16:39     ` Paul E. McKenney
2024-08-02  0:30 ` [PATCH misc 2/2] exit: Sleep at TASK_IDLE when waiting for application core dump Paul E. McKenney

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=20240802003046.4134043-1-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=clm@fb.com \
    --cc=ffledgling@meta.com \
    --cc=jiangshanlai@gmail.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=riel@surriel.com \
    --cc=tj@kernel.org \
    --cc=willy@infradead.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