public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: shengminghu512 <shengminghu512@qq.com>
Cc: akpm <akpm@linux-foundation.org>, tglx <tglx@linutronix.de>,
	mingo <mingo@kernel.org>, broonie <broonie@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"hu.shengming" <hu.shengming@zte.com.cn>,
	"zhang.run" <zhang.run@zte.com.cn>
Subject: Re: [PATCH] watchdog/softlockup: Fix sample ring index wrap in need_counting_irqs()
Date: Wed, 28 Jan 2026 18:52:11 +0100	[thread overview]
Message-ID: <aXpMy67Ra5ejKVnm@pathway.suse.cz> (raw)
In-Reply-To: <tencent_7068189CB6D6689EB353F3D17BF5A5311A07@qq.com>

On Mon 2026-01-19 21:59:05, shengminghu512 wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
> 
> cpustat_tail indexes cpustat_util[], which is a NUM_SAMPLE_PERIODS-sized
> ring buffer. need_counting_irqs() currently wraps the index using
> NUM_HARDIRQ_REPORT, which only happens to match NUM_SAMPLE_PERIODS.
> 
> Use NUM_SAMPLE_PERIODS for the wrap to keep the ring math correct even if
> the NUM_HARDIRQ_REPORT or  NUM_SAMPLE_PERIODS changes.
> 
> ---
>  kernel/watchdog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/watchdog.c b/kernel/watchdog.c
> index b4d5fbdb9..7d675781b 100644
> --- a/kernel/watchdog.c
> +++ b/kernel/watchdog.c
> @@ -550,7 +550,7 @@ static bool need_counting_irqs(void)
>  	u8 util;
>  	int tail = __this_cpu_read(cpustat_tail);
>  
> -	tail = (tail + NUM_HARDIRQ_REPORT - 1) % NUM_HARDIRQ_REPORT;
> +	tail = (tail + NUM_SAMPLE_PERIODS - 1) % NUM_SAMPLE_PERIODS;
>  	util = __this_cpu_read(cpustat_util[tail][STATS_HARDIRQ]);
>  	return util > HARDIRQ_PERCENT_THRESH;

Great catch! It makes perfect sense.

The NUM_HARDIRQ_REPORT is used for another array (irq_counts_sorted[])
with the most frequent IRQs. This code was added with the same commit
which added the other array. It would explain the mistake.

Reviewed-by: Petr Mladek <pmladek@suse.com>

Andrew, I assume that you would take it...

Best Regards,
Petr









>  }
> -- 
> 2.25.1
> 

  reply	other threads:[~2026-01-28 17:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-19 13:59 [PATCH] watchdog/softlockup: Fix sample ring index wrap in need_counting_irqs() shengminghu512
2026-01-28 17:52 ` Petr Mladek [this message]
2026-01-28 18:13   ` Andrew Morton
2026-01-29  9:42     ` Petr Mladek
  -- strict thread matches above, loose matches on Subject: below --
2026-01-18  9:14 shengminghu512

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=aXpMy67Ra5ejKVnm@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=broonie@kernel.org \
    --cc=hu.shengming@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=shengminghu512@qq.com \
    --cc=tglx@linutronix.de \
    --cc=zhang.run@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