mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <brads@mainlining.org>
To: dennylin0707@gmail.com
Cc: akpm@linux-foundation.org, bsingharora@gmail.com,
	jiang.kun2@zte.com.cn, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, wang.yaxin@zte.com.cn,
	wang.yong12@zte.com.cn, xu.xin@linux.dev, yang.yang29@zte.com.cn
Subject: Re: [PATCH] delayacct: Preserve delay extrema when aggregating taskstats
Date: Wed, 21 Oct 2026 15:54:27 +0100	[thread overview]
Message-ID: <B170F35B-5CEC-4EA8-AA85-92E552F7D74A@mainlining.org> (raw)
In-Reply-To: <20261021010022.85881-1-dennylin0707@gmail.com>

On 21 October 2026 02:00:22 BST, Hungyu Lin <dennylin0707@gmail.com> wrote:
>delayacct_add_tsk() adds each task's statistics to the accumulated TGID
>statistics, but overwrites the delay maxima, minima and peak timestamps.
>Consequently, the last task determines these fields, and a task with no
>recorded delay can erase an earlier task's peak despite a nonzero total.
>
>Keep the largest maximum and its associated timestamp, and combine the
>minima with min_not_zero() since zero denotes an unrecorded delay. Apply
>this to CPU delay and the seven delay types handled by UPDATE_DELAY().
>Single-task queries still start with zeroed statistics and retain the
>task's values.

Hmm.


>
>Fixes: 658eb5ab916d ("delayacct: add delay max to record delay peak")
>Fixes: f65c64f311ee ("delayacct: add delay min to record delay peak")
>Cc: stable@vger.kernel.org
>Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
>---
> kernel/delayacct.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
>diff --git a/kernel/delayacct.c b/kernel/delayacct.c
>index 479e860aff70..ea1424524654 100644
>--- a/kernel/delayacct.c
>+++ b/kernel/delayacct.c
>@@ -12,14 +12,18 @@
> #include <linux/taskstats.h>
> #include <linux/sysctl.h>
> #include <linux/delayacct.h>
>+#include <linux/minmax.h>
> #include <linux/module.h>
> 
> #define UPDATE_DELAY(type) \
> do { \
>-	d->type##_delay_max = tsk->delays->type##_delay_max; \
>-	d->type##_delay_min = tsk->delays->type##_delay_min; \
>-	d->type##_delay_max_ts.tv_sec = tsk->delays->type##_delay_max_ts.tv_sec; \
>-	d->type##_delay_max_ts.tv_nsec = tsk->delays->type##_delay_max_ts.tv_nsec; \
>+	if (tsk->delays->type##_delay_max > d->type##_delay_max) { \
>+		d->type##_delay_max = tsk->delays->type##_delay_max; \
>+		d->type##_delay_max_ts.tv_sec = tsk->delays->type##_delay_max_ts.tv_sec; \
>+		d->type##_delay_max_ts.tv_nsec = tsk->delays->type##_delay_max_ts.tv_nsec; \
>+	} \
>+	d->type##_delay_min = min_not_zero(d->type##_delay_min, \
>+					 tsk->delays->type##_delay_min); \
> 	tmp = d->type##_delay_total + tsk->delays->type##_delay; \
> 	d->type##_delay_total = (tmp < d->type##_delay_total) ? 0 : tmp; \
> 	d->type##_count += tsk->delays->type##_count; \
>@@ -174,10 +178,13 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
> 
> 	d->cpu_count += t1;
> 
>-	d->cpu_delay_max = tsk->sched_info.max_run_delay;
>-	d->cpu_delay_min = tsk->sched_info.min_run_delay;
>-	d->cpu_delay_max_ts.tv_sec = tsk->sched_info.max_run_delay_ts.tv_sec;
>-	d->cpu_delay_max_ts.tv_nsec = tsk->sched_info.max_run_delay_ts.tv_nsec;
>+	if (tsk->sched_info.max_run_delay > d->cpu_delay_max) {
>+		d->cpu_delay_max = tsk->sched_info.max_run_delay;
>+		d->cpu_delay_max_ts.tv_sec = tsk->sched_info.max_run_delay_ts.tv_sec;
>+		d->cpu_delay_max_ts.tv_nsec = tsk->sched_info.max_run_delay_ts.tv_nsec;
>+	}
>+	d->cpu_delay_min = min_not_zero(d->cpu_delay_min,
>+					tsk->sched_info.min_run_delay);
> 	tmp = (s64)d->cpu_delay_total + t2;

Makes sense, thanks

Reviewed-by: Bradley Morgan <brads@mainlining.org>

> 	d->cpu_delay_total = (tmp < (s64)d->cpu_delay_total) ? 0 : tmp;
> 	tmp = (s64)d->cpu_run_virtual_total + t3;
>


--- Thanks!
"I'm not a very positive person" - Linus torvalds

      reply	other threads:[~2026-10-21 14:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  1:00 Hungyu Lin
2026-10-21 14:54 ` Bradley Morgan [this message]

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=B170F35B-5CEC-4EA8-AA85-92E552F7D74A@mainlining.org \
    --to=brads@mainlining.org \
    --cc=akpm@linux-foundation.org \
    --cc=bsingharora@gmail.com \
    --cc=dennylin0707@gmail.com \
    --cc=jiang.kun2@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wang.yaxin@zte.com.cn \
    --cc=wang.yong12@zte.com.cn \
    --cc=xu.xin@linux.dev \
    --cc=yang.yang29@zte.com.cn \
    /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®