Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Walter Chang (張維哲)" <Walter.Chang@mediatek.com>
To: "matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"sudeep.holla@arm.com" <sudeep.holla@arm.com>,
	"angelogioacchino.delregno@collabora.com"
	<angelogioacchino.delregno@collabora.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"jstultz@google.com" <jstultz@google.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	wsd_upstream <wsd_upstream@mediatek.com>,
	"daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org>,
	"krzysztof.kozlowski@linaro.org" <krzysztof.kozlowski@linaro.org>,
	"Chun-Hung Wu (巫駿宏)" <Chun-hung.Wu@mediatek.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"Stanley Chu (朱原陞)" <stanley.chu@mediatek.com>,
	"macro@orcam.me.uk" <macro@orcam.me.uk>,
	"Freddy Hsin (辛恒豐)" <Freddy.Hsin@mediatek.com>
Subject: Re: [PATCH v2 4/4] clocksource/drivers/timer-mediatek: Make timer-mediatek become loadable module
Date: Wed, 29 Mar 2023 06:22:57 +0000	[thread overview]
Message-ID: <32777456f8e0f98e4cd5b950f421d21f71b149cf.camel@mediatek.com> (raw)
In-Reply-To: <26c100f2-bf31-7212-5d13-25b6b14b8f61@collabora.com>

On Thu, 2023-02-16 at 12:36 +0100, AngeloGioacchino Del Regno wrote:
> Il 16/02/23 12:23, Matthias Brugger ha scritto:
> > 
> > 
> > On 16/02/2023 11:22, AngeloGioacchino Del Regno wrote:
> > > Il 15/02/23 15:46, Sudeep Holla ha scritto:
> > > > On Wed, Feb 15, 2023 at 02:30:51PM +0100, AngeloGioacchino Del
> > > > Regno wrote:
> > > > > 
> > > > > Both. I mean that these platforms do have architected timers,
> > > > > but they are stopped
> > > > > before the bootloader jumps to the kernel, or they are never
> > > > > started at all.
> > > > > 
> > > > > Please refer to:
> > > > > 
> > > > > 
https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/clocksource/timer-mediatek.c?h=next-20230215&id=327e93cf9a59b0d04eb3a31a7fdbf0f11cf13ecb__;!!CTRNKA9wMg0ARbw!jOX04TQn1HXcKOdzAiK3ZlqsSE3j3p6Zo-Cajr0khXC9ANlbkl8kQrUgx6wadR8b_46o9J0SbJgjhoS03rQ7somJfA5Z9L6G_g$ 
> > > > >  
> > > > > 
> > > > > For a nice explanation.
> > > > > 
> > > > 
> > > > Thanks for that. Well then I see no point in making these
> > > > modules if you
> > > > can't have generic Image that boots on all the platform. I now
> > > > tend to think
> > > > that these are made modules just because GKI demands and it
> > > > *might* work
> > > > on one or 2 platforms. One we move this as modules, how will be
> > > > know the
> > > > Image without these timers or with them built as modules will
> > > > boot or not
> > > > on a given mediatek platform. Sorry, I initially saw some point
> > > > in making
> > > > these timers as modules but if they are required for boot on
> > > > some systems
> > > > then I see no point. So if that is the case, NACK for these as
> > > > it just
> > > > creates more confusion after these are merged as why some
> > > > Images or
> > > > even why defconfig image(if we push the config change as well)
> > > > is not
> > > > booting on these platforms.
> > > > 
> > > > It is no longer just for system timer useful in low power CPU
> > > > idle states
> > > > as I initial thought.
> > > > 
> > > 
> > > I think that there is still a point in modularization for this
> > > driver and I
> > > can propose a rather simple solution, even though this may add
> > > some, rather
> > > little, code duplication to the mix.
> > > 
> > > The platforms that I've described (like mt6795) need the system
> > > timer to be
> > > initialized as early as possible - that's true - but that timer
> > > is always
> > > "CPUXGPT".
> > > 
> > > On those platforms, you *still* have multiple timers:
> > >   - CPUX (short for cpuxgpt), used only as system timer;
> > >   - SYST, as another system timer implementation (additional
> > > timers) but
> > >     those are always initialized (AFAIK) from the bootloader
> > > before booting;
> > >   - GPT (General Purpose Timer).
> > > 
> > > On one SoC, you may have:
> > >   - CPUX *and* SYST
> > >   - CPUX *and* GPT
> > >   - CPUX *and* SYST *and* GPT
> > > 
> > > ... where the only one that is boot critical and needs to be
> > > initialized early
> > > is always only CPUX.
> > > 
> > > Hence this proposal: to still allow modularization of timers on
> > > MediaTek platforms,
> > > we could eventually split the CPUX as a separated driver that
> > > *cannot be*, due to
> > > the previously explained constraints, compiled as module, hence
> > > always built-in,
> > > from a timer-mediatek driver that could be a module and capable
> > > of handling only
> > > SYST and GPT timers.
> > > 
> > > In that case, we'd hence have...
> > >   - timer-mediatek-cpux.o (bool)
> > >   - timer-mediatek.c (tristate)
> > > 
> > > Counting that the CPUX timers are actually even using different
> > > `tick_resume`
> > > and `set_state_shutdown` callbacks (doing only a IRQ
> > > clear/restore and nothing
> > > else), the amount of duplication would be .. well, again,
> > > minimal, but then
> > > this means that timer-mediatek-cpux would be `default y if
> > > ARCH_MEDIATEK`, or
> > > even selected by ARCH_MEDIATEK itself.
> > > 
> > > If you think that this could be a good solution, I can send a
> > > "fast" patch to
> > > split it out, preparing the ground for the people doing this
> > > module work.
> > > 
> > > Any considerations?
> > > 
> > 
> > I think your proposal sounds acceptable, but we would need to make
> > sure that all 
> > SoCs can boot with the CPUX driver. I'm aware of some armv7 SoCs
> > that use a kind of 
> > hack to enable the architecture timer [1]. This, for one part,
> > should be moved to 
> > CPUX, if possible. For the other part it makes me wonder if really
> > all supported 
> > MediaTek platforms will boot with SYST/GPT being a module. I think
> > we will need 
> > some effort from the community to test that.
> > 
> > So as a resume, yes I think your approach is feasible but we should
> > collect 
> > tested-by tags before merging it.
> > 
> > Regards,
> > Matthias
> > 
> > 
> > [1] 
> > 
https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/mach-mediatek/mediatek.c?h=v6.2-rc8*n16__;Iw!!CTRNKA9wMg0ARbw!jOX04TQn1HXcKOdzAiK3ZlqsSE3j3p6Zo-Cajr0khXC9ANlbkl8kQrUgx6wadR8b_46o9J0SbJgjhoS03rQ7somJfA5mnCQ6Fw$ 
> >  
> 
> Right. I completely forgot about those platforms, even though my
> intention was
> to actually try and migrate them once the CPUX was picked. My bad.
> 
> Well, I think that this module conversion will take quite a while, so
> there
> should be no need to rush... I'll send a series later with the split
> *and* a
> conversion of those platforms, so that we will see a removal of that
> mediatek_timer_init() function.
> 
> Some encouraging words ahead: I'm totally confident that the
> conversion will
> Just Work, because the MT6795 SoC had the same handling for CPUXGPT
> as the
> older MT6589/7623/8127/8135... as that SoC had two implementations
> initially,
> one as ARM, one as ARM64.
> 
> Whatever - let's see what I can come up with, then.
> 
> Cheers,
> Angelo

First, I'd like to thank Angelo for assisting us in spliting out the
CPUX driver [1], allowing this driver to become a module that can be
loaded when needed.

In response to Matthias's concern about whether SYST/GPT on the old
MediaTek platforms can boot properly with the loadable module, I
recently conducted a few tests and found that both hardwares are
capable of booting normally with this loadable module.

For my experiments, I used MT6768 with this patch:

1. When the module was not loaded or load the module but the
corresponding compatible property was not specified in the dts, the
following results were obtained:

# cat /proc/timer_list | grep "Broadcast device" -A 15
Broadcast device
Clock Event Device: bc_hrtimer
 max_delta_ns:   9223372036854775807
 min_delta_ns:   1
 mult:           1
 shift:          0
 mode:           3
 next_event:     490204000000 nsecs
 set_next_event: <0000000000000000>
 shutdown: bc_shutdown.cfi_jt
 event_handler:  tick_handle_oneshot_broadcast.cfi_jt
 retries:        0

tick_broadcast_mask: ff
tick_broadcast_oneshot_mask: 7e

The built-in `bc_hrtimer` was used as the broadcast device, whereby one
CPU was kept awake to wake up the other CPUs. As a result, one CPU
could not enter the idle state.

2. When the module was loaded and the GPT compatible property was
specified in the dts:

# cat /proc/timer_list | grep "Broadcast device" -A 17
Broadcast device
Clock Event Device: mtk-clkevt
 max_delta_ns:   330382104634
 min_delta_ns:   1000
 mult:           27917287
 shift:          31
 mode:           3
 next_event:     1483221016462 nsecs
 set_next_event: mtk_gpt_clkevt_next_event.cfi_jt
 shutdown: mtk_gpt_clkevt_shutdown.cfi_jt
 periodic: mtk_gpt_clkevt_set_periodic.cfi_jt
 oneshot:  mtk_gpt_clkevt_shutdown.cfi_jt
 resume:   mtk_gpt_clkevt_shutdown.cfi_jt
 event_handler:  tick_handle_oneshot_broadcast.cfi_jt
 retries:        17

tick_broadcast_mask: ff
tick_broadcast_oneshot_mask: bf

3. When the module was loaded and the SYST compatible property was
specified in the dts:

# cat /proc/timer_list | grep "Broadcast device" -A 17
Broadcast device
Clock Event Device: mtk-clkevt
 max_delta_ns:   330382104634
 min_delta_ns:   1000
 mult:           27917287
 shift:          31
 mode:           3
 next_event:     132252000000 nsecs
 set_next_event: mtk_syst_clkevt_next_event.cfi_jt
 shutdown: mtk_syst_clkevt_shutdown.cfi_jt
 oneshot:  mtk_syst_clkevt_oneshot.cfi_jt
 resume:   mtk_syst_clkevt_resume.cfi_jt
 event_handler:  tick_handle_oneshot_broadcast.cfi_jt
 retries:        8

tick_broadcast_mask: ff
tick_broadcast_oneshot_mask: 3f

These two experiments show that SYST/GPT on the old MediaTek platforms
can also work properly with the loadable module, and will not cause any
booting issues. Therefore, making timer-mediatek.c driver into a
loadable module is feasible.

Thanks,
Walter Chang

[1] 
https://lore.kernel.org/lkml/20230309103913.116775-1-angelogioacchino.delregno@collabora.com/

  reply	other threads:[~2023-03-29  6:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14 10:53 [PATCH v2 0/4] Support timer drivers as loadable modules walter.chang
2023-02-14 10:53 ` [PATCH v2 1/4] time/sched_clock: Export sched_clock_register() walter.chang
2023-02-14 10:53 ` [PATCH v2 2/4] clocksource/drivers/mmio: Export clocksource_mmio_init() walter.chang
2023-02-14 10:53 ` [PATCH v2 3/4] clocksource/drivers/timer-of: Remove __init markings walter.chang
2023-02-14 10:53 ` [PATCH v2 4/4] clocksource/drivers/timer-mediatek: Make timer-mediatek become loadable module walter.chang
2023-02-14 11:09   ` Krzysztof Kozlowski
2023-02-14 23:20     ` John Stultz
2023-02-15 18:35       ` Krzysztof Kozlowski
2023-02-15 20:59         ` John Stultz
2023-02-14 22:20   ` Sudeep Holla
2023-02-15 12:43     ` AngeloGioacchino Del Regno
2023-02-15 13:18       ` Sudeep Holla
2023-02-15 13:30         ` AngeloGioacchino Del Regno
2023-02-15 14:46           ` Sudeep Holla
2023-02-16  1:03             ` John Stultz
2023-02-16 10:22             ` AngeloGioacchino Del Regno
2023-02-16 11:23               ` Matthias Brugger
2023-02-16 11:36                 ` AngeloGioacchino Del Regno
2023-03-29  6:22                   ` Walter Chang (張維哲) [this message]
2023-04-10  6:58                     ` Walter Chang (張維哲)

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=32777456f8e0f98e4cd5b950f421d21f71b149cf.camel@mediatek.com \
    --to=walter.chang@mediatek.com \
    --cc=Chun-hung.Wu@mediatek.com \
    --cc=Freddy.Hsin@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=jstultz@google.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=macro@orcam.me.uk \
    --cc=matthias.bgg@gmail.com \
    --cc=stanley.chu@mediatek.com \
    --cc=sudeep.holla@arm.com \
    --cc=tglx@linutronix.de \
    --cc=wsd_upstream@mediatek.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