From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexander Dahl <ada@thorsis.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/6] clocksource/drivers: Add a new driver for the Atmel ARM TC blocks
Date: Fri, 6 Jul 2018 17:18:48 +0200 [thread overview]
Message-ID: <20180706151848.GB16084@piout.net> (raw)
In-Reply-To: <0ebef205-a6c8-0da2-86b4-6b1c982a1fdf@linaro.org>
On 28/06/2018 18:24:12+0200, Daniel Lezcano wrote:
> > +static void tc_clkevt2_clk_enable(struct clock_event_device *d)
> > +{
> > + if (tce.clk_enabled)
> > + return;
>
> Why this test ?
>
> > + clk_enable(tce.clk);
> > + tce.clk_enabled = true;
> > +}
> >
> > +static int tc_clkevt2_stop(struct clock_event_device *d)
> > +{
> > + writel(0xff, tce.base + ATMEL_TC_IDR(tce.channel));
> > + writel(ATMEL_TC_CCR_CLKDIS, tce.base + ATMEL_TC_CCR(tce.channel));
> > +
> > + return 0;
> > +}
> > +
> > +static int tc_clkevt2_shutdown(struct clock_event_device *d)
> > +{
> > + tc_clkevt2_stop(d);
> > + if (!clockevent_state_detached(d))
>
> Why this test ?
>
> > + tc_clkevt2_clk_disable(d);
> > +
> > + return 0;
> > +}
> > +
> > +/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
> > + * because using one of the divided clocks would usually mean the
> > + * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
> > + *
> > + * A divided clock could be good for high resolution timers, since
> > + * 30.5 usec resolution can seem "low".
> > + */
> > +static int tc_clkevt2_set_oneshot(struct clock_event_device *d)
> > +{
> > + if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
> > + tc_clkevt2_stop(d);
>
> Why these tests ? :)
>
All these test are to be nice with preempt-rt else we would be disabling
then reenabling the clock in an atomic context which fails with the
preempt-rt patch.
> > + /* By not making the gentime core emulate periodic mode on top
> > + * of oneshot, we get lower overhead and improved accuracy.
> > + */
> > + tc_clkevt2_clk_enable(d);
> > +
> > + /* slow clock, count up to RC, then irq and restart */
> > + writel(ATMEL_TC_CMR_TCLK(4) | ATMEL_TC_CMR_WAVE |
> > + ATMEL_TC_CMR_WAVESEL_UPRC,
> > + tce.base + ATMEL_TC_CMR(tce.channel));
> > + writel((32768 + HZ / 2) / HZ, tce.base + ATMEL_TC_RC(tce.channel));
>
> Do this computation at init time.
>
Does it really matter? All the members are constant so no code will be
generated for the computation. This ends up being an immediate value
computing it at init time would mean storing it in the structure which
would incur an extra load.
> > + /* Enable clock and interrupts on RC compare */
> > + writel(ATMEL_TC_CPCS, tce.base + ATMEL_TC_IER(tce.channel));
> > + writel(ATMEL_TC_CCR_CLKEN | ATMEL_TC_CCR_SWTRG,
> > + tce.base + ATMEL_TC_CCR(tce.channel));
> > +
> > + return 0;
> > +}
> > +
> > +static int tc_clkevt2_next_event(unsigned long delta,
> > + struct clock_event_device *d)
> > +{
> > + writel(delta, tce.base + ATMEL_TC_RC(tce.channel));
> > + writel(ATMEL_TC_CCR_CLKEN | ATMEL_TC_CCR_SWTRG,
> > + tce.base + ATMEL_TC_CCR(tce.channel));
> > +
> > + return 0;
> > +}
> > +
> > +static irqreturn_t tc_clkevt2_irq(int irq, void *handle)
> > +{
> > + unsigned int sr;
> > +
> > + sr = readl(tce.base + ATMEL_TC_SR(tce.channel));
> > + if (sr & ATMEL_TC_CPCS) {
> > + tce.clkevt.event_handler(&tce.clkevt);
> > + return IRQ_HANDLED;
>
> Isn't an clear irq missing ?
>
It is cleared on read.
> > + }
> > +
> > + return IRQ_NONE;
> > +}
> > +
> > +static void tc_clkevt2_suspend(struct clock_event_device *d)
> > +{
> > + tce.cache.cmr = readl(tce.base + ATMEL_TC_CMR(tce.channel));
> > + tce.cache.imr = readl(tce.base + ATMEL_TC_IMR(tce.channel));
> > + tce.cache.rc = readl(tce.base + ATMEL_TC_RC(tce.channel));
> > + tce.cache.clken = !!(readl(tce.base + ATMEL_TC_SR(tce.channel)) &
> > + ATMEL_TC_CLKSTA);
>
> Who is in charge of powering down the timer ?
>
The platform code stops all the clocks when going to suspend.
--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2018-07-06 15:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 21:19 [PATCH v5 0/6] clocksource: rework Atmel TCB timer driver Alexandre Belloni
2018-06-19 21:19 ` [PATCH v5 1/6] ARM: at91: add TCB registers definitions Alexandre Belloni
2018-06-28 15:15 ` Daniel Lezcano
2018-06-28 18:34 ` Alexandre Belloni
2018-06-28 19:55 ` Daniel Lezcano
2018-06-19 21:19 ` [PATCH v5 2/6] clocksource/drivers: Add a new driver for the Atmel ARM TC blocks Alexandre Belloni
2018-06-20 9:03 ` Thomas Gleixner
2018-06-20 9:46 ` Alexandre Belloni
2018-06-20 10:07 ` Thomas Gleixner
2018-06-20 10:32 ` Alexandre Belloni
2018-06-20 10:58 ` Thomas Gleixner
2018-06-20 11:18 ` Alexandre Belloni
2018-06-20 11:55 ` Thomas Gleixner
2018-06-28 16:24 ` Daniel Lezcano
2018-07-06 15:18 ` Alexandre Belloni [this message]
2018-06-19 21:19 ` [PATCH v5 3/6] clocksource/drivers: atmel-pit: make option silent Alexandre Belloni
2018-06-19 21:19 ` [PATCH v5 4/6] ARM: at91: Implement clocksource selection Alexandre Belloni
2018-06-19 21:19 ` [PATCH v5 5/6] ARM: configs: at91: use new TCB timer driver Alexandre Belloni
2018-06-19 21:19 ` [PATCH v5 6/6] ARM: configs: at91: unselect PIT Alexandre Belloni
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=20180706151848.GB16084@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=ada@thorsis.com \
--cc=bigeasy@linutronix.de \
--cc=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--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 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®