Skip to contentSkip to conversation

clocksource/drivers: Add timer-of common init routine

PATCH New Daniel Lezcano 2 participants 4 messages Jun 6, 2017 – Jun 8, 2017

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

PATCH 1/2 clocksource/drivers: Add timer-of common init routine

The different drivers are all using the same pattern when initializing.

1. Get the base address
2. Get the irq number
3. Get the clock
4. Prepare and enable the clock
5. Get the rate
6. Request an interrupt

Instead of repeating again and again these steps in all the drivers, let's provide a common init routine to give the opportunity to factor all of them out.

We can expect a significant kernel size improvement when the common routine will be used in all the drivers.

---
 drivers/clocksource/Makefile   |   1 +
 drivers/clocksource/timer-of.c | 168 +++++++++++++++++++++++++++++++++++++++++
 drivers/clocksource/timer-of.h |  67 ++++++++++++++++
 3 files changed, 236 insertions(+)
 create mode 100644 drivers/clocksource/timer-of.c
 create mode 100644 drivers/clocksource/timer-of.h
drivers/clocksource/Makefile +1 -0
index ec55921..72bfd00 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_TIMER_OF)		+= timer-of.o
 obj-$(CONFIG_TIMER_PROBE)	+= timer-probe.o
 obj-$(CONFIG_ATMEL_PIT)		+= timer-atmel-pit.o
 obj-$(CONFIG_ATMEL_ST)		+= timer-atmel-st.o
drivers/clocksource/timer-of.c new file +168 -0

168 lines not on this page · raw message

drivers/clocksource/timer-of.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 clocksource/drivers/keystone: Use the timer-of common routine

The previous patch provided a common init routine for the OF drivers.

The keystone driver is given as example on the improvement and usage of the common initialization routine.

---
 drivers/clocksource/Kconfig          |   1 +
 drivers/clocksource/timer-keystone.c | 117 +++++++++++++----------------------
 2 files changed, 44 insertions(+), 74 deletions(-)
drivers/clocksource/Kconfig +1 -0
index 4ba230d..f1ed520 100644
@@ -216,6 +216,7 @@ config KEYSTONE_TIMER
 	depends on GENERIC_CLOCKEVENTS
 	depends on ARM || ARM64
 	select CLKSRC_MMIO
+	select TIMER_OF
 	help
 	  Enables support for the Keystone timer.
 
drivers/clocksource/timer-keystone.c +43 -74

162 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw
In reply to Daniel Lezcano
url: https://github.com/0day-ci/linux/commits/Daniel-Lezcano/clocksource-drivers-Add-timer-of-common-init-routine/20170607-024801 config: ia64-allmodconfig (attached as .config) compiler…

Hi Daniel,

[auto build test ERROR on next-20170605]
[cannot apply to tip/timers/core clk/clk-next linus/master v4.9-rc8 v4.9-rc7 v4.9-rc6 v4.12-rc4] [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/Daniel-Lezcano/clocksource-drivers-Add-timer-of-common-init-routine/20170607-024801
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0
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=ia64

All error/warnings (new ones prefixed by >>):

In file included from drivers/clocksource/timer-of.c:25:0:

>> drivers/clocksource/timer-of.h:34:28: error: field 'clkevt' has incomplete type
     struct clock_event_device clkevt;
                               ^~~~~~
   In file included from include/linux/err.h:4:0,
                    from include/linux/clk.h:15,
                    from drivers/clocksource/timer-of.c:18:
   drivers/clocksource/timer-of.h: In function 'to_timer_of':
   include/linux/kernel.h:859:32: error: dereferencing pointer to incomplete type 'struct clock_event_device'
     BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
                                   ^~~~~~
   include/linux/compiler.h:517:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^~~~~~~~~
   include/linux/compiler.h:537:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:46:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:859:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
     ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:859:20: note: in expansion of macro '__same_type'
     BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
                       ^~~~~~~~~~~
>> drivers/clocksource/timer-of.h:42:9: note: in expansion of macro 'container_of'
     return container_of(clkevt, struct timer_of, clkevt);
            ^~~~~~~~~~~~

vim +/clkevt +34 drivers/clocksource/timer-of.h

    28		unsigned long rate;
    29		unsigned long period;
    30	};
    31	
    32	struct timer_of {
    33		unsigned int flags;
  > 34		struct clock_event_device clkevt;
    35		struct of_timer_base of_base;
    36		struct of_timer_irq  of_irq;
    37		struct of_timer_clk  of_clk;
    38	};
    39	
    40	static inline struct timer_of *to_timer_of(struct clock_event_device *clkevt)
    41	{
  > 42		return container_of(clkevt, struct timer_of, clkevt);
    43	}
    44	
    45	static inline void __iomem *timer_of_base(struct timer_of *to)

---
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: 47902 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170607/0c037873/attachment-0001.gz>

#3 lore raw
In reply to Daniel Lezcano
url: https://github.com/0day-ci/linux/commits/Daniel-Lezcano/clocksource-drivers-Add-timer-of-common-init-routine/20170607-024801 reproduce:

Hi Daniel,

[auto build test WARNING on next-20170605]
[cannot apply to tip/timers/core clk/clk-next linus/master v4.9-rc8 v4.9-rc7 v4.9-rc6 v4.12-rc4] [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/Daniel-Lezcano/clocksource-drivers-Add-timer-of-common-init-routine/20170607-024801
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

include/linux/compiler.h:260:8: sparse: attribute 'no_sanitize_address': unknown attribute

>> drivers/clocksource/timer-of.c:33:24: sparse: incompatible types in conditional expression (different types)

vim +33 drivers/clocksource/timer-of.c

    17	 */
    18	#include <linux/clk.h>
    19	#include <linux/interrupt.h>
    20	#include <linux/of.h>
    21	#include <linux/of_address.h>
    22	#include <linux/of_irq.h>
    23	#include <linux/slab.h>
    24	
    25	#include "timer-of.h"
    26	
    27	static __init void timer_irq_exit(struct of_timer_irq *of_irq)
    28	{
    29		struct timer_of *to = container_of(of_irq, struct timer_of, of_irq);
    30	
    31		struct clock_event_device *clkevt = &to->clkevt;
    32	
  > 33		of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) :
    34			free_irq(of_irq->irq, clkevt);
    35	}
    36	
    37	static __init int timer_irq_init(struct device_node *np,
    38					 struct of_timer_irq *of_irq)
    39	{
    40		int ret;
    41		struct timer_of *to = container_of(of_irq, struct timer_of, of_irq);

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