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 | |
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>
-rw-r--r-- | include/linux/timer.h | 123 | ||||
-rw-r--r-- | kernel/timer.c | 56 |
2 files changed, 53 insertions, 126 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h index 1d364aed1802..3f95c1fa615e 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h | |||
@@ -62,136 +62,91 @@ extern struct tvec_base boot_tvec_bases; | |||
62 | 62 | ||
63 | #define TIMER_FLAG_MASK 0x1LU | 63 | #define TIMER_FLAG_MASK 0x1LU |
64 | 64 | ||
65 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ | 65 | #define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \ |
66 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 66 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
67 | .function = (_function), \ | 67 | .function = (_function), \ |
68 | .expires = (_expires), \ | 68 | .expires = (_expires), \ |
69 | .data = (_data), \ | 69 | .data = (_data), \ |
70 | .base = &boot_tvec_bases, \ | 70 | .base = (void *)((unsigned long)&boot_tvec_bases + (_flags)), \ |
71 | .slack = -1, \ | 71 | .slack = -1, \ |
72 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | 72 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
73 | __FILE__ ":" __stringify(__LINE__)) \ | 73 | __FILE__ ":" __stringify(__LINE__)) \ |
74 | } | 74 | } |
75 | 75 | ||
76 | #define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ | 76 | #define TIMER_INITIALIZER(_function, _expires, _data) \ |
77 | ((unsigned char *)(ptr) + TIMER_DEFERRABLE)) | 77 | __TIMER_INITIALIZER((_function), (_expires), (_data), 0) |
78 | 78 | ||
79 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ | 79 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \ |
80 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 80 | __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE) |
81 | .function = (_function), \ | ||
82 | .expires = (_expires), \ | ||
83 | .data = (_data), \ | ||
84 | .base = TBASE_MAKE_DEFERRED(&boot_tvec_bases), \ | ||
85 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | ||
86 | __FILE__ ":" __stringify(__LINE__)) \ | ||
87 | } | ||
88 | 81 | ||
89 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ | 82 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
90 | struct timer_list _name = \ | 83 | struct timer_list _name = \ |
91 | TIMER_INITIALIZER(_function, _expires, _data) | 84 | TIMER_INITIALIZER(_function, _expires, _data) |
92 | 85 | ||
93 | void init_timer_key(struct timer_list *timer, | 86 | void init_timer_key(struct timer_list *timer, unsigned int flags, |
94 | const char *name, | 87 | const char *name, struct lock_class_key *key); |
95 | struct lock_class_key *key); | ||
96 | void init_timer_deferrable_key(struct timer_list *timer, | ||
97 | const char *name, | ||
98 | struct lock_class_key *key); | ||
99 | 88 | ||
100 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS | 89 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
101 | extern void init_timer_on_stack_key(struct timer_list *timer, | 90 | extern void init_timer_on_stack_key(struct timer_list *timer, |
102 | const char *name, | 91 | unsigned int flags, const char *name, |
103 | struct lock_class_key *key); | 92 | struct lock_class_key *key); |
104 | extern void destroy_timer_on_stack(struct timer_list *timer); | 93 | extern void destroy_timer_on_stack(struct timer_list *timer); |
105 | #else | 94 | #else |
106 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } | 95 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } |
107 | static inline void init_timer_on_stack_key(struct timer_list *timer, | 96 | static inline void init_timer_on_stack_key(struct timer_list *timer, |
108 | const char *name, | 97 | unsigned int flags, const char *name, |
109 | struct lock_class_key *key) | 98 | struct lock_class_key *key) |
110 | { | 99 | { |
111 | init_timer_key(timer, name, key); | 100 | init_timer_key(timer, flags, name, key); |
112 | } | 101 | } |
113 | #endif | 102 | #endif |
114 | 103 | ||
115 | #ifdef CONFIG_LOCKDEP | 104 | #ifdef CONFIG_LOCKDEP |
116 | #define init_timer(timer) \ | 105 | #define __init_timer(_timer, _flags) \ |
117 | do { \ | 106 | do { \ |
118 | static struct lock_class_key __key; \ | 107 | static struct lock_class_key __key; \ |
119 | init_timer_key((timer), #timer, &__key); \ | 108 | init_timer_key((_timer), (_flags), #_timer, &__key); \ |
120 | } while (0) | 109 | } while (0) |
121 | 110 | ||
122 | #define init_timer_deferrable(timer) \ | 111 | #define __init_timer_on_stack(_timer, _flags) \ |
123 | do { \ | 112 | do { \ |
124 | static struct lock_class_key __key; \ | 113 | static struct lock_class_key __key; \ |
125 | init_timer_deferrable_key((timer), #timer, &__key); \ | 114 | init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \ |
126 | } while (0) | 115 | } while (0) |
116 | #else | ||
117 | #define __init_timer(_timer, _flags) \ | ||
118 | init_timer_key((_timer), (_flags), NULL, NULL) | ||
119 | #define __init_timer_on_stack(_timer, _flags) \ | ||
120 | init_timer_on_stack_key((_timer), (_flags), NULL, NULL) | ||
121 | #endif | ||
127 | 122 | ||
123 | #define init_timer(timer) \ | ||
124 | __init_timer((timer), 0) | ||
125 | #define init_timer_deferrable(timer) \ | ||
126 | __init_timer((timer), TIMER_DEFERRABLE) | ||
128 | #define init_timer_on_stack(timer) \ | 127 | #define init_timer_on_stack(timer) \ |
128 | __init_timer_on_stack((timer), 0) | ||
129 | |||
130 | #define __setup_timer(_timer, _fn, _data, _flags) \ | ||
129 | do { \ | 131 | do { \ |
130 | static struct lock_class_key __key; \ | 132 | __init_timer((_timer), (_flags)); \ |
131 | init_timer_on_stack_key((timer), #timer, &__key); \ | 133 | (_timer)->function = (_fn); \ |
134 | (_timer)->data = (_data); \ | ||
132 | } while (0) | 135 | } while (0) |
133 | 136 | ||
134 | #define setup_timer(timer, fn, data) \ | 137 | #define __setup_timer_on_stack(_timer, _fn, _data, _flags) \ |
135 | do { \ | 138 | do { \ |
136 | static struct lock_class_key __key; \ | 139 | __init_timer_on_stack((_timer), (_flags)); \ |
137 | setup_timer_key((timer), #timer, &__key, (fn), (data));\ | 140 | (_timer)->function = (_fn); \ |
141 | (_timer)->data = (_data); \ | ||
138 | } while (0) | 142 | } while (0) |
139 | 143 | ||
144 | #define setup_timer(timer, fn, data) \ | ||
145 | __setup_timer((timer), (fn), (data), 0) | ||
140 | #define setup_timer_on_stack(timer, fn, data) \ | 146 | #define setup_timer_on_stack(timer, fn, data) \ |
141 | do { \ | 147 | __setup_timer_on_stack((timer), (fn), (data), 0) |
142 | static struct lock_class_key __key; \ | ||
143 | setup_timer_on_stack_key((timer), #timer, &__key, \ | ||
144 | (fn), (data)); \ | ||
145 | } while (0) | ||
146 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ | 148 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ |
147 | do { \ | 149 | __setup_timer_on_stack((timer), (fn), (data), TIMER_DEFERRABLE) |
148 | static struct lock_class_key __key; \ | ||
149 | setup_deferrable_timer_on_stack_key((timer), #timer, \ | ||
150 | &__key, (fn), \ | ||
151 | (data)); \ | ||
152 | } while (0) | ||
153 | #else | ||
154 | #define init_timer(timer)\ | ||
155 | init_timer_key((timer), NULL, NULL) | ||
156 | #define init_timer_deferrable(timer)\ | ||
157 | init_timer_deferrable_key((timer), NULL, NULL) | ||
158 | #define init_timer_on_stack(timer)\ | ||
159 | init_timer_on_stack_key((timer), NULL, NULL) | ||
160 | #define setup_timer(timer, fn, data)\ | ||
161 | setup_timer_key((timer), NULL, NULL, (fn), (data)) | ||
162 | #define setup_timer_on_stack(timer, fn, data)\ | ||
163 | setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) | ||
164 | #define setup_deferrable_timer_on_stack(timer, fn, data)\ | ||
165 | setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) | ||
166 | #endif | ||
167 | |||
168 | static inline void setup_timer_key(struct timer_list * timer, | ||
169 | const char *name, | ||
170 | struct lock_class_key *key, | ||
171 | void (*function)(unsigned long), | ||
172 | unsigned long data) | ||
173 | { | ||
174 | timer->function = function; | ||
175 | timer->data = data; | ||
176 | init_timer_key(timer, name, key); | ||
177 | } | ||
178 | |||
179 | static inline void setup_timer_on_stack_key(struct timer_list *timer, | ||
180 | const char *name, | ||
181 | struct lock_class_key *key, | ||
182 | void (*function)(unsigned long), | ||
183 | unsigned long data) | ||
184 | { | ||
185 | timer->function = function; | ||
186 | timer->data = data; | ||
187 | init_timer_on_stack_key(timer, name, key); | ||
188 | } | ||
189 | |||
190 | extern void setup_deferrable_timer_on_stack_key(struct timer_list *timer, | ||
191 | const char *name, | ||
192 | struct lock_class_key *key, | ||
193 | void (*function)(unsigned long), | ||
194 | unsigned long data); | ||
195 | 150 | ||
196 | /** | 151 | /** |
197 | * timer_pending - is a timer pending? | 152 | * timer_pending - is a timer pending? |
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; |