Skip to contentSkip to conversation

Implement clocksource for rockchip SoC using rockchip timer

PATCH In review Alexander Kochetkov 5 participants 20 messages Mar 22, 2017 – Mar 30, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v7 cover Implement clocksource for rockchip SoC using rockchip timer

Hello, Daniel, Heiko.

Here is try 7 :) Could you please take a look into it?

rockchip_timer init code implemented using CLOCKEVENT_OF_DECLARE() introduced in commit 0c8893c9095d ("clockevents: Add a clkevt-of mechanism like clksrc-of")

There is change in the arch/arm/mach-rockchip/rockchip.c.

This series should be applied after the commit:
https://lkml.org/lkml/2017/3/22/426

As without the commit, you will get linker error ("clkevt-probe.c:63:
undefined reference to `__clkevt_of_table?")

Regards,
Alexander.

Alexander Kochetkov (6):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer
ARM: dts: rockchip: add clockevent attribute to rockchip timers clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

Daniel Lezcano (1):
clocksource/drivers/clksrc-evt-probe: Describe with the DT both the
clocksource and the clockevent

 .../bindings/timer/rockchip,rk-timer.txt           |   12 +-
 Documentation/devicetree/bindings/timer/timer.txt  |   38 ++++
 arch/arm/boot/dts/rk3036.dtsi                      |    1 +
 arch/arm/boot/dts/rk3188.dtsi                      |   19 ++
 arch/arm/boot/dts/rk322x.dtsi                      |    3 +-
 arch/arm/boot/dts/rk3288.dtsi                      |    1 +
 arch/arm/mach-rockchip/rockchip.c                  |    2 +
 arch/arm64/boot/dts/rockchip/rk3368.dtsi           |    1 +
 drivers/clocksource/Kconfig                        |    2 +
 drivers/clocksource/clkevt-probe.c                 |    7 +
 drivers/clocksource/clksrc-probe.c                 |    7 +
 drivers/clocksource/rockchip_timer.c               |  215 ++++++++++++++------
 12 files changed, 241 insertions(+), 67 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/timer/timer.txt
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v7 1/7 clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

From: Daniel Lezcano <[email protected]>

The CLOCKSOURCE_OF_DECLARE() was introduced before the CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the clockevent and the clocksource are both initialized in the same init routine.

With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can now split the clocksource and the clockevent init code. However, the device tree may specify a single node, so the same node will be passed to the clockevent/clocksource's init function, with the same base address.

with this patch it is possible to specify an attribute to the timer's node to specify if it is a clocksource or a clockevent and define two timers node.

For example:

        timer: timer at 98400000 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400000 0x42>;
                interrupts = <19 1>;
                clocks = <&coreclk>;
                clockevent;
        };

        timer: timer at 98400010 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400010 0x42>;
                clocks = <&coreclk>;
                clocksource;
        };

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.
---
 Documentation/devicetree/bindings/timer/timer.txt |   38 +++++++++++++++++++++
 drivers/clocksource/clkevt-probe.c                |    7 ++++
 drivers/clocksource/clksrc-probe.c                |    7 ++++
 3 files changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/timer.txt
Documentation/devicetree/bindings/timer/timer.txt new file +38 -0
new file mode 100644
index 0000000..f1ee0cf
@@ -0,0 +1,38 @@
+
+Specifying timer information for devices
+========================================
+
+The timer can be declared via the macro:
+
+CLOCKSOURCE_OF_DECLARE(name, init) if it is a clocksource
+CLOCKEVENT_OF_DECLARE(name, init) if it is a clockevent
+
+The CLOCKSOURCE_OF_DECLARE() was introduced before the
+CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the
+clockevent and the clocksource are both initialized in the same init
+routine.
+
+With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can
+now split the clocksource and the clockevent init code. However, the
+device tree may specify a single node, so the same node will be passed
+to the clockevent/clocksource's init function, with the same base
+address. It is possible to specify an attribute to the timer's node to
+specify if it is a clocksource or a clockevent and define two timers
+node.
+
+Example:
+
+	timer: timer at 98400000 {
+		compatible = "moxa,moxart-timer";
+		reg = <0x98400000 0x42>;
+		interrupts = <19 1>;
+		clocks = <&coreclk>;
+		clockevent;
+	};
+
+	timer: timer at 98400010 {
+		compatible = "moxa,moxart-timer";
+		reg = <0x98400010 0x42>;
+		clocks = <&coreclk>;
+		clocksource;
+	};
drivers/clocksource/clkevt-probe.c +7 -0
index eb89b50..fa02ac1 100644
@@ -37,6 +37,13 @@ int __init clockevent_probe(void)
 
 		init_func = match->data;
 
+		/*
+		 * The device node describes a clocksource, ignore it
+		 * as we are in the clockevent init routine.
+		 */
+		if (of_property_read_bool(np, "clocksource"))
+			continue;
+
 		ret = init_func(np);
 		if (ret) {
 			pr_warn("Failed to initialize '%s' (%d)\n",
drivers/clocksource/clksrc-probe.c +7 -0
index bc62be9..ce50f33 100644
@@ -38,6 +38,13 @@ void __init clocksource_probe(void)
 
 		init_func_ret = match->data;
 
+		/*
+		 * The device node describes a clockevent, ignore it
+		 * as we are in the clocksource init routine.
+		 */
+		if (of_property_read_bool(np, "clockevent"))
+			continue;
+
 		ret = init_func_ret(np);
 		if (ret) {
 			pr_err("Failed to initialize '%s': %d",
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v7 2/7 dt-bindings: clarify compatible property for rockchip timers

In reply to Alexander Kochetkov

Make all properties description in form '"rockchip,<chip>-timer", "rockchip,rk3288-timer"' for all chips found in linux kernel.

---
 .../bindings/timer/rockchip,rk-timer.txt           |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/timer/rockchip,rk-timer.txt +9 -3
index a41b184..16a5f45 100644
@@ -1,9 +1,15 @@
 Rockchip rk timer
 
 Required properties:
-- compatible: shall be one of:
-  "rockchip,rk3288-timer" - for rk3066, rk3036, rk3188, rk322x, rk3288, rk3368
-  "rockchip,rk3399-timer" - for rk3399
+- compatible: should be:
+  "rockchip,rk3036-timer", "rockchip,rk3288-timer": for Rockchip RK3036
+  "rockchip,rk3066-timer", "rockchip,rk3288-timer": for Rockchip RK3066
+  "rockchip,rk3188-timer", "rockchip,rk3288-timer": for Rockchip RK3188
+  "rockchip,rk3228-timer", "rockchip,rk3288-timer": for Rockchip RK3228
+  "rockchip,rk3229-timer", "rockchip,rk3288-timer": for Rockchip RK3229
+  "rockchip,rk3288-timer": for Rockchip RK3288
+  "rockchip,rk3368-timer", "rockchip,rk3288-timer": for Rockchip RK3368
+  "rockchip,rk3399-timer": for Rockchip RK3399
 - reg: base address of the timer register starting with TIMERS CONTROL register
 - interrupts: should contain the interrupts for Timer0
 - clocks : must contain an entry for each entry in clock-names
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v7 3/7 ARM: dts: rockchip: update compatible property for rk322x timer

In reply to Alexander Kochetkov

Property set to '"rockchip,rk3228-timer", "rockchip,rk3288-timer"' to match devicetree bindings.

---
 arch/arm/boot/dts/rk322x.dtsi |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/rk322x.dtsi +1 -1
index 9e6bf0e..2a4eee2 100644
@@ -323,7 +323,7 @@
 	};
 
 	timer: timer at 110c0000 {
-		compatible = "rockchip,rk3288-timer";
+		compatible = "rockchip,rk3228-timer", "rockchip,rk3288-timer";
 		reg = <0x110c0000 0x20>;
 		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&xin24m>, <&cru PCLK_TIMER>;
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v7 4/7 ARM: dts: rockchip: add clockevent attribute to rockchip timers

In reply to Alexander Kochetkov

All rockchip timers present in the DT act as clockevent. It is possible to specify timer role using DT attribute. Mark them accordingly.

Also this patch specify that for timer should be called init function specified with CLOCKEVENT_OF_DECLARE().

Without the commit boot warnings will appear because clock framework will try initialize them as clocksource.

---
 arch/arm/boot/dts/rk3036.dtsi            |    1 +
 arch/arm/boot/dts/rk322x.dtsi            |    1 +
 arch/arm/boot/dts/rk3288.dtsi            |    1 +
 arch/arm64/boot/dts/rockchip/rk3368.dtsi |    1 +
 4 files changed, 4 insertions(+)
arch/arm/boot/dts/rk3036.dtsi +1 -0
index 843d2be..a04bb5a 100644
@@ -353,6 +353,7 @@
 		interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&xin24m>, <&cru PCLK_TIMER>;
 		clock-names = "timer", "pclk";
+		clockevent;
 	};
 
 	pwm0: pwm at 20050000 {
arch/arm/boot/dts/rk322x.dtsi +1 -0
index 2a4eee2..2250640 100644
@@ -328,6 +328,7 @@
 		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&xin24m>, <&cru PCLK_TIMER>;
 		clock-names = "timer", "pclk";
+		clockevent;
 	};
 
 	cru: clock-controller at 110e0000 {
arch/arm/boot/dts/rk3288.dtsi +1 -0
index 91c4b3c..f45b7ad 100644
@@ -217,6 +217,7 @@
 		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&xin24m>, <&cru PCLK_TIMER>;
 		clock-names = "timer", "pclk";
+		clockevent;
 	};
 
 	display-subsystem {
arch/arm64/boot/dts/rockchip/rk3368.dtsi +1 -0
index 4f44d11..054dadd 100644
@@ -673,6 +673,7 @@
 		compatible = "rockchip,rk3368-timer", "rockchip,rk3288-timer";
 		reg = <0x0 0xff810000 0x0 0x20>;
 		interrupts = <GIC_SPI 66 IRQ_TYPE_LEVEL_HIGH>;
+		clockevent;
 	};
 
 	gic: interrupt-controller at ffb71000 {
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH v7 5/7 clocksource/drivers/rockchip_timer: implement clocksource timer

In reply to Alexander Kochetkov

The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency making this timer unsuitable as a stable clocksource and sched clock.

The rk3188, rk3288 and following socs share a separate timer block already handled by the rockchip-timer driver. Therefore adapt this driver to also be able to act as clocksource and sched clock on rk3188.

In order to test clocksource you can run following commands and check how much time it take in real. On rk3188 it take about ~45 seconds.

cpufreq-set -f 1.6GHZ
date; sleep 60; date

In order to use the patch you need to declare two timers in the dts file. The first timer will be initialized as clockevent provider and the second one as clocksource. The clockevent must be from alive subsystem as it used as backup for the local timers at sleep time.

The patch does not break compatibility with older device tree files. The older device tree files contain only one timer. The timer will be initialized as clockevent, as expected. But new warnings like 'Failed to initialize /timer at ....' will appear with old device tree files. To resolve them 'clockevent' attribute should be added to the timer.

rk3288 (and probably anything newer) is irrelevant to this patch, as it has the arch timer interface. This patch may be useful for Cortex-A9/A5 based parts.

---
 arch/arm/mach-rockchip/rockchip.c    |    2 +
 drivers/clocksource/Kconfig          |    2 +
 drivers/clocksource/rockchip_timer.c |  215 ++++++++++++++++++++++++----------
 3 files changed, 156 insertions(+), 63 deletions(-)
arch/arm/mach-rockchip/rockchip.c +2 -0
index a7ab9ec..5184f7d 100644
@@ -21,6 +21,7 @@
 #include <linux/irqchip.h>
 #include <linux/clk-provider.h>
 #include <linux/clocksource.h>
+#include <linux/clockchips.h>
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
 #include <asm/mach/arch.h>
@@ -67,6 +68,7 @@ static void __init rockchip_timer_init(void)
 	}
 
 	of_clk_init(NULL);
+	clockevent_probe();
 	clocksource_probe();
 }
 
drivers/clocksource/Kconfig +2 -0
index 21f84ea..5e0df76 100644
@@ -71,6 +71,8 @@ config ROCKCHIP_TIMER
 	bool "Rockchip timer driver" if COMPILE_TEST
 	depends on ARM || ARM64
 	select CLKSRC_OF
+	select CLKEVT_OF
+	select CLKSRC_MMIO
 	help
 	  Enables the support for the rockchip timer driver.
 
drivers/clocksource/rockchip_timer.c +152 -63

332 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#16 lore raw

PATCH v7 6/7 ARM: dts: rockchip: add timer entries to rk3188 SoC

In reply to Alexander Kochetkov

The patch add two timers to all rk3188 based boards.

The first timer is from alive subsystem and it act as a backup for the local timers at sleep time. It act the same as other SoC rockchip timers already present in kernel.

The second timer is from CPU subsystem and act as replacement for the arm-global-timer clocksource and sched clock. It run at stable frequency 24MHz.

---
 arch/arm/boot/dts/rk3188.dtsi |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm/boot/dts/rk3188.dtsi +18 -0
index b3e6a30..a20d501 100644
@@ -106,6 +106,24 @@
 		};
 	};
 
+	timer3: timer at 2000e000 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x2000e000 0x20>;
+		interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER3>, <&cru PCLK_TIMER3>;
+		clock-names = "timer", "pclk";
+		clockevent;
+	};
+
+	timer6: timer at 200380a0 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x200380a0 0x20>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER6>, <&cru PCLK_TIMER0>;
+		clock-names = "timer", "pclk";
+		clocksource;
+	};
+
 	i2s0: i2s at 1011a000 {
 		compatible = "rockchip,rk3188-i2s", "rockchip,rk3066-i2s";
 		reg = <0x1011a000 0x2000>;
Signature · 1 line
1.7.9.5
#17 lore raw

PATCH v7 7/7 ARM: dts: rockchip: disable arm-global-timer for rk3188

In reply to Alexander Kochetkov

The clocksource and the sched_clock provided by the arm_global_timer are quite unstable because their rates depend on the cpu frequency.

On the other side, the arm_global_timer has a higher rating than the rockchip_timer, it will be selected by default by the time framework while we want to use the stable rockchip clocksource.

Let's disable the arm_global_timer in order to have the rockchip clocksource selected by default.

---
 arch/arm/boot/dts/rk3188.dtsi |    1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/rk3188.dtsi +1 -0
index a20d501..c316468 100644
@@ -548,6 +548,7 @@
 
 &global_timer {
 	interrupts = <GIC_PPI 11 0xf04>;
+	status = "disabled";
 };
 
 &local_timer {
Signature · 1 line
1.7.9.5
#13 lore raw

Re: [PATCH v7 5/7] clocksource/drivers/rockchip_timer: implement clocksource timer

In reply to Alexander Kochetkov
url: https://github.com/0day-ci/linux/commits/Alexander-Kochetkov/Implement-clocksource-for-rockchip-SoC-using-rockchip-timer/20170324-113008 config: arm64-defconfig (attached as .config) compiler…

Hi Alexander,

[auto build test ERROR on tip/timers/core]
[also build test ERROR on v4.11-rc3 next-20170323]
[cannot apply to rockchip/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Alexander-Kochetkov/Implement-clocksource-for-rockchip-SoC-using-rockchip-timer/20170324-113008
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

All errors (new ones prefixed by >>):

In file included from include/linux/tick.h:7:0,
from drivers//acpi/processor_idle.c:32:

>> include/linux/clockchips.h:232:2: error: invalid preprocessing directive #els
    #els
     ^~~
>> include/linux/clockchips.h:233:19: error: static declaration of 'clockevent_probe' follows non-static declaration
    static inline int clockevent_probe(void) { return 0; }
                      ^~~~~~~~~~~~~~~~
   include/linux/clockchips.h:231:12: note: previous declaration of 'clockevent_probe' was here
    extern int clockevent_probe(void);
               ^~~~~~~~~~~~~~~~
--
>> drivers//clocksource/clkevt-probe.c:20:29: fatal error: linux/clockchip.h: No such file or directory
    #include <linux/clockchip.h>
                                ^

compilation terminated.

vim +232 include/linux/clockchips.h

d316c57f Thomas Gleixner 2007-02-16  226  
376bc271 Daniel Lezcano  2016-04-19  227  #define CLOCKEVENT_OF_DECLARE(name, compat, fn) \
376bc271 Daniel Lezcano  2016-04-19  228  	OF_DECLARE_1_RET(clkevt, name, compat, fn)
376bc271 Daniel Lezcano  2016-04-19  229  
376bc271 Daniel Lezcano  2016-04-19  230  #ifdef CONFIG_CLKEVT_PROBE
376bc271 Daniel Lezcano  2016-04-19  231  extern int clockevent_probe(void);
376bc271 Daniel Lezcano  2016-04-19 @232  #els
376bc271 Daniel Lezcano  2016-04-19 @233  static inline int clockevent_probe(void) { return 0; }
376bc271 Daniel Lezcano  2016-04-19  234  #endif
376bc271 Daniel Lezcano  2016-04-19  235  
9eed56e8 Ingo Molnar     2015-04-02  236  #endif /* _LINUX_CLOCKCHIPS_H */

:::::: The code at line 232 was first introduced by commit
:::::: 376bc27150f180d9f5eddec6a14117780177589d clockevents: Add a clkevt-of mechanism like clksrc-of

:::::: TO: Daniel Lezcano <[email protected]> :::::: CC: Daniel Lezcano <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 34554 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170324/872b4abd/attachment-0001.gz>

#14 lore raw

Re: [PATCH v7 5/7] clocksource/drivers/rockchip_timer: implement clocksource timer

The patch series should be applied after the patches [1] and [2] haven?t merged yet into the kernel. That mention in the cover letter.

[1] https://lkml.org/lkml/2017/3/22/420
[2] https://lkml.org/lkml/2017/3/22/426

Quoted 61 lines

24 ????? 2017 ?., ? 11:29, kbuild test robot <[email protected]> ???????(?):

Hi Alexander,

[auto build test ERROR on tip/timers/core]
[also build test ERROR on v4.11-rc3 next-20170323]
[cannot apply to rockchip/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Alexander-Kochetkov/Implement-clocksource-for-rockchip-SoC-using-rockchip-timer/20170324-113008
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

All errors (new ones prefixed by >>):

In file included from include/linux/tick.h:7:0,
from drivers//acpi/processor_idle.c:32:

Quoted 1 line
Quoted 1 line

include/linux/clockchips.h:232:2: error: invalid preprocessing directive #els

#els

    ^~~
Quoted 1 line
Quoted 1 line

include/linux/clockchips.h:233:19: error: static declaration of 'clockevent_probe' follows non-static declaration

static inline int clockevent_probe(void) { return 0; }

                     ^~~~~~~~~~~~~~~~
  include/linux/clockchips.h:231:12: note: previous declaration of 'clockevent_probe' was here
   extern int clockevent_probe(void);
              ^~~~~~~~~~~~~~~~

--

Quoted 1 line
Quoted 1 line

drivers//clocksource/clkevt-probe.c:20:29: fatal error: linux/clockchip.h: No such file or directory

   #include <linux/clockchip.h>
                               ^

compilation terminated.

vim +232 include/linux/clockchips.h

d316c57f Thomas Gleixner 2007-02-16  226  
376bc271 Daniel Lezcano  2016-04-19  227  #define CLOCKEVENT_OF_DECLARE(name, compat, fn) \
376bc271 Daniel Lezcano  2016-04-19  228  	OF_DECLARE_1_RET(clkevt, name, compat, fn)
376bc271 Daniel Lezcano  2016-04-19  229  
376bc271 Daniel Lezcano  2016-04-19  230  #ifdef CONFIG_CLKEVT_PROBE
376bc271 Daniel Lezcano  2016-04-19  231  extern int clockevent_probe(void);
376bc271 Daniel Lezcano  2016-04-19 @232  #els
376bc271 Daniel Lezcano  2016-04-19 @233  static inline int clockevent_probe(void) { return 0; }
376bc271 Daniel Lezcano  2016-04-19  234  #endif
376bc271 Daniel Lezcano  2016-04-19  235  
9eed56e8 Ingo Molnar     2015-04-02  236  #endif /* _LINUX_CLOCKCHIPS_H */

:::::: The code at line 232 was first introduced by commit
:::::: 376bc27150f180d9f5eddec6a14117780177589d clockevents: Add a clkevt-of mechanism like clksrc-of

:::::: TO: Daniel Lezcano <[email protected]> :::::: CC: Daniel Lezcano <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
<.config.gz>

#15 lore raw

Re: [PATCH v7 5/7] clocksource/drivers/rockchip_timer: implement clocksource timer

Quoted 5 lines · Alexander Kochetkov

The patch series should be applied after the patches [1] and [2] haven?t merged yet into the kernel. That mention in the cover letter.

[1] https://lkml.org/lkml/2017/3/22/420
[2] https://lkml.org/lkml/2017/3/22/426

Thanks for the fix Alexander.

-- Daniel

Signature · 5 lines
 <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
maintainer
#2 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

In reply to Alexander Kochetkov
Quoted 7 lines · Alexander Kochetkov

From: Daniel Lezcano <[email protected]>

The CLOCKSOURCE_OF_DECLARE() was introduced before the CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the clockevent and the clocksource are both initialized in the same init routine.

Quoted 8 lines

With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can now split the clocksource and the clockevent init code. However, the device tree may specify a single node, so the same node will be passed to the clockevent/clocksource's init function, with the same base address.

with this patch it is possible to specify an attribute to the timer's node to specify if it is a clocksource or a clockevent and define two timers node.

Daniel and I discussed and agreed against this a while back. What changed?

Quoted 6 lines

For example:

        timer: timer at 98400000 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400000 0x42>;

This overlaps the next node. You can change this to 0x10, but are these really 2 independent h/w blocks? Don't design the nodes around the current needs of Linux.

Quoted 3 lines
                interrupts = <19 1>;
                clocks = <&coreclk>;
                clockevent;

This is not needed. The presence of "interrupts" is enough to say use this timer for clockevent.

Quoted 7 lines
        };

        timer: timer at 98400010 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400010 0x42>;
                clocks = <&coreclk>;
                clocksource;

Likewise.

Quoted 6 lines
        };

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Quoted 27 lines
---
 Documentation/devicetree/bindings/timer/timer.txt |   38 +++++++++++++++++++++
 drivers/clocksource/clkevt-probe.c                |    7 ++++
 drivers/clocksource/clksrc-probe.c                |    7 ++++
 3 files changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/timer.txt
Documentation/devicetree/bindings/timer/timer.txt new file +11 -0
new file mode 100644
index 0000000..f1ee0cf
@@ -0,0 +1,38 @@
+
+Specifying timer information for devices
+========================================
+
+The timer can be declared via the macro:
+
+CLOCKSOURCE_OF_DECLARE(name, init) if it is a clocksource
+CLOCKEVENT_OF_DECLARE(name, init) if it is a clockevent
+
+The CLOCKSOURCE_OF_DECLARE() was introduced before the
+CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the

Documentation/devicetree/bindings/timer/timer.txt line 21

Quoted 10 lines
Documentation/devicetree/bindings/timer/timer.txt new file +10 -0
+clockevent and the clocksource are both initialized in the same init
+routine.
+
+With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can
+now split the clocksource and the clockevent init code. However, the
+device tree may specify a single node, so the same node will be passed
+to the clockevent/clocksource's init function, with the same base
+address. It is possible to specify an attribute to the timer's node to
+specify if it is a clocksource or a clockevent and define two timers
+node.

This is all Linux details and doesn't belong in binding docs.

Quoted 56 lines
Documentation/devicetree/bindings/timer/timer.txt new file +17 -0
+
+Example:
+
+	timer: timer at 98400000 {
+		compatible = "moxa,moxart-timer";
+		reg = <0x98400000 0x42>;
+		interrupts = <19 1>;
+		clocks = <&coreclk>;
+		clockevent;
+	};
+
+	timer: timer at 98400010 {
+		compatible = "moxa,moxart-timer";
+		reg = <0x98400010 0x42>;
+		clocks = <&coreclk>;
+		clocksource;
+	};
drivers/clocksource/clkevt-probe.c +7 -0
index eb89b50..fa02ac1 100644
@@ -37,6 +37,13 @@ int __init clockevent_probe(void)
 
 		init_func = match->data;
 
+		/*
+		 * The device node describes a clocksource, ignore it
+		 * as we are in the clockevent init routine.
+		 */
+		if (of_property_read_bool(np, "clocksource"))
+			continue;
+
 		ret = init_func(np);
 		if (ret) {
 			pr_warn("Failed to initialize '%s' (%d)\n",
drivers/clocksource/clksrc-probe.c +7 -0
index bc62be9..ce50f33 100644
@@ -38,6 +38,13 @@ void __init clocksource_probe(void)
 
 		init_func_ret = match->data;
 
+		/*
+		 * The device node describes a clockevent, ignore it
+		 * as we are in the clocksource init routine.
+		 */
+		if (of_property_read_bool(np, "clockevent"))
+			continue;
+
 		ret = init_func_ret(np);
 		if (ret) {
 			pr_err("Failed to initialize '%s': %d",
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

Quoted 14 lines · Rob Herring
Quoted 13 lines · Alexander Kochetkov

From: Daniel Lezcano <[email protected]>

The CLOCKSOURCE_OF_DECLARE() was introduced before the CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the clockevent and the clocksource are both initialized in the same init routine.

With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can now split the clocksource and the clockevent init code. However, the device tree may specify a single node, so the same node will be passed to the clockevent/clocksource's init function, with the same base address.

Quoted 5 lines
Quoted 2 lines

with this patch it is possible to specify an attribute to the timer's node to specify if it is a clocksource or a clockevent and define two timers node.

Daniel and I discussed and agreed against this a while back. What changed?

Hi Rob,

Quoted 9 lines
Quoted 5 lines

For example:

        timer: timer at 98400000 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400000 0x42>;

This overlaps the next node. You can change this to 0x10, but are these really 2 independent h/w blocks? Don't design the nodes around the current needs of Linux.

Mmh, thanks for raising this. Conceptually speaking there are two (or more) different entities, the clocksource and the clockevents but they share the same IP block.

In the driver timer-sp804.c there is a fragile mechanism with the timer counting assuming the timers are declared in a specific order in the DT (integratorcp.dts). There are multiple nodes, which are IIUC overlapping like what you are describing.

I'm a bit puzzled with how this should be done.

Do you have a suggestion ?

Quoted 6 lines
Quoted 3 lines
                interrupts = <19 1>;
                clocks = <&coreclk>;
                clockevent;

This is not needed. The presence of "interrupts" is enough to say use this timer for clockevent.

Yes, that is true if no drivers was already taking CLOCKSOURCE_OF and initializing the clockevent. The driver will pass through the clocksource_probe function, check the interrupt and bail out because there is an interrupt declared and assume it is a clockevent, so no initialization for the driver. IOW, it is not backward compatible.

We need this attribute somehow in order to separate clearly a clocksource or a clockevent with a new implementation.

Quoted 12 lines
Quoted 7 lines
        };

        timer: timer at 98400010 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400010 0x42>;
                clocks = <&coreclk>;
                clocksource;

Likewise.

Quoted 2 lines
        };
Quoted 7 lines
Quoted 4 lines

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Yes, there is already the bindings, but that force to do some hackish initialization.

I would like to give the opportunity to declare separately a clocksource and a clockevent, in order to have full control of how this is initialized.

#4 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

Hi,

Quoted 33 lines · Daniel Lezcano
Quoted 14 lines · Rob Herring
Quoted 13 lines · Alexander Kochetkov

From: Daniel Lezcano <[email protected]>

The CLOCKSOURCE_OF_DECLARE() was introduced before the CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the clockevent and the clocksource are both initialized in the same init routine.

With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can now split the clocksource and the clockevent init code. However, the device tree may specify a single node, so the same node will be passed to the clockevent/clocksource's init function, with the same base address.

Quoted 5 lines
Quoted 2 lines

with this patch it is possible to specify an attribute to the timer's node to specify if it is a clocksource or a clockevent and define two timers node.

Daniel and I discussed and agreed against this a while back. What changed?

Hi Rob,

Quoted 9 lines
Quoted 5 lines

For example:

        timer: timer at 98400000 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400000 0x42>;

This overlaps the next node. You can change this to 0x10, but are these really 2 independent h/w blocks? Don't design the nodes around the current needs of Linux.

Quoted 5 lines

Mmh, thanks for raising this. Conceptually speaking there are two (or more) different entities, the clocksource and the clockevents but they share the same IP block.

From the DT's PoV, this is one entity, which is the IP block.

The clocksource/clockevent concept is a Linux implementation detail. The DT cannot and should not be aware of that.

[...]

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
                interrupts = <19 1>;
                clocks = <&coreclk>;
                clockevent;

This is not needed. The presence of "interrupts" is enough to say use this timer for clockevent.

Quoted 8 lines

Yes, that is true if no drivers was already taking CLOCKSOURCE_OF and initializing the clockevent. The driver will pass through the clocksource_probe function, check the interrupt and bail out because there is an interrupt declared and assume it is a clockevent, so no initialization for the driver. IOW, it is not backward compatible.

We need this attribute somehow in order to separate clearly a clocksource or a clockevent with a new implementation.

Why? A single IP block can provide the functionality of both (though there are reasons that functionality may be mutually exclusive). What is the benefit of this split?

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Yes, there is already the bindings, but that force to do some hackish initialization.

Here, you are forcing hackish DT changes that do not truly describe HW. How is that better?

Quoted 2 lines

I would like to give the opportunity to declare separately a clocksource and a clockevent, in order to have full control of how this is initialized.

To me it sounds like what we need is Linux infrastructure that allows one to register a device as having both clockevent/clocksource functionality.

That way, we can choose to do something sane at boot time, and if the user really wants specific devices used in specific ways, they can request that.

Thanks,
Mark.

#5 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

Quoted 60 lines · Mark Rutland

Hi,

Quoted 29 lines · Daniel Lezcano
Quoted 14 lines · Rob Herring
Quoted 13 lines · Alexander Kochetkov

From: Daniel Lezcano <[email protected]>

The CLOCKSOURCE_OF_DECLARE() was introduced before the CLOCKEVENT_OF_DECLARE() and that resulted in some abuse where the clockevent and the clocksource are both initialized in the same init routine.

With the introduction of the CLOCKEVENT_OF_DECLARE(), the driver can now split the clocksource and the clockevent init code. However, the device tree may specify a single node, so the same node will be passed to the clockevent/clocksource's init function, with the same base address.

Quoted 5 lines
Quoted 2 lines

with this patch it is possible to specify an attribute to the timer's node to specify if it is a clocksource or a clockevent and define two timers node.

Daniel and I discussed and agreed against this a while back. What changed?

Hi Rob,

Quoted 6 lines
Quoted 5 lines

For example:

        timer: timer at 98400000 {
                compatible = "moxa,moxart-timer";
                reg = <0x98400000 0x42>;
Quoted 7 lines
Quoted 3 lines

This overlaps the next node. You can change this to 0x10, but are these really 2 independent h/w blocks? Don't design the nodes around the current needs of Linux.

Mmh, thanks for raising this. Conceptually speaking there are two (or more) different entities, the clocksource and the clockevents but they share the same IP block.

From the DT's PoV, this is one entity, which is the IP block.

The clocksource/clockevent concept is a Linux implementation detail. The DT cannot and should not be aware of that.

[...]

Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
                interrupts = <19 1>;
                clocks = <&coreclk>;
                clockevent;

This is not needed. The presence of "interrupts" is enough to say use this timer for clockevent.

Yes, that is true if no drivers was already taking CLOCKSOURCE_OF and initializing the clockevent. The driver will pass through the clocksource_probe function, check the interrupt and bail out because there is an interrupt declared and assume it is a clockevent, so no initialization for the driver. IOW, it is not backward compatible.

Quoted 6 lines
Quoted 2 lines

We need this attribute somehow in order to separate clearly a clocksource or a clockevent with a new implementation.

Why? A single IP block can provide the functionality of both (though there are reasons that functionality may be mutually exclusive). What is the benefit of this split?

Hi Mark,

You can have several timers on the system and may want to use the clockevents from one IP block and the clocksource from another IP block. For example, in the case of a bogus clocksource.

Moreover there are some drivers with a node for a clocksource and another one for the clockevent, and the driver is assuming the clockevent is defined first and then the clocksource.

eg.

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;
}

Even if that works, it is a fragile mechanism.

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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Yes, there is already the bindings, but that force to do some hackish initialization.

Here, you are forcing hackish DT changes that do not truly describe HW. How is that better?

So if this is hackish DT changes, then the existing DTs should be fixed, no?

Quoted 6 lines
Quoted 2 lines

I would like to give the opportunity to declare separately a clocksource and a clockevent, in order to have full control of how this is initialized.

To me it sounds like what we need is Linux infrastructure that allows one to register a device as having both clockevent/clocksource functionality.

That was the idea. Create a macro CLOCKEVENT_OF and CLOCKSOURCE_OF both of them calling their respective init routines. And in addition a TIMER_OF doing both CLOCKEVENT_OF and CLOCKSOURCE_OF.

It is the DT which does not allow to do this separation.

Would be the following approach more acceptable ?

1. Replace all CLOCKSOURCE_OF by TIMER_OF (just renaming)
2. A node can have a clockevent and|or a clocksource attributes
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.

Quoted 3 lines

That way, we can choose to do something sane at boot time, and if the user really wants specific devices used in specific ways, they can request that.

Signature · 5 lines
 <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
#6 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

Quoted 8 lines · Daniel Lezcano
Quoted 3 lines · Mark Rutland
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Rob Herring

On Wed, Mar 22, 2017 at 06:48:28PM +0300, Alexander Kochetkov wrote:

You can have several timers on the system and may want to use the clockevents from one IP block and the clocksource from another IP block. For example, in the case of a bogus clocksource.

I understand this. However, what I was trying to say is that *how* we use a particular device should be a software decision. I have a more concrete suggestion on that below.

Quoted 39 lines

Moreover there are some drivers with a node for a clocksource and another one for the clockevent, and the driver is assuming the clockevent is defined first and then the clocksource.

eg.

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;
}
Quoted 5 lines

Even if that works, it is a fragile mechanism.

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.

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.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Yes, there is already the bindings, but that force to do some hackish initialization.

Here, you are forcing hackish DT changes that do not truly describe HW. How is that better?

So if this is hackish DT changes, then the existing DTs should be fixed, no?

Yes.

For the above snippet, the only thing that needs to change is the comment.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

I would like to give the opportunity to declare separately a clocksource and a clockevent, in order to have full control of how this is initialized.

To me it sounds like what we need is Linux infrastructure that allows one to register a device as having both clockevent/clocksource functionality.

That was the idea. Create a macro CLOCKEVENT_OF and CLOCKSOURCE_OF both of them calling their respective init routines. And in addition a TIMER_OF doing both CLOCKEVENT_OF and CLOCKSOURCE_OF.

Quoted 5 lines

It is the DT which does not allow to do this separation.

Would be the following approach more acceptable ?

1. Replace all CLOCKSOURCE_OF by TIMER_OF (just renaming)

I am fine with this renaming.

Quoted 1 line

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.

Quoted 7 lines

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).

Thanks,
Mark.

#18 lore raw
In reply to Alexander Kochetkov

Hello, Daniel.

Due to recent comments from Mark[1], may be is better to apply v6[2] series instead of v7[3]? Because my main goal was to fix wall time on rk3188. And I did it the same way how that was already done for other timer drivers (one of possible solution).

You can rename CLOCKSOURCE_OF to TIMER_OF later. I can help with that, but I don?t think it is good idea to combine my changes and timer framework cleanups/improvements into single series.

And I thinks, that probably is is better to drop [3] and [4] and revert 0c8893c9095d ("clockevents: Add a clkevt-of mechanism like clksrc-of?).

What do you think?

[1] https://lkml.org/lkml/2017/3/29/286
[2] https://lkml.org/lkml/2017/1/31/401
[3] https://lkml.org/lkml/2017/3/22/508
[4] https://lkml.org/lkml/2017/3/22/420
[5] https://lkml.org/lkml/2017/3/22/426

Quoted 52 lines

22 ????? 2017 ?., ? 18:48, Alexander Kochetkov <[email protected]> ???????(?):

Hello, Daniel, Heiko.

Here is try 7 :) Could you please take a look into it?

rockchip_timer init code implemented using CLOCKEVENT_OF_DECLARE() introduced in commit 0c8893c9095d ("clockevents: Add a clkevt-of mechanism like clksrc-of")

There is change in the arch/arm/mach-rockchip/rockchip.c.

This series should be applied after the commit:
https://lkml.org/lkml/2017/3/22/426

As without the commit, you will get linker error ("clkevt-probe.c:63:
undefined reference to `__clkevt_of_table?")

Regards,
Alexander.

Alexander Kochetkov (6):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer
ARM: dts: rockchip: add clockevent attribute to rockchip timers clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

Daniel Lezcano (1):
clocksource/drivers/clksrc-evt-probe: Describe with the DT both the
clocksource and the clockevent

.../bindings/timer/rockchip,rk-timer.txt           |   12 +-
Documentation/devicetree/bindings/timer/timer.txt  |   38 ++++
arch/arm/boot/dts/rk3036.dtsi                      |    1 +
arch/arm/boot/dts/rk3188.dtsi                      |   19 ++
arch/arm/boot/dts/rk322x.dtsi                      |    3 +-
arch/arm/boot/dts/rk3288.dtsi                      |    1 +
arch/arm/mach-rockchip/rockchip.c                  |    2 +
arch/arm64/boot/dts/rockchip/rk3368.dtsi           |    1 +
drivers/clocksource/Kconfig                        |    2 +
drivers/clocksource/clkevt-probe.c                 |    7 +
drivers/clocksource/clksrc-probe.c                 |    7 +
drivers/clocksource/rockchip_timer.c               |  215 ++++++++++++++------
12 files changed, 241 insertions(+), 67 deletions(-)

create mode 100644 Documentation/devicetree/bindings/timer/timer.txt

Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

In reply to Mark Rutland
Quoted 59 lines · Mark Rutland
Quoted 8 lines · Daniel Lezcano
Quoted 3 lines · Mark Rutland
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Rob Herring

On Wed, Mar 22, 2017 at 06:48:28PM +0300, Alexander Kochetkov wrote:

You can have several timers on the system and may want to use the clockevents from one IP block and the clocksource from another IP block. For example, in the case of a bogus clocksource.

I understand this. However, what I was trying to say is that *how* we use a particular device should be a software decision. I have a more concrete suggestion on that below.

Quoted 39 lines

Moreover there are some drivers with a node for a clocksource and another one for the clockevent, and the driver is assuming the clockevent is defined first and then the clocksource.

eg.

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;
}
Quoted 5 lines

Even if that works, it is a fragile mechanism.

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.

Quoted 6 lines

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.

Quoted 8 lines

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.

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.

Quoted 38 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

With this approach, we allow a mechanism to clearly define a clocksource or a clockevent without aerobatics we can find around in some drivers:

	timer-sp804.c, arc-timer.c, dw_apb_timer_of.c, mps2-timer.c,
	renesas-ostm.c, time-efm32.c, time-lpc32xx.c.

These all already have bindings and work. What problem are you trying to solve other than restructuring Linux?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Yes, there is already the bindings, but that force to do some hackish initialization.

Here, you are forcing hackish DT changes that do not truly describe HW. How is that better?

So if this is hackish DT changes, then the existing DTs should be fixed, no?

Yes.

For the above snippet, the only thing that needs to change is the comment.

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

I would like to give the opportunity to declare separately a clocksource and a clockevent, in order to have full control of how this is initialized.

To me it sounds like what we need is Linux infrastructure that allows one to register a device as having both clockevent/clocksource functionality.

That was the idea. Create a macro CLOCKEVENT_OF and CLOCKSOURCE_OF both of them calling their respective init routines. And in addition a TIMER_OF doing both CLOCKEVENT_OF and CLOCKSOURCE_OF.

Quoted 5 lines

It is the DT which does not allow to do this separation.

Would be the following approach more acceptable ?

1. Replace all CLOCKSOURCE_OF by TIMER_OF (just renaming)

Quoted 8 lines

I am fine with this renaming.

Quoted 1 line

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' ?).

Quoted 8 lines
Quoted 7 lines

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.

Quoted 7 lines

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. Regarding the number of timers, I do believe it is much better to simply tell which one we want to use via the DT (assuming the DT is a description of the desired hardware, not all the available hardware).

Signature · 5 lines
 <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
#8 lore raw

Re: [PATCH v7 1/7] clocksource/drivers/clksrc-evt-probe: Describe with the DT both the clocksource and the clockevent

Quoted 43 lines · Daniel Lezcano
Quoted 42 lines · Mark Rutland
Quoted 33 lines · Daniel Lezcano

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;
}
Quoted 3 lines

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*.

Quoted 8 lines
Quoted 3 lines

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.

Quoted 11 lines
Quoted 8 lines

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.

Quoted 3 lines

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.

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 1 line

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.

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

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.

Quoted 5 lines
Quoted 3 lines

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.

#19 lore raw
In reply to Alexander Kochetkov
Quoted 1 line · Alexander Kochetkov

Hello, Daniel.

Hi Alexander,

Quoted 4 lines

Due to recent comments from Mark[1], may be is better to apply v6[2] series instead of v7[3]? Because my main goal was to fix wall time on rk3188. And I did it the same way how that was already done for other timer drivers (one of possible solution).

Quoted 8 lines

You can rename CLOCKSOURCE_OF to TIMER_OF later. I can help with that, but I don?t think it is good idea to combine my changes and timer framework cleanups/improvements into single series.

And I thinks, that probably is is better to drop [3] and [4] and revert 0c8893c9095d ("clockevents: Add a clkevt-of mechanism like clksrc-of?).

What do you think?

I share your opinion.

-- Daniel

Quoted 59 lines

[1] https://lkml.org/lkml/2017/3/29/286
[2] https://lkml.org/lkml/2017/1/31/401
[3] https://lkml.org/lkml/2017/3/22/508
[4] https://lkml.org/lkml/2017/3/22/420
[5] https://lkml.org/lkml/2017/3/22/426

Quoted 52 lines

22 ????? 2017 ?., ? 18:48, Alexander Kochetkov <[email protected]> ???????(?):

Hello, Daniel, Heiko.

Here is try 7 :) Could you please take a look into it?

rockchip_timer init code implemented using CLOCKEVENT_OF_DECLARE() introduced in commit 0c8893c9095d ("clockevents: Add a clkevt-of mechanism like clksrc-of")

There is change in the arch/arm/mach-rockchip/rockchip.c.

This series should be applied after the commit:
https://lkml.org/lkml/2017/3/22/426

As without the commit, you will get linker error ("clkevt-probe.c:63:
undefined reference to `__clkevt_of_table?")

Regards,
Alexander.

Alexander Kochetkov (6):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer
ARM: dts: rockchip: add clockevent attribute to rockchip timers clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

Daniel Lezcano (1):
clocksource/drivers/clksrc-evt-probe: Describe with the DT both the
clocksource and the clockevent

.../bindings/timer/rockchip,rk-timer.txt           |   12 +-
Documentation/devicetree/bindings/timer/timer.txt  |   38 ++++
arch/arm/boot/dts/rk3036.dtsi                      |    1 +
arch/arm/boot/dts/rk3188.dtsi                      |   19 ++
arch/arm/boot/dts/rk322x.dtsi                      |    3 +-
arch/arm/boot/dts/rk3288.dtsi                      |    1 +
arch/arm/mach-rockchip/rockchip.c                  |    2 +
arch/arm64/boot/dts/rockchip/rk3368.dtsi           |    1 +
drivers/clocksource/Kconfig                        |    2 +
drivers/clocksource/clkevt-probe.c                 |    7 +
drivers/clocksource/clksrc-probe.c                 |    7 +
drivers/clocksource/rockchip_timer.c               |  215 ++++++++++++++------
12 files changed, 241 insertions(+), 67 deletions(-)

create mode 100644 Documentation/devicetree/bindings/timer/timer.txt

Signature · 1 line
1.7.9.5
Signature · 5 lines
 <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