Skip to contentSkip to conversation

Porting Mediatek timer driver to kernel module

PATCH New Freddy Hsin 4 participants 10 messages Jul 28, 2020 – Oct 5, 2020 Clocksource, clockevent drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Porting Mediatek timer driver to kernel module

Porting Mediatek timer driver to kernel module for GKI (Generic Kernel Image). Clocksource mmio functions are exported for Mediatek timer init function.

This patch depends on the timer-of patch submitted by Baolin Wang
https://lkml.org/lkml/2020/3/24/72

Freddy Hsin (2):
kernel: time: remove init section label of sched_clock_register
timer: mt6873: porting timer driver to loadable module

 drivers/clocksource/Kconfig          |    2 +-
 drivers/clocksource/mmio.c           |    4 +++-
 drivers/clocksource/timer-mediatek.c |   39 ++++++++++++++++++++++++++++++++++
 kernel/time/sched_clock.c            |    1 +
#1 lore raw

PATCH 1/2 kernel: time: export sched_clock_register function

export sched_clock_register function, because the Mediatek timer loadable module depends on this function

---
 kernel/time/sched_clock.c |    1 +
 1 file changed, 1 insertion(+)
kernel/time/sched_clock.c +1 -0
index fa3f800..e1d5afe 100644
@@ -239,6 +239,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL(sched_clock_register);
 
 void __init generic_sched_clock_init(void)
 {
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v1 1/2] kernel: time: export sched_clock_register function

Freddy,

Freddy Hsin <[email protected]> writes:

please do not come up with random prefixes. Just look at the topmost two commits on that file:

2c8bd58812ee ("time/sched_clock: Expire timer in hardirq context") 2707745533d6 ("time/sched_clock: Disable interrupts in sched_clock_register()")

Also the sentence after the colon starts with an uppercase letter.

Please change 'sched_clock_register function' to 'sched_clock_register()' which makes it clear that this is a function

Quoted 2 lines

export sched_clock_register function, because the Mediatek timer loadable module depends on this function

Again sentences start with an uppercase letter. Also the reason for exporting this is wrong. There is no mediatek timer module now.

The point of exporting this (if at all) is that it's required for any ARM SoC timer driver to be modularized.

kernel/time/sched_clock.c static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt) · line 242

Quoted 5 lines
kernel/time/sched_clock.c +1 -0
@@ -239,6 +239,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL(sched_clock_register);

EXPORT_SYMBOL_GPL() please.

Thanks,

tglx

#3 lore raw

Re: [PATCH v1 1/2] kernel: time: export sched_clock_register function

In reply to Freddy Hsin

Hi Freddy,

Quoted 2 lines · Freddy Hsin

export sched_clock_register function, because the Mediatek timer loadable module depends on this function

That is not a sufficient reason to ask for exporting a symbol from the core framework.

It is the second patch asking for exporting the symbols because of GKI.

If we want to do this move, it is important to understand what that will imply by doing the changes as a whole:

- Identify the routines which will need EXPORT_SYMBOL_GPL

- Show it is safe to use them with what that implies as module. eg.
What about cpuidle drivers using the broadcast timers?

- As pointed by Thomas, TIMER_OF_DECLARE must be adapted to handle the
module cases

The conversion to all modules is not as straightforward as just exporting a symbol and the changes must be provided with the proof the impact has been studied and anticipated.

Quoted 14 lines
---
 kernel/time/sched_clock.c |    1 +
 1 file changed, 1 insertion(+)
kernel/time/sched_clock.c +1 -0
index fa3f800..e1d5afe 100644
@@ -239,6 +239,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL(sched_clock_register);
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
#4 lore raw

PATCH 2/2 timer: mt6873: porting Mediatek timer driver to loadable module

In reply to Freddy Hsin

porting Mediatek timer driver to loadable module

---
 drivers/clocksource/Kconfig          |    2 +-
 drivers/clocksource/mmio.c           |    4 +++-
 drivers/clocksource/timer-mediatek.c |   39 ++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
drivers/clocksource/Kconfig +1 -1
index 9141838..538351a 100644
@@ -472,7 +472,7 @@ config SYS_SUPPORTS_SH_CMT
 	bool
 
 config MTK_TIMER
-	bool "Mediatek timer driver" if COMPILE_TEST
+	tristate "Mediatek timer driver"
 	depends on HAS_IOMEM
 	select TIMER_OF
 	select CLKSRC_MMIO
drivers/clocksource/mmio.c +3 -1
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
 	return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);
 
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:	Number of valid bits
  * @read:	One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 	unsigned long hz, int rating, unsigned bits,
 	u64 (*read)(struct clocksource *))
 {
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
 	return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);
drivers/clocksource/timer-mediatek.c +39 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
 	return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+	int (*timer_init)(struct device_node *node);
+	struct device_node *np = pdev->dev.of_node;
+
+	timer_init = of_device_get_match_data(&pdev->dev);
+	return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+	{
+		.compatible = "mediatek,mt6577-timer",
+		.data = mtk_gpt_init,
+	},
+	{
+		.compatible = "mediatek,mt6765-timer",
+		.data = mtk_syst_init,
+	},
+	{}
+};
+
+static struct platform_driver mtk_timer_driver = {
+	.probe = mtk_timer_probe,
+	.driver = {
+		.name = "mtk-timer",
+		.of_match_table = mtk_timer_match_table,
+	},
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH v1 2/2] timer: mt6873: porting Mediatek timer driver to loadable module

Freddy,

Freddy Hsin <[email protected]> writes:

again, please be more careful with subject lines. git log $FILE will give you a hint.

Quoted 1 line

porting Mediatek timer driver to loadable module

Repeating the sentence in the subject line is not giving any information. Also changelogs want to tell the WHY and not the WHAT. This also lacks any information why this is actually safe when booting such a system w/o this particular driver built in. What is early boot - up to module load - using as clocksource and timer?

drivers/clocksource/mmio.c u64 clocksource_mmio_readl_up(struct clocksource *c) · line 24

Quoted 9 lines
drivers/clocksource/mmio.c +1 -0
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
 	return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);

Again EXPORT_SYMBOL_GPL() and this wants to be a seperate patch. It has absolutely no business with the mediatek timer changes.

Quoted 13 lines
drivers/clocksource/mmio.c +1 -1
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:	Number of valid bits
  * @read:	One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 
 	unsigned long hz, int rating, unsigned bits,
 	u64 (*read)(struct clocksource *))

{

drivers/clocksource/mmio.c int __init clocksource_mmio_init(void __iomem *base, const char *name, · line 72

Quoted 4 lines
drivers/clocksource/mmio.c +1 -0
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
 	return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);

See above.

Quoted 46 lines
drivers/clocksource/timer-mediatek.c +31 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
 	return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+	int (*timer_init)(struct device_node *node);
+	struct device_node *np = pdev->dev.of_node;
+
+	timer_init = of_device_get_match_data(&pdev->dev);
+	return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+	{
+		.compatible = "mediatek,mt6577-timer",
+		.data = mtk_gpt_init,
+	},
+	{
+		.compatible = "mediatek,mt6765-timer",
+		.data = mtk_syst_init,
+	},
+	{}
+};
+
+static struct platform_driver mtk_timer_driver = {
+	.probe = mtk_timer_probe,
+	.driver = {
+		.name = "mtk-timer",
+		.of_match_table = mtk_timer_match_table,

drivers/clocksource/timer-mediatek.c static int __init mtk_gpt_init(struct device_node *node) · line 352

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +8 -0
+	},
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif

Sorry no. This is not going to happen.

The above probe, match table and platform driver structs plus the module* thingies are going to be repeated in every single driver which is going to support module build. Tons of boilerplate copied over and over again.

We had exactly the same before TIMER_OF_DECLARE() came around, so pretty please this want's to be some smart macro which handles all of this automatically.

Thanks,

tglx

#6 lore raw

Re: [PATCH v1 2/2] timer: mt6873: porting Mediatek timer driver to loadable module

Quoted 108 lines · Thomas Gleixner

Freddy,

Freddy Hsin <[email protected]> writes:

again, please be more careful with subject lines. git log $FILE will give you a hint.

Quoted 1 line

porting Mediatek timer driver to loadable module

Repeating the sentence in the subject line is not giving any information. Also changelogs want to tell the WHY and not the WHAT. This also lacks any information why this is actually safe when booting such a system w/o this particular driver built in. What is early boot - up to module load - using as clocksource and timer?

drivers/clocksource/mmio.c u64 clocksource_mmio_readl_up(struct clocksource *c) · line 24

Quoted 9 lines
drivers/clocksource/mmio.c +1 -0
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
      return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);

Again EXPORT_SYMBOL_GPL() and this wants to be a seperate patch. It has absolutely no business with the mediatek timer changes.

Quoted 13 lines
drivers/clocksource/mmio.c +1 -1
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:    Number of valid bits
  * @read:    One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 
      unsigned long hz, int rating, unsigned bits,
      u64 (*read)(struct clocksource *))

{

drivers/clocksource/mmio.c int __init clocksource_mmio_init(void __iomem *base, const char *name, · line 72

Quoted 4 lines
drivers/clocksource/mmio.c +1 -0
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
      return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);

See above.

Quoted 46 lines
drivers/clocksource/timer-mediatek.c +31 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
      return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+     int (*timer_init)(struct device_node *node);
+     struct device_node *np = pdev->dev.of_node;
+
+     timer_init = of_device_get_match_data(&pdev->dev);
+     return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+     {
+             .compatible = "mediatek,mt6577-timer",
+             .data = mtk_gpt_init,
+     },
+     {
+             .compatible = "mediatek,mt6765-timer",
+             .data = mtk_syst_init,
+     },
+     {}
+};
+
+static struct platform_driver mtk_timer_driver = {
+     .probe = mtk_timer_probe,
+     .driver = {
+             .name = "mtk-timer",
+             .of_match_table = mtk_timer_match_table,

drivers/clocksource/timer-mediatek.c static int __init mtk_gpt_init(struct device_node *node) · line 352

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +8 -0
+     },
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif

Sorry no. This is not going to happen.

Quoted 8 lines

The above probe, match table and platform driver structs plus the module* thingies are going to be repeated in every single driver which is going to support module build. Tons of boilerplate copied over and over again.

We had exactly the same before TIMER_OF_DECLARE() came around, so pretty please this want's to be some smart macro which handles all of this automatically.

Probably something like what I did for IRQCHIP?
https://lore.kernel.org/lkml/[email protected]/

Also, one point that came up with IRQCHIP is that if these drivers can be platform drivers, then they should stay that way even when it's built in. I'm not sure if that has any other special implications for timer code, but raising it in case you'd prefer that here too.

-Saravana

#7 lore raw

Re: [PATCH v1 2/2] timer: mt6873: porting Mediatek timer driver to loadable module

Quoted 121 lines · Saravana Kannan
Quoted 108 lines · Thomas Gleixner

Freddy,

Freddy Hsin <[email protected]> writes:

again, please be more careful with subject lines. git log $FILE will give you a hint.

Quoted 1 line

porting Mediatek timer driver to loadable module

Repeating the sentence in the subject line is not giving any information. Also changelogs want to tell the WHY and not the WHAT. This also lacks any information why this is actually safe when booting such a system w/o this particular driver built in. What is early boot - up to module load - using as clocksource and timer?

drivers/clocksource/mmio.c u64 clocksource_mmio_readl_up(struct clocksource *c) · line 24

Quoted 9 lines
drivers/clocksource/mmio.c +1 -0
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
      return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);

Again EXPORT_SYMBOL_GPL() and this wants to be a seperate patch. It has absolutely no business with the mediatek timer changes.

Quoted 13 lines
drivers/clocksource/mmio.c +1 -1
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:    Number of valid bits
  * @read:    One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 
      unsigned long hz, int rating, unsigned bits,
      u64 (*read)(struct clocksource *))

{

drivers/clocksource/mmio.c int __init clocksource_mmio_init(void __iomem *base, const char *name, · line 72

Quoted 4 lines
drivers/clocksource/mmio.c +1 -0
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
      return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);

See above.

Quoted 46 lines
drivers/clocksource/timer-mediatek.c +31 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
      return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+     int (*timer_init)(struct device_node *node);
+     struct device_node *np = pdev->dev.of_node;
+
+     timer_init = of_device_get_match_data(&pdev->dev);
+     return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+     {
+             .compatible = "mediatek,mt6577-timer",
+             .data = mtk_gpt_init,
+     },
+     {
+             .compatible = "mediatek,mt6765-timer",
+             .data = mtk_syst_init,
+     },
+     {}
+};
+
+static struct platform_driver mtk_timer_driver = {
+     .probe = mtk_timer_probe,
+     .driver = {
+             .name = "mtk-timer",
+             .of_match_table = mtk_timer_match_table,

drivers/clocksource/timer-mediatek.c static int __init mtk_gpt_init(struct device_node *node) · line 352

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +8 -0
+     },
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif

Sorry no. This is not going to happen.

Quoted 8 lines

The above probe, match table and platform driver structs plus the module* thingies are going to be repeated in every single driver which is going to support module build. Tons of boilerplate copied over and over again.

We had exactly the same before TIMER_OF_DECLARE() came around, so pretty please this want's to be some smart macro which handles all of this automatically.

Probably something like what I did for IRQCHIP?
https://lore.kernel.org/lkml/[email protected]/

Quoted 7 lines

Also, one point that came up with IRQCHIP is that if these drivers can be platform drivers, then they should stay that way even when it's built in. I'm not sure if that has any other special implications for timer code, but raising it in case you'd prefer that here too.

-Saravana

Hi Sravana,

Thanks for your advice. I already tried to add a common macro for timer ko drivers as you did for irqchip, but there are some issues need to be solved. e.g. the event handler cannot be changed to tick_handle_oneshot_broadcast and rcu warning caused by some cores are already in idle loop.

cat /proc/timer_list
==========================

Tick Device: mode: 1
Broadcast device
Clock Event Device: mtk-clkevt

 max_delta_ns:   330382104634
 min_delta_ns:   1000
 mult:           27917287
 shift:          31
 mode:           3
 next_event:     86709384386 nsecs

set_next_event: mtk_syst_clkevt_next_event
shutdown: mtk_syst_clkevt_shutdown
oneshot: mtk_syst_clkevt_oneshot
resume: mtk_syst_clkevt_resume
event_handler: tick_handle_periodic_broadcast
retries: 4

log of loading timer-mediatek.ko
============================

[   25.658884] init 7: Loaded kernel
module /lib/modules/timer-mediatek.ko
[   25.658946] =============================
[   25.660010] init 7: Loading module /lib/modules/reboot-mode.ko with
args ""
[   25.660364] WARNING: suspicious RCU usage
[   25.661831] 5.4.46-g325aef33bcb1-dirty #17 Tainted: G S
W        
[   25.662707] -----------------------------
[   25.663254] include/linux/rcupdate.h:601 rcu_read_lock() used
illegally while idle!
[   25.664279] 
[   25.664279] other info that might help us debug this:
[   25.665350] RCU used illegally from idle CPU!
[   25.665350] rcu_scheduler_active = 2, debug_locks = 1
[   25.666796] RCU used illegally from extended quiescent state!
[   25.667571] 2 locks held by swapper/1/0:
[   25.668105]  #0: ffffffec240b9a58 (tick_broadcast_lock){-.-.}, at:
__tick_broadcast_oneshot_control+0x6c/0x444
[   25.669460]  #1: ffffffec2410e020 (rcu_read_lock){....}, at:
rcu_lock_acquire+0x0/0x40
[   25.670536] stack backtrace:
[   25.671131] CPU: 1 PID: 0 Comm: swapper/1 Tainted: G S      W
5.4.46-g325aef33bcb1-dirty #17
[   25.672350] Hardware name: mediatek,mt6873 (DT)
[   25.672964] Call trace:
[   25.673310]  dump_backtrace.cfi_jt+0x0/0x4
[   25.673872]  dump_stack+0xf4/0x178
[   25.674344]  lockdep_rcu_suspicious+0x138/0x154
[   25.674961]  __cfi_slowpath+0x7c/0x1ec
[   25.675475]  clockevents_program_event+0x288/0x290
[   25.676126]  __tick_broadcast_oneshot_control+0x2f8/0x444
[   25.676856]  tick_broadcast_oneshot_control+0x58/0x68
[   25.677544]  cpuidle_enter_state+0x4c/0x314
[   25.678115]  cpuidle_enter+0x38/0x50
[   25.678608]  do_idle.llvm.7895800599653321206+0x1e0/0x2e8
[   25.679338]  cpu_startup_entry+0x24/0x28

BRs,
FreddyHsin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#8 lore raw

Re: [PATCH v1 2/2] timer: mt6873: porting Mediatek timer driver to loadable module

Quoted 200 lines · Freddy.Hsin
Quoted 121 lines · Saravana Kannan
Quoted 108 lines · Thomas Gleixner

Freddy,

Freddy Hsin <[email protected]> writes:

again, please be more careful with subject lines. git log $FILE will give you a hint.

Quoted 1 line

porting Mediatek timer driver to loadable module

Repeating the sentence in the subject line is not giving any information. Also changelogs want to tell the WHY and not the WHAT. This also lacks any information why this is actually safe when booting such a system w/o this particular driver built in. What is early boot - up to module load - using as clocksource and timer?

drivers/clocksource/mmio.c u64 clocksource_mmio_readl_up(struct clocksource *c) · line 24

Quoted 9 lines
drivers/clocksource/mmio.c +1 -0
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
      return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);

Again EXPORT_SYMBOL_GPL() and this wants to be a seperate patch. It has absolutely no business with the mediatek timer changes.

Quoted 13 lines
drivers/clocksource/mmio.c +1 -1
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:    Number of valid bits
  * @read:    One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 
      unsigned long hz, int rating, unsigned bits,
      u64 (*read)(struct clocksource *))

{

drivers/clocksource/mmio.c int __init clocksource_mmio_init(void __iomem *base, const char *name, · line 72

Quoted 4 lines
drivers/clocksource/mmio.c +1 -0
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
      return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);

See above.

Quoted 46 lines
drivers/clocksource/timer-mediatek.c +31 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
      return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+     int (*timer_init)(struct device_node *node);
+     struct device_node *np = pdev->dev.of_node;
+
+     timer_init = of_device_get_match_data(&pdev->dev);
+     return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+     {
+             .compatible = "mediatek,mt6577-timer",
+             .data = mtk_gpt_init,
+     },
+     {
+             .compatible = "mediatek,mt6765-timer",
+             .data = mtk_syst_init,
+     },
+     {}
+};
+
+static struct platform_driver mtk_timer_driver = {
+     .probe = mtk_timer_probe,
+     .driver = {
+             .name = "mtk-timer",
+             .of_match_table = mtk_timer_match_table,

drivers/clocksource/timer-mediatek.c static int __init mtk_gpt_init(struct device_node *node) · line 352

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +8 -0
+     },
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif

Sorry no. This is not going to happen.

Quoted 8 lines

The above probe, match table and platform driver structs plus the module* thingies are going to be repeated in every single driver which is going to support module build. Tons of boilerplate copied over and over again.

We had exactly the same before TIMER_OF_DECLARE() came around, so pretty please this want's to be some smart macro which handles all of this automatically.

Probably something like what I did for IRQCHIP?
https://lore.kernel.org/lkml/[email protected]/

Quoted 7 lines

Also, one point that came up with IRQCHIP is that if these drivers can be platform drivers, then they should stay that way even when it's built in. I'm not sure if that has any other special implications for timer code, but raising it in case you'd prefer that here too.

-Saravana

Hi Sravana,

Thanks for your advice. I already tried to add a common macro for timer ko drivers as you did for irqchip, but there are some issues need to be solved. e.g. the event handler cannot be changed to tick_handle_oneshot_broadcast and rcu warning caused by some cores are already in idle loop.

cat /proc/timer_list
==========================

Tick Device: mode: 1
Broadcast device
Clock Event Device: mtk-clkevt

 max_delta_ns:   330382104634
 min_delta_ns:   1000
 mult:           27917287
 shift:          31
 mode:           3
 next_event:     86709384386 nsecs

set_next_event: mtk_syst_clkevt_next_event
shutdown: mtk_syst_clkevt_shutdown
oneshot: mtk_syst_clkevt_oneshot
resume: mtk_syst_clkevt_resume
event_handler: tick_handle_periodic_broadcast
retries: 4

log of loading timer-mediatek.ko
============================

[   25.658884] init 7: Loaded kernel
module /lib/modules/timer-mediatek.ko
[   25.658946] =============================
[   25.660010] init 7: Loading module /lib/modules/reboot-mode.ko with
args ""
[   25.660364] WARNING: suspicious RCU usage
[   25.661831] 5.4.46-g325aef33bcb1-dirty #17 Tainted: G S
W        
[   25.662707] -----------------------------
[   25.663254] include/linux/rcupdate.h:601 rcu_read_lock() used
illegally while idle!
[   25.664279] 
[   25.664279] other info that might help us debug this:
[   25.665350] RCU used illegally from idle CPU!
[   25.665350] rcu_scheduler_active = 2, debug_locks = 1
[   25.666796] RCU used illegally from extended quiescent state!
[   25.667571] 2 locks held by swapper/1/0:
[   25.668105]  #0: ffffffec240b9a58 (tick_broadcast_lock){-.-.}, at:
__tick_broadcast_oneshot_control+0x6c/0x444
[   25.669460]  #1: ffffffec2410e020 (rcu_read_lock){....}, at:
rcu_lock_acquire+0x0/0x40
[   25.670536] stack backtrace:
[   25.671131] CPU: 1 PID: 0 Comm: swapper/1 Tainted: G S      W
5.4.46-g325aef33bcb1-dirty #17
[   25.672350] Hardware name: mediatek,mt6873 (DT)
[   25.672964] Call trace:
[   25.673310]  dump_backtrace.cfi_jt+0x0/0x4
[   25.673872]  dump_stack+0xf4/0x178
[   25.674344]  lockdep_rcu_suspicious+0x138/0x154
[   25.674961]  __cfi_slowpath+0x7c/0x1ec
[   25.675475]  clockevents_program_event+0x288/0x290
[   25.676126]  __tick_broadcast_oneshot_control+0x2f8/0x444
[   25.676856]  tick_broadcast_oneshot_control+0x58/0x68
[   25.677544]  cpuidle_enter_state+0x4c/0x314
[   25.678115]  cpuidle_enter+0x38/0x50
[   25.678608]  do_idle.llvm.7895800599653321206+0x1e0/0x2e8
[   25.679338]  cpu_startup_entry+0x24/0x28
Quoted 4 lines

BRs,
FreddyHsin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw

Re: [PATCH v1 2/2] timer: mt6873: porting Mediatek timer driver to loadable module

In reply to Saravana Kannan
Quoted 121 lines · Saravana Kannan
Quoted 108 lines · Thomas Gleixner

Freddy,

Freddy Hsin <[email protected]> writes:

again, please be more careful with subject lines. git log $FILE will give you a hint.

Quoted 1 line

porting Mediatek timer driver to loadable module

Repeating the sentence in the subject line is not giving any information. Also changelogs want to tell the WHY and not the WHAT. This also lacks any information why this is actually safe when booting such a system w/o this particular driver built in. What is early boot - up to module load - using as clocksource and timer?

drivers/clocksource/mmio.c u64 clocksource_mmio_readl_up(struct clocksource *c) · line 24

Quoted 9 lines
drivers/clocksource/mmio.c +1 -0
index 9de7515..5504569 100644
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
 {
      return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
 }
+EXPORT_SYMBOL(clocksource_mmio_readl_up);

Again EXPORT_SYMBOL_GPL() and this wants to be a seperate patch. It has absolutely no business with the mediatek timer changes.

Quoted 13 lines
drivers/clocksource/mmio.c +1 -1
 u64 clocksource_mmio_readl_down(struct clocksource *c)
 {
@@ -46,7 +47,7 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
  * @bits:    Number of valid bits
  * @read:    One of clocksource_mmio_read*() above
  */
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
+int clocksource_mmio_init(void __iomem *base, const char *name,
 
      unsigned long hz, int rating, unsigned bits,
      u64 (*read)(struct clocksource *))

{

drivers/clocksource/mmio.c int __init clocksource_mmio_init(void __iomem *base, const char *name, · line 72

Quoted 4 lines
drivers/clocksource/mmio.c +1 -0
@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,
 
      return clocksource_register_hz(&cs->clksrc, hz);
 }
+EXPORT_SYMBOL(clocksource_mmio_init);

See above.

Quoted 46 lines
drivers/clocksource/timer-mediatek.c +31 -0
index 9318edc..5c89b6b 100644
@@ -13,6 +13,9 @@
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
 #include <linux/sched_clock.h>
 #include <linux/slab.h>
 #include "timer-of.h"
@@ -309,5 +312,41 @@ static int __init mtk_gpt_init(struct device_node *node)
 
      return 0;
 }
+
+#ifdef MODULE
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+     int (*timer_init)(struct device_node *node);
+     struct device_node *np = pdev->dev.of_node;
+
+     timer_init = of_device_get_match_data(&pdev->dev);
+     return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+     {
+             .compatible = "mediatek,mt6577-timer",
+             .data = mtk_gpt_init,
+     },
+     {
+             .compatible = "mediatek,mt6765-timer",
+             .data = mtk_syst_init,
+     },
+     {}
+};
+
+static struct platform_driver mtk_timer_driver = {
+     .probe = mtk_timer_probe,
+     .driver = {
+             .name = "mtk-timer",
+             .of_match_table = mtk_timer_match_table,

drivers/clocksource/timer-mediatek.c static int __init mtk_gpt_init(struct device_node *node) · line 352

Quoted 10 lines
drivers/clocksource/timer-mediatek.c +8 -0
+     },
+};
+MODULE_DESCRIPTION("MEDIATEK Module timer driver");
+MODULE_LICENSE("GPL v2");
+
+module_platform_driver(mtk_timer_driver);
+#else
 TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
 TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#endif

Sorry no. This is not going to happen.

Quoted 8 lines

The above probe, match table and platform driver structs plus the module* thingies are going to be repeated in every single driver which is going to support module build. Tons of boilerplate copied over and over again.

We had exactly the same before TIMER_OF_DECLARE() came around, so pretty please this want's to be some smart macro which handles all of this automatically.

Probably something like what I did for IRQCHIP?
https://lore.kernel.org/lkml/[email protected]/

Quoted 7 lines

Also, one point that came up with IRQCHIP is that if these drivers can be platform drivers, then they should stay that way even when it's built in. I'm not sure if that has any other special implications for timer code, but raising it in case you'd prefer that here too.

-Saravana

Hi Sravana,

Thanks for your advice. I already tried to add a common macro for timer ko drivers as you did for irqchip, but there are some issues need to be solved. e.g. the event handler cannot be changed to tick_handle_oneshot_broadcast and rcu warning caused by some cores are already in idle loop.

cat /proc/timer_list
==========================

Tick Device: mode: 1
Broadcast device
Clock Event Device: mtk-clkevt

 max_delta_ns:   330382104634
 min_delta_ns:   1000
 mult:           27917287
 shift:          31
 mode:           3
 next_event:     86709384386 nsecs

set_next_event: mtk_syst_clkevt_next_event
shutdown: mtk_syst_clkevt_shutdown
oneshot: mtk_syst_clkevt_oneshot
resume: mtk_syst_clkevt_resume
event_handler: tick_handle_periodic_broadcast
retries: 4

log of loading timer-mediatek.ko
============================

[   25.658884] init 7: Loaded kernel
module /lib/modules/timer-mediatek.ko
[   25.658946] =============================
[   25.660010] init 7: Loading module /lib/modules/reboot-mode.ko with
args ""
[   25.660364] WARNING: suspicious RCU usage
[   25.661831] 5.4.46-g325aef33bcb1-dirty #17 Tainted: G SW        
[   25.662707] -----------------------------
[   25.663254] include/linux/rcupdate.h:601 rcu_read_lock() used
illegally while idle!
[   25.664279] 
[   25.664279] other info that might help us debug this:
[   25.665350] RCU used illegally from idle CPU!
[   25.665350] rcu_scheduler_active = 2, debug_locks = 1
[   25.666796] RCU used illegally from extended quiescent state!
[   25.667571] 2 locks held by swapper/1/0:
[   25.668105]  #0: ffffffec240b9a58 (tick_broadcast_lock){-.-.},
at:__tick_broadcast_oneshot_control+0x6c/0x444
[   25.669460]  #1: ffffffec2410e020 (rcu_read_lock){....}, at:
rcu_lock_acquire+0x0/0x40
[   25.670536] stack backtrace:
[   25.671131] CPU: 1 PID: 0 Comm: swapper/1 Tainted: G S
W5.4.46-g325aef33bcb1-dirty #17
[   25.672350] Hardware name: mediatek,mt6873 (DT)
[   25.672964] Call trace:
[   25.673310]  dump_backtrace.cfi_jt+0x0/0x4
[   25.673872]  dump_stack+0xf4/0x178
[   25.674344]  lockdep_rcu_suspicious+0x138/0x154
[   25.674961]  __cfi_slowpath+0x7c/0x1ec
[   25.675475]  clockevents_program_event+0x288/0x290
[   25.676126]  __tick_broadcast_oneshot_control+0x2f8/0x444
[   25.676856]  tick_broadcast_oneshot_control+0x58/0x68
[   25.677544]  cpuidle_enter_state+0x4c/0x314
[   25.678115]  cpuidle_enter+0x38/0x50
[   25.678608]  do_idle.llvm.7895800599653321206+0x1e0/0x2e8
[   25.679338]  cpu_startup_entry+0x24/0x28

BRs,
FreddyHsin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel