Devicetree
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev, conor+dt@kernel.org,
	wsa+renesas@sang-engineering.com, robh@kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v5 2/4] clocksource/drivers: Add support for the Renesas RZ/N1 timers
Date: Tue, 29 Sep 2026 10:43:20 +0200	[thread overview]
Message-ID: <20260929104320.0e6eeadc@bootlin.com> (raw)
In-Reply-To: <20260911151837.709F41F000FF@smtp.kernel.org>

Hi,

On Fri, 11 Sep 2026 15:18:37 +0000
sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] The 16-bit per-CPU timers will never be chosen over the arch timer due to their low rating, resulting in asymmetrical per-CPU tick devices.
> - [Medium] Clocksource and sched_clock return raw decreasing values if the timer is a down-counter.
> --
> 
> commit 0389aacef8150cde2d480116d05b7b23c573015b
> Author: Herve Codina (Schneider Electric) <herve.codina@bootlin.com>
> 
> clocksource/drivers: Add support for the Renesas RZ/N1 timers
> 
> The Renesas RZ/N1 timer block controller is the controller in charge of
> timers available in the Renesas RZ/N1 SoCs family. This controller handles
> 8 timers (6 16-bit, 2 32-bit). Each timer has its own interrupt and prescaler.
> 
> > diff --git a/drivers/clocksource/timer-rzn1.c b/drivers/clocksource/timer-rzn1.c
> > new file mode 100644
> > index 0000000000000..a66a045309f63
> > --- /dev/null
> > +++ b/drivers/clocksource/timer-rzn1.c  
> 
> [ ... ]
> 
> > +static u64 notrace rzn1_sched_read(void)
> > +{
> > +	return readl_relaxed(rzn1_sched_clock->base + RZN1_TIMER_CURRENT_COUNT_REG);
> > +}
> > +
> > +static u64 rzn1_clksrc_read(struct clocksource *cs)
> > +{
> > +	return readl_relaxed(rzn1_sched_clock->base + RZN1_TIMER_CURRENT_COUNT_REG);
> > +}  
> 
> [Severity: Medium]
> If the timer is a down-counter, will these functions return a decreasing value?
> 
> The clocksource and sched_clock cores require monotonically increasing values.
> If the timer counts down, returning the raw value could cause the
> (now - last) & mask calculation to yield large forward time jumps, breaking
> system timekeeping and scheduling.

Timers available in the hardware increases their counter.

These functions return increasing values.

> 
> [ ... ]
> 
> > +static int rzn1_local_timer_starting_cpu(unsigned int cpu)
> > +{
> > +	struct rzn1_timer *timer;
> > +
> > +	/* We assign the first and second 16-bit timer as per-cpu timers. */
> > +	if (cpu >= 2)
> > +		return 0;
> > +
> > +	timer = &rzn1_tab_timers[cpu + RZN1_TIMER_BASE_INDEX_16BIT_TIMERS];  
> 
> [ ... ]
> 
> > +static void rzn1_timer_clkevt_init_ced(struct rzn1_timer *timer, const char *name,
> > +				       int irq)
> > +{  
> 
> [ ... ]
> 
> > +	/*
> > +	 * 32-bit timers are fed with a 25 MHz clock directly derived from the
> > +	 * main PLL (1 GHz). The arch timer, ARMv7 CP15 in RZ/N1 SoCs, is fed
> > +	 * with to a 6.25 MHz clock.
> > +	 *
> > +	 * The clock of the RZ/N1 timers block is a stable one and the RZ/N1
> > +	 * timers have a higher resolution than the ARM CP15 one.
> > +	 *
> > +	 * Also those 32-bit RZ/N1 timers are assigned per-cpu.
> > +	 *
> > +	 * Use a high rating for the 32-bit RZ/N1 timers in order to have them
> > +	 * chosen by the system.
> > +	 */
> > +	timer->ced.rating = timer->width == 16 ? 200 : 460;  
> 
> [Severity: High]
> Is it intentional that the 16-bit per-CPU timers are assigned a rating of 200?
> 
> In rzn1_local_timer_starting_cpu(), the 16-bit timers are explicitly assigned
> as the per-CPU tick devices. However, because the ARM arch timer typically has
> a higher rating (400-450), won't the 16-bit timers always be outranked and
> ignored by the clockevents core?
> 
> This appears to contradict the comment stating that 32-bit timers are assigned
> per-cpu, and could leave CPU 1 falling back to the arch timer while CPU 0
> might use the global 32-bit timer, resulting in asymmetrical per-CPU tick
> devices.
> 

First the comment is not fully correct. Only 16-bit timers are registered
per-cpu. I will update the comment in the next series iteration.

We have one 32-bit timer shared between cpu (cpumask set to cpu_possible_mask),
two 16-bit timers per-cpu with cpumask set to the cpu registering the timer in
rzn1_local_timer_starting_cpu().

When timers are registered (calls to clockevents_config_and_register() function),
tick_check_preferred() [1] is called.

This function prefers a local cpu timer even if the local cpu timer has a rating
lower than a shared cpu timer.

With that pointed out, we cannot have asymmetrical per-CPU tick devices.

[1] https://elixir.bootlin.com/linux/v7.3-rc5/source/kernel/time/tick-common.c#L289

Best regards,
Hervé

  reply	other threads:[~2026-09-29  8:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 15:04 [PATCH v5 0/4] timers: Add support for RZ/N1 SoCs timers Herve Codina (Schneider Electric)
2026-09-11 15:04 ` [PATCH v5 1/4] dt-bindings: timer: Add the Renesas RZ/N1 timer Herve Codina (Schneider Electric)
2026-09-11 15:04 ` [PATCH v5 2/4] clocksource/drivers: Add support for the Renesas RZ/N1 timers Herve Codina (Schneider Electric)
2026-09-11 15:18   ` sashiko-bot
2026-09-29  8:43     ` Herve Codina [this message]
2026-09-14  6:39   ` Wolfram Sang
2026-09-14  7:50     ` Miquel Raynal
2026-09-11 15:04 ` [PATCH v5 3/4] ARM: dts: r9a06g032: Add support for timers Herve Codina (Schneider Electric)
2026-09-11 15:04 ` [PATCH v5 4/4] MAINTAINERS: Add the Renesas RZ/N1 timers driver entry Herve Codina (Schneider Electric)

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=20260929104320.0e6eeadc@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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