All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Rob Herring <robh@kernel.org>,
	Alexander Kochetkov <al.kochet@gmail.com>,
	Heiko Stuebner <heiko@sntech.de>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Russell King <linux@armlinux.org.uk>,
	Caesar Wang <wxt@rock-chips.com>,
	Huang Tao <huangtao@rock-chips.com>
Subject: Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent
Date: Wed, 29 Mar 2017 15:34:12 +0100	[thread overview]
Message-ID: <20170329143411.GL23442@leverpostej> (raw)
In-Reply-To: <20170329134134.GJ2123@mai>

On Wed, Mar 29, 2017 at 03:41:34PM +0200, Daniel Lezcano wrote:
> On Wed, Mar 29, 2017 at 01:57:14PM +0100, Mark Rutland wrote:
> > On Wed, Mar 29, 2017 at 02:36:38PM +0200, Daniel Lezcano wrote:

> > > arch/arc/boot/dts/abilis_tb10x.dtsi:
> > > 
> > >         /* TIMER0 with interrupt for clockevent */
> > >         timer0 {
> > >                 compatible = "snps,arc-timer";
> > >                 interrupts = <3>;
> > >                 interrupt-parent = <&intc>;
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > >         /* TIMER1 for free running clocksource */
> > >         timer1 {
> > >                 compatible = "snps,arc-timer";
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > > drivers/clocksource/arc_timer.c:
> > > 
> > > static int __init arc_of_timer_init(struct device_node *np)
> > > {
> > >         static int init_count = 0;
> > >         int ret;
> > > 
> > >         if (!init_count) {
> > >                 init_count = 1;
> > >                 ret = arc_clockevent_setup(np);
> > >         } else {
> > >                 ret = arc_cs_setup_timer1(np);
> > >         }
> > > 
> > >         return ret;
> > > }
> > > 
> > > So the purpose of these changes is to provide a stronger timer declaration in
> > > order to clearly split in the kernel a clocksource and a clockevent
> > > initialization.
> > 
> > I agree that this pattern is not nice. However, I think that splitting
> > devices as this level makes the problem *worse*.
> > 
> > Users care that they have a clocksource and a clockevent device. They
> > do not care *which* particular device is used as either. The comments in
> > the DT above are at best misleading.
> 
> Agree.
> 
> And the driver is assuming the first node is the clockevent and the second one
> is the clocksource. If the DT invert these nodes, that breaks the driver.

Sure, but that is something we can and should fix within Linux.

> > What we need is for the kernel to understand that devices can be both
> > clockevent and clocksource (perhaps mutually exclusively), such that the
> > kernel can decide how to make use of devices.
> > 
> > That way, for the above the kernel can figure out that timer0 could be
> > used as clocksource or clockevent, while timer1 can only be used as a
> > clocksource due to the lack of an interrupt. Thus, it can choose to use
> > timer0 as a clockevent, and timer1 and a clocksource.
> 
> Well, 'interrupt' gives an indication the timer can be used as a clockevent and
> clocksource, not the clockevent only.

Which is exactly what I said above, when I said:

	the kernel can figure out that timer0 could be used as
	clocksource or clockevent

Considering both timer0 and timer1 is how we can figure out timer0 must
be the clockevent, since timer1 cannot be.

> If we take the case of the rockchip, the arm_arch_timer clocksource is stopped
> when the CPU is clock gated. So specifically, we don't want to use this
> clocksource but we want to use the arch clockevents because they are better.

Sure. As I pointed out, we want to consider the holistic details to make
the right decision. i.e. the infrastructure should make the choice, not
the individual drivers.

Consider that the kernel may need to make decisions that differ it a
kernel is built wihout certain drivers. That cannot work if the use is
allocated in the DT.

[...]

> > > 2. A node can have a clockevent and|or a clocksource attributes
> > 
> > As above, this should not be in the DT given it's describing a
> > (Linux-specific) SW policy and not a HW detail.
> > 
> > So I must disagree with this.
> 
> IIUC my discussion with Rob, an attribute is acceptable (btw if
> 'clocksource'|'clockevent' names are too Linux specific (+1), what
> about a more generic name like 'tick' and 'time' ?).

The *meaning* of these is Linux specific. The naming is irrelevant.

> > > 3. The timer_probe pass a flag to the driver's init function, so this one knows
> > >    if it should invoke the clockevent/clocksource init functions.
> > >    No attribute defaults to clocksource|clockevent.
> > > 
> > > That would be backward compatible and will let to create drivers with clutch
> > > activated device via DT. Also, it will give the opportunity to the existing
> > > drivers to change consolidate their initialization routines.
> > 
> > I think that if anything, we need a combined clocksource+clockevent
> > device that we register to the core code. That means all
> > clocksource/clockevent drivers have a consolidated routine.
> > 
> > Subsequently, core code should determine how specifically to use the
> > device (e.g. based on what other devices are registered, and their
> > capabilities).
> 
> IMO, the core code is complex enough and that may imply more heuristics.

Given that the majority of cases are going to be multiple instances of
the same IP, I cannot imagine it is complex to get something that works.

A generally optimal configuration may require some heuristics, but
that's a different matter to a correct and functional configuration.

I must disagree with trying to push that complexity into the DT by means
of static SW policy, rather than solving the problem in SW where we have
all the information to do so.

Thanks,
Mark.

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>
To: Daniel Lezcano <daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Alexander Kochetkov
	<al.kochet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Russell King <linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org>,
	Caesar Wang <wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org>,
	Huang Tao <huangtao-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Subject: Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent
Date: Wed, 29 Mar 2017 15:34:12 +0100	[thread overview]
Message-ID: <20170329143411.GL23442@leverpostej> (raw)
In-Reply-To: <20170329134134.GJ2123@mai>

On Wed, Mar 29, 2017 at 03:41:34PM +0200, Daniel Lezcano wrote:
> On Wed, Mar 29, 2017 at 01:57:14PM +0100, Mark Rutland wrote:
> > On Wed, Mar 29, 2017 at 02:36:38PM +0200, Daniel Lezcano wrote:

> > > arch/arc/boot/dts/abilis_tb10x.dtsi:
> > > 
> > >         /* TIMER0 with interrupt for clockevent */
> > >         timer0 {
> > >                 compatible = "snps,arc-timer";
> > >                 interrupts = <3>;
> > >                 interrupt-parent = <&intc>;
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > >         /* TIMER1 for free running clocksource */
> > >         timer1 {
> > >                 compatible = "snps,arc-timer";
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > > drivers/clocksource/arc_timer.c:
> > > 
> > > static int __init arc_of_timer_init(struct device_node *np)
> > > {
> > >         static int init_count = 0;
> > >         int ret;
> > > 
> > >         if (!init_count) {
> > >                 init_count = 1;
> > >                 ret = arc_clockevent_setup(np);
> > >         } else {
> > >                 ret = arc_cs_setup_timer1(np);
> > >         }
> > > 
> > >         return ret;
> > > }
> > > 
> > > So the purpose of these changes is to provide a stronger timer declaration in
> > > order to clearly split in the kernel a clocksource and a clockevent
> > > initialization.
> > 
> > I agree that this pattern is not nice. However, I think that splitting
> > devices as this level makes the problem *worse*.
> > 
> > Users care that they have a clocksource and a clockevent device. They
> > do not care *which* particular device is used as either. The comments in
> > the DT above are at best misleading.
> 
> Agree.
> 
> And the driver is assuming the first node is the clockevent and the second one
> is the clocksource. If the DT invert these nodes, that breaks the driver.

Sure, but that is something we can and should fix within Linux.

> > What we need is for the kernel to understand that devices can be both
> > clockevent and clocksource (perhaps mutually exclusively), such that the
> > kernel can decide how to make use of devices.
> > 
> > That way, for the above the kernel can figure out that timer0 could be
> > used as clocksource or clockevent, while timer1 can only be used as a
> > clocksource due to the lack of an interrupt. Thus, it can choose to use
> > timer0 as a clockevent, and timer1 and a clocksource.
> 
> Well, 'interrupt' gives an indication the timer can be used as a clockevent and
> clocksource, not the clockevent only.

Which is exactly what I said above, when I said:

	the kernel can figure out that timer0 could be used as
	clocksource or clockevent

Considering both timer0 and timer1 is how we can figure out timer0 must
be the clockevent, since timer1 cannot be.

> If we take the case of the rockchip, the arm_arch_timer clocksource is stopped
> when the CPU is clock gated. So specifically, we don't want to use this
> clocksource but we want to use the arch clockevents because they are better.

Sure. As I pointed out, we want to consider the holistic details to make
the right decision. i.e. the infrastructure should make the choice, not
the individual drivers.

Consider that the kernel may need to make decisions that differ it a
kernel is built wihout certain drivers. That cannot work if the use is
allocated in the DT.

[...]

> > > 2. A node can have a clockevent and|or a clocksource attributes
> > 
> > As above, this should not be in the DT given it's describing a
> > (Linux-specific) SW policy and not a HW detail.
> > 
> > So I must disagree with this.
> 
> IIUC my discussion with Rob, an attribute is acceptable (btw if
> 'clocksource'|'clockevent' names are too Linux specific (+1), what
> about a more generic name like 'tick' and 'time' ?).

The *meaning* of these is Linux specific. The naming is irrelevant.

> > > 3. The timer_probe pass a flag to the driver's init function, so this one knows
> > >    if it should invoke the clockevent/clocksource init functions.
> > >    No attribute defaults to clocksource|clockevent.
> > > 
> > > That would be backward compatible and will let to create drivers with clutch
> > > activated device via DT. Also, it will give the opportunity to the existing
> > > drivers to change consolidate their initialization routines.
> > 
> > I think that if anything, we need a combined clocksource+clockevent
> > device that we register to the core code. That means all
> > clocksource/clockevent drivers have a consolidated routine.
> > 
> > Subsequently, core code should determine how specifically to use the
> > device (e.g. based on what other devices are registered, and their
> > capabilities).
> 
> IMO, the core code is complex enough and that may imply more heuristics.

Given that the majority of cases are going to be multiple instances of
the same IP, I cannot imagine it is complex to get something that works.

A generally optimal configuration may require some heuristics, but
that's a different matter to a correct and functional configuration.

I must disagree with trying to push that complexity into the DT by means
of static SW policy, rather than solving the problem in SW where we have
all the information to do so.

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent
Date: Wed, 29 Mar 2017 15:34:12 +0100	[thread overview]
Message-ID: <20170329143411.GL23442@leverpostej> (raw)
In-Reply-To: <20170329134134.GJ2123@mai>

On Wed, Mar 29, 2017 at 03:41:34PM +0200, Daniel Lezcano wrote:
> On Wed, Mar 29, 2017 at 01:57:14PM +0100, Mark Rutland wrote:
> > On Wed, Mar 29, 2017 at 02:36:38PM +0200, Daniel Lezcano wrote:

> > > arch/arc/boot/dts/abilis_tb10x.dtsi:
> > > 
> > >         /* TIMER0 with interrupt for clockevent */
> > >         timer0 {
> > >                 compatible = "snps,arc-timer";
> > >                 interrupts = <3>;
> > >                 interrupt-parent = <&intc>;
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > >         /* TIMER1 for free running clocksource */
> > >         timer1 {
> > >                 compatible = "snps,arc-timer";
> > >                 clocks = <&cpu_clk>;
> > >         };
> > > 
> > > drivers/clocksource/arc_timer.c:
> > > 
> > > static int __init arc_of_timer_init(struct device_node *np)
> > > {
> > >         static int init_count = 0;
> > >         int ret;
> > > 
> > >         if (!init_count) {
> > >                 init_count = 1;
> > >                 ret = arc_clockevent_setup(np);
> > >         } else {
> > >                 ret = arc_cs_setup_timer1(np);
> > >         }
> > > 
> > >         return ret;
> > > }
> > > 
> > > So the purpose of these changes is to provide a stronger timer declaration in
> > > order to clearly split in the kernel a clocksource and a clockevent
> > > initialization.
> > 
> > I agree that this pattern is not nice. However, I think that splitting
> > devices as this level makes the problem *worse*.
> > 
> > Users care that they have a clocksource and a clockevent device. They
> > do not care *which* particular device is used as either. The comments in
> > the DT above are at best misleading.
> 
> Agree.
> 
> And the driver is assuming the first node is the clockevent and the second one
> is the clocksource. If the DT invert these nodes, that breaks the driver.

Sure, but that is something we can and should fix within Linux.

> > What we need is for the kernel to understand that devices can be both
> > clockevent and clocksource (perhaps mutually exclusively), such that the
> > kernel can decide how to make use of devices.
> > 
> > That way, for the above the kernel can figure out that timer0 could be
> > used as clocksource or clockevent, while timer1 can only be used as a
> > clocksource due to the lack of an interrupt. Thus, it can choose to use
> > timer0 as a clockevent, and timer1 and a clocksource.
> 
> Well, 'interrupt' gives an indication the timer can be used as a clockevent and
> clocksource, not the clockevent only.

Which is exactly what I said above, when I said:

	the kernel can figure out that timer0 could be used as
	clocksource or clockevent

Considering both timer0 and timer1 is how we can figure out timer0 must
be the clockevent, since timer1 cannot be.

> If we take the case of the rockchip, the arm_arch_timer clocksource is stopped
> when the CPU is clock gated. So specifically, we don't want to use this
> clocksource but we want to use the arch clockevents because they are better.

Sure. As I pointed out, we want to consider the holistic details to make
the right decision. i.e. the infrastructure should make the choice, not
the individual drivers.

Consider that the kernel may need to make decisions that differ it a
kernel is built wihout certain drivers. That cannot work if the use is
allocated in the DT.

[...]

> > > 2. A node can have a clockevent and|or a clocksource attributes
> > 
> > As above, this should not be in the DT given it's describing a
> > (Linux-specific) SW policy and not a HW detail.
> > 
> > So I must disagree with this.
> 
> IIUC my discussion with Rob, an attribute is acceptable (btw if
> 'clocksource'|'clockevent' names are too Linux specific (+1), what
> about a more generic name like 'tick' and 'time' ?).

The *meaning* of these is Linux specific. The naming is irrelevant.

> > > 3. The timer_probe pass a flag to the driver's init function, so this one knows
> > >    if it should invoke the clockevent/clocksource init functions.
> > >    No attribute defaults to clocksource|clockevent.
> > > 
> > > That would be backward compatible and will let to create drivers with clutch
> > > activated device via DT. Also, it will give the opportunity to the existing
> > > drivers to change consolidate their initialization routines.
> > 
> > I think that if anything, we need a combined clocksource+clockevent
> > device that we register to the core code. That means all
> > clocksource/clockevent drivers have a consolidated routine.
> > 
> > Subsequently, core code should determine how specifically to use the
> > device (e.g. based on what other devices are registered, and their
> > capabilities).
> 
> IMO, the core code is complex enough and that may imply more heuristics.

Given that the majority of cases are going to be multiple instances of
the same IP, I cannot imagine it is complex to get something that works.

A generally optimal configuration may require some heuristics, but
that's a different matter to a correct and functional configuration.

I must disagree with trying to push that complexity into the DT by means
of static SW policy, rather than solving the problem in SW where we have
all the information to do so.

Thanks,
Mark.

  reply	other threads:[~2017-03-29 14:34 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22 15:48 [PATCH v7 0/7] Implement clocksource for rockchip SoC using rockchip timer Alexander Kochetkov
2017-03-22 15:48 ` Alexander Kochetkov
2017-03-22 15:48 ` Alexander Kochetkov
2017-03-22 15:48 ` [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-29  1:51   ` Rob Herring
2017-03-29  1:51     ` Rob Herring
2017-03-29  1:51     ` Rob Herring
2017-03-29  9:22     ` Daniel Lezcano
2017-03-29  9:22       ` Daniel Lezcano
2017-03-29  9:22       ` Daniel Lezcano
2017-03-29 10:49       ` Mark Rutland
2017-03-29 10:49         ` Mark Rutland
2017-03-29 10:49         ` Mark Rutland
2017-03-29 12:36         ` Daniel Lezcano
2017-03-29 12:36           ` Daniel Lezcano
2017-03-29 12:36           ` Daniel Lezcano
2017-03-29 12:57           ` Mark Rutland
2017-03-29 12:57             ` Mark Rutland
2017-03-29 13:41             ` Daniel Lezcano
2017-03-29 13:41               ` Daniel Lezcano
2017-03-29 13:41               ` Daniel Lezcano
2017-03-29 14:34               ` Mark Rutland [this message]
2017-03-29 14:34                 ` Mark Rutland
2017-03-29 14:34                 ` Mark Rutland
2017-03-22 15:48 ` [PATCH v7 2/7] dt-bindings: clarify compatible property for rockchip timers Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48 ` [PATCH v7 3/7] ARM: dts: rockchip: update compatible property for rk322x timer Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48 ` [PATCH v7 4/7] ARM: dts: rockchip: add clockevent attribute to rockchip timers Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48 ` [PATCH v7 5/7] clocksource/drivers/rockchip_timer: implement clocksource timer Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-24  8:29   ` kbuild test robot
2017-03-24  8:29     ` kbuild test robot
2017-03-24  8:29     ` kbuild test robot
2017-03-24  8:41     ` Alexander Kochetkov
2017-03-24  8:41       ` Alexander Kochetkov
2017-03-24  8:41       ` Alexander Kochetkov
2017-03-24  8:55       ` Daniel Lezcano
2017-03-24  8:55         ` Daniel Lezcano
2017-03-24  8:55         ` Daniel Lezcano
2017-03-22 15:48 ` [PATCH v7 6/7] ARM: dts: rockchip: add timer entries to rk3188 SoC Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48 ` [PATCH v7 7/7] ARM: dts: rockchip: disable arm-global-timer for rk3188 Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-22 15:48   ` Alexander Kochetkov
2017-03-29 13:22 ` [PATCH v7 0/7] Implement clocksource for rockchip SoC using rockchip timer Alexander Kochetkov
2017-03-29 13:22   ` Alexander Kochetkov
2017-03-30  9:26   ` Daniel Lezcano
2017-03-30  9:26     ` Daniel Lezcano
2017-03-30  9:26     ` Daniel Lezcano

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=20170329143411.GL23442@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=al.kochet@gmail.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=heiko@sntech.de \
    --cc=huangtao@rock-chips.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wxt@rock-chips.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 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.