diff options
author | Tejun Heo <tj@kernel.org> | 2012-08-08 14:10:27 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2012-08-21 10:28:30 -0400 |
commit | fc683995a6c4e604d62ab9a488ac2c1ba94fa868 (patch) | |
tree | c43956da7c1fc34446d40d64f7cff81475915fee /kernel/timer.c | |
parent | 5a9af38d05f6a1bd0d3f1f69a074cdbe9c87e977 (diff) |
timer: Clean up timer initializers
Over time, timer initializers became messy with unnecessarily
duplicated code which are inconsistently spread across timer.h and
timer.c.
This patch cleans up timer initializers.
* timer.c::__init_timer() is renamed to do_init_timer().
* __TIMER_INITIALIZER() added. It takes @flags and all initializers
are wrappers around it.
* init_timer[_on_stack]_key() now take @flags.
* __init_timer[_on_stack]() added. They take @flags and all init
macros are wrappers around them.
* __setup_timer[_on_stack]() added. It uses __init_timer() and takes
@flags. All setup macros are wrappers around the two.
Note that this patch doesn't add missing init/setup combinations -
e.g. init_timer_deferrable_on_stack(). Adding missing ones is
trivial.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: torvalds@linux-foundation.org
Cc: peterz@infradead.org
Link: http://lkml.kernel.org/r/1344449428-24962-4-git-send-email-tj@kernel.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/timer.c')
-rw-r--r-- | kernel/timer.c | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index cf7af56940b7..8d185a1677cc 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -100,11 +100,6 @@ static inline struct tvec_base *tbase_get_base(struct tvec_base *base) | |||
100 | return ((struct tvec_base *)((unsigned long)base & ~TIMER_FLAG_MASK)); | 100 | return ((struct tvec_base *)((unsigned long)base & ~TIMER_FLAG_MASK)); |
101 | } | 101 | } |
102 | 102 | ||
103 | static inline void timer_set_deferrable(struct timer_list *timer) | ||
104 | { | ||
105 | timer->base = TBASE_MAKE_DEFERRED(timer->base); | ||
106 | } | ||
107 | |||
108 | static inline void | 103 | static inline void |
109 | timer_set_base(struct timer_list *timer, struct tvec_base *new_base) | 104 | timer_set_base(struct timer_list *timer, struct tvec_base *new_base) |
110 | { | 105 | { |
@@ -564,16 +559,14 @@ static inline void debug_timer_assert_init(struct timer_list *timer) | |||
564 | debug_object_assert_init(timer, &timer_debug_descr); | 559 | debug_object_assert_init(timer, &timer_debug_descr); |
565 | } | 560 | } |
566 | 561 | ||
567 | static void __init_timer(struct timer_list *timer, | 562 | static void do_init_timer(struct timer_list *timer, unsigned int flags, |
568 | const char *name, | 563 | const char *name, struct lock_class_key *key); |
569 | struct lock_class_key *key); | ||
570 | 564 | ||
571 | void init_timer_on_stack_key(struct timer_list *timer, | 565 | void init_timer_on_stack_key(struct timer_list *timer, unsigned int flags, |
572 | const char *name, | 566 | const char *name, struct lock_class_key *key) |
573 | struct lock_class_key *key) | ||
574 | { | 567 | { |
575 | debug_object_init_on_stack(timer, &timer_debug_descr); | 568 | debug_object_init_on_stack(timer, &timer_debug_descr); |
576 | __init_timer(timer, name, key); | 569 | do_init_timer(timer, flags, name, key); |
577 | } | 570 | } |
578 | EXPORT_SYMBOL_GPL(init_timer_on_stack_key); | 571 | EXPORT_SYMBOL_GPL(init_timer_on_stack_key); |
579 | 572 | ||
@@ -614,12 +607,13 @@ static inline void debug_assert_init(struct timer_list *timer) | |||
614 | debug_timer_assert_init(timer); | 607 | debug_timer_assert_init(timer); |
615 | } | 608 | } |
616 | 609 | ||
617 | static void __init_timer(struct timer_list *timer, | 610 | static void do_init_timer(struct timer_list *timer, unsigned int flags, |
618 | const char *name, | 611 | const char *name, struct lock_class_key *key) |
619 | struct lock_class_key *key) | ||
620 | { | 612 | { |
613 | struct tvec_base *base = __raw_get_cpu_var(tvec_bases); | ||
614 | |||
621 | timer->entry.next = NULL; | 615 | timer->entry.next = NULL; |
622 | timer->base = __raw_get_cpu_var(tvec_bases); | 616 | timer->base = (void *)((unsigned long)base | flags); |
623 | timer->slack = -1; | 617 | timer->slack = -1; |
624 | #ifdef CONFIG_TIMER_STATS | 618 | #ifdef CONFIG_TIMER_STATS |
625 | timer->start_site = NULL; | 619 | timer->start_site = NULL; |
@@ -629,22 +623,10 @@ static void __init_timer(struct timer_list *timer, | |||
629 | lockdep_init_map(&timer->lockdep_map, name, key, 0); | 623 | lockdep_init_map(&timer->lockdep_map, name, key, 0); |
630 | } | 624 | } |
631 | 625 | ||
632 | void setup_deferrable_timer_on_stack_key(struct timer_list *timer, | ||
633 | const char *name, | ||
634 | struct lock_class_key *key, | ||
635 | void (*function)(unsigned long), | ||
636 | unsigned long data) | ||
637 | { | ||
638 | timer->function = function; | ||
639 | timer->data = data; | ||
640 | init_timer_on_stack_key(timer, name, key); | ||
641 | timer_set_deferrable(timer); | ||
642 | } | ||
643 | EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); | ||
644 | |||
645 | /** | 626 | /** |
646 | * init_timer_key - initialize a timer | 627 | * init_timer_key - initialize a timer |
647 | * @timer: the timer to be initialized | 628 | * @timer: the timer to be initialized |
629 | * @flags: timer flags | ||
648 | * @name: name of the timer | 630 | * @name: name of the timer |
649 | * @key: lockdep class key of the fake lock used for tracking timer | 631 | * @key: lockdep class key of the fake lock used for tracking timer |
650 | * sync lock dependencies | 632 | * sync lock dependencies |
@@ -652,24 +634,14 @@ EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); | |||
652 | * init_timer_key() must be done to a timer prior calling *any* of the | 634 | * init_timer_key() must be done to a timer prior calling *any* of the |
653 | * other timer functions. | 635 | * other timer functions. |
654 | */ | 636 | */ |
655 | void init_timer_key(struct timer_list *timer, | 637 | void init_timer_key(struct timer_list *timer, unsigned int flags, |
656 | const char *name, | 638 | const char *name, struct lock_class_key *key) |
657 | struct lock_class_key *key) | ||
658 | { | 639 | { |
659 | debug_init(timer); | 640 | debug_init(timer); |
660 | __init_timer(timer, name, key); | 641 | do_init_timer(timer, flags, name, key); |
661 | } | 642 | } |
662 | EXPORT_SYMBOL(init_timer_key); | 643 | EXPORT_SYMBOL(init_timer_key); |
663 | 644 | ||
664 | void init_timer_deferrable_key(struct timer_list *timer, | ||
665 | const char *name, | ||
666 | struct lock_class_key *key) | ||
667 | { | ||
668 | init_timer_key(timer, name, key); | ||
669 | timer_set_deferrable(timer); | ||
670 | } | ||
671 | EXPORT_SYMBOL(init_timer_deferrable_key); | ||
672 | |||
673 | static inline void detach_timer(struct timer_list *timer, bool clear_pending) | 645 | static inline void detach_timer(struct timer_list *timer, bool clear_pending) |
674 | { | 646 | { |
675 | struct list_head *entry = &timer->entry; | 647 | struct list_head *entry = &timer->entry; |