All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: Re: [PATCH v2] clocksource/drivers/sh_cmt: Always leave device running after probe
Date: Sun, 9 Nov 2025 15:37:08 +0100	[thread overview]
Message-ID: <20251109143708.GD4126953@ragnatech.se> (raw)
In-Reply-To: <c4377971-173a-4af9-8566-24e5860787ae@linaro.org>

Hi Daniel,

On 2025-11-07 10:53:41 +0100, Daniel Lezcano wrote:
> On 11/5/25 19:32, Niklas Söderlund wrote:
> > Hi Daniel,
> > 
> > Thanks for your feedback.
> > 
> > On 2025-11-05 17:39:14 +0100, Daniel Lezcano wrote:
> > > On 11/5/25 17:06, Niklas Söderlund wrote:
> > > > On 2025-11-05 16:36:15 +0100, Daniel Lezcano wrote:
> > > > > On 10/16/25 20:20, Niklas Söderlund wrote:
> > > > > > The CMT device can be used as both a clocksource and a clockevent
> > > > > > provider. The driver tries to be smart and power itself on and off, as
> > > > > > well as enabling and disabling its clock when it's not in operation.
> > > > > > This behavior is slightly altered if the CMT is used as an early
> > > > > > platform device in which case the device is left powered on after probe,
> > > > > > but the clock is still enabled and disabled at runtime.
> > > > > > 
> > > > > > This has worked for a long time, but recent improvements in PREEMPT_RT
> > > > > > and PROVE_LOCKING have highlighted an issue. As the CMT registers itself
> > > > > > as a clockevent provider, clockevents_register_device(), it needs to use
> > > > > > raw spinlocks internally as this is the context of which the clockevent
> > > > > > framework interacts with the CMT driver. However in the context of
> > > > > > holding a raw spinlock the CMT driver can't really manage its power
> > > > > > state or clock with calls to pm_runtime_*() and clk_*() as these calls
> > > > > > end up in other platform drivers using regular spinlocks to control
> > > > > > power and clocks.
> > > > > 
> > > > > So the fix is to remove PM management in the driver ?
> > > > 
> > > > Yes. As I understand it we can't do runtime pm in these drivers as the
> > > > core calls into the functions with the raw spinlock held. I hope we can
> > > > improve this in future.
> > > 
> > > 
> > > IIUC, the changes done for PREEMPT_RT prevent to use pm_runtime by functions
> > > running in atomic context because the spinlocks are actually mutexes.
> > 
> > My understanding is that the core issue is that the clockevent core uses
> > raw spinlocks, so all operations done from the callbacks in drivers need
> > to use them too.
> > 
> > The Renesas CMT and TMU (which I intend to fix too once we find a way
> > forward for CMT) are the only clockenvet drivers attempting to do
> > runtime pm.
> > 
> >      $ git grep -l pm_runtime_get -- drivers/clocksource
> >      drivers/clocksource/sh_cmt.c
> >      drivers/clocksource/sh_mtu2.c
> >      drivers/clocksource/sh_tmu.c
> >      drivers/clocksource/timer-ti-dm.c
> > 
> > The timer-ti-dm.c driver do not register a clockevent device.
> > 
> > > 
> > > But if PREEMPT_RT is not set, then everything is running as usual.
> > 
> > I still get LOCKDEP warnings.
> 
> Ah ok, you get the LOCKDEP warning because it identifies the called code to
> be invalid in case the PREEMPT_RT is compiled-in but does not reflect a real
> problem with !PREEMPT_RT.
> 
> [ ... ]
> 
> > The problem is not really PREEMPT_RT. The problem is the clockevents
> > core require drivers to use raw spinlocks as itself uses them.
> > 
> > I would prefer to get the driver in a state without splats, warnings and
> > potential PREEMPT_RT issues. Especially if the cost is to disable
> > runtime pm.
> > 
> > As I understand it most systems where CMT exists, who don't use it, keep
> > them disabled in DT. And the devices that use them have
> > is_sh_early_platform_device() set so they already disable runtime pm.
> > 
> > Once we have that fixed we can work on enabling it without the quirks.
> > In your opinion am I missing something where this approach is a bad idea?
> 
> If you prefer to remove the PM in the driver, I'm fine with that.

I'm not super fond of removing it, but for now I think it is the best 
way to ensure correct operation in all cases. If anybody have ideas I'm 
all ears. Specially as I will need to do a similar fix for the TMU 
driver once we have found a acceptable way for CMT.

Once we I'm out of the woods and not worried about whats currently in 
tree can have issues I think it's time to start thinking, if and how we 
can improve tings in the core so we can enable some or all of the PM CMT 
and TMU.

I really appreciate you pushed back on this, I agree removing runtime PM 
support is kind of a last resort here. But I see no other path.
> 
> 
> -- 
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
> 
> Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog

-- 
Kind Regards,
Niklas Söderlund

  reply	other threads:[~2025-11-09 14:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 18:20 [PATCH v2] clocksource/drivers/sh_cmt: Always leave device running after probe Niklas Söderlund
2025-11-05 15:36 ` Daniel Lezcano
2025-11-05 16:06   ` Niklas Söderlund
2025-11-05 16:39     ` Daniel Lezcano
2025-11-05 18:32       ` Niklas Söderlund
2025-11-07  9:53         ` Daniel Lezcano
2025-11-09 14:37           ` Niklas Söderlund [this message]
2025-11-18 20:18             ` Niklas Söderlund
2025-11-18 20:26               ` Daniel Lezcano
2025-11-18 20:29                 ` Niklas Söderlund
2025-11-18 20:30                   ` Daniel Lezcano
2025-11-26 14:40 ` [tip: timers/clocksource] " tip-bot2 for Niklas Söderlund

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=20251109143708.GD4126953@ragnatech.se \
    --to=niklas.soderlund+renesas@ragnatech.se \
    --cc=daniel.lezcano@linaro.org \
    --cc=geert+renesas@glider.be \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.