Skip to content

Commit 3691c51

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
[PATCH] kill __init_timer_base in favor of boot_tvec_bases
Commit a4a6198: [PATCH] tvec_bases too large for per-cpu data introduced "struct tvec_t_base_s boot_tvec_bases" which is visible at compile time. This means we can kill __init_timer_base and move timer_base_s's content into tvec_t_base_s. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 5ce2964 commit 3691c51

2 files changed

Lines changed: 39 additions & 53 deletions

File tree

‎include/linux/timer.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <linux/spinlock.h>
77
#include <linux/stddef.h>
88

9-
struct timer_base_s;
9+
struct tvec_t_base_s;
1010

1111
struct timer_list {
1212
struct list_head entry;
@@ -15,16 +15,16 @@ struct timer_list {
1515
void (*function)(unsigned long);
1616
unsigned long data;
1717

18-
struct timer_base_s *base;
18+
struct tvec_t_base_s *base;
1919
};
2020

21-
extern struct timer_base_s __init_timer_base;
21+
extern struct tvec_t_base_s boot_tvec_bases;
2222

2323
#define TIMER_INITIALIZER(_function, _expires, _data) { \
2424
.function = (_function), \
2525
.expires = (_expires), \
2626
.data = (_data), \
27-
.base = &__init_timer_base, \
27+
.base = &boot_tvec_bases, \
2828
}
2929

3030
#define DEFINE_TIMER(_name, _function, _expires, _data) \

‎kernel/timer.c‎

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,13 @@ EXPORT_SYMBOL(jiffies_64);
5454
/*
5555
* per-CPU timer vector definitions:
5656
*/
57-
5857
#define TVN_BITS (CONFIG_BASE_SMALL ? 4 : 6)
5958
#define TVR_BITS (CONFIG_BASE_SMALL ? 6 : 8)
6059
#define TVN_SIZE (1 << TVN_BITS)
6160
#define TVR_SIZE (1 << TVR_BITS)
6261
#define TVN_MASK (TVN_SIZE - 1)
6362
#define TVR_MASK (TVR_SIZE - 1)
6463

65-
struct timer_base_s {
66-
spinlock_t lock;
67-
struct timer_list *running_timer;
68-
};
69-
7064
typedef struct tvec_s {
7165
struct list_head vec[TVN_SIZE];
7266
} tvec_t;
@@ -76,7 +70,8 @@ typedef struct tvec_root_s {
7670
} tvec_root_t;
7771

7872
struct tvec_t_base_s {
79-
struct timer_base_s t_base;
73+
spinlock_t lock;
74+
struct timer_list *running_timer;
8075
unsigned long timer_jiffies;
8176
tvec_root_t tv1;
8277
tvec_t tv2;
@@ -87,13 +82,14 @@ struct tvec_t_base_s {
8782

8883
typedef struct tvec_t_base_s tvec_base_t;
8984
static DEFINE_PER_CPU(tvec_base_t *, tvec_bases);
90-
static tvec_base_t boot_tvec_bases;
85+
tvec_base_t boot_tvec_bases;
86+
EXPORT_SYMBOL(boot_tvec_bases);
9187

9288
static inline void set_running_timer(tvec_base_t *base,
9389
struct timer_list *timer)
9490
{
9591
#ifdef CONFIG_SMP
96-
base->t_base.running_timer = timer;
92+
base->running_timer = timer;
9793
#endif
9894
}
9995

@@ -139,15 +135,6 @@ static void internal_add_timer(tvec_base_t *base, struct timer_list *timer)
139135
list_add_tail(&timer->entry, vec);
140136
}
141137

142-
typedef struct timer_base_s timer_base_t;
143-
/*
144-
* Used by TIMER_INITIALIZER, we can't use per_cpu(tvec_bases)
145-
* at compile time, and we need timer->base to lock the timer.
146-
*/
147-
timer_base_t __init_timer_base
148-
____cacheline_aligned_in_smp = { .lock = SPIN_LOCK_UNLOCKED };
149-
EXPORT_SYMBOL(__init_timer_base);
150-
151138
/***
152139
* init_timer - initialize a timer.
153140
* @timer: the timer to be initialized
@@ -158,7 +145,7 @@ EXPORT_SYMBOL(__init_timer_base);
158145
void fastcall init_timer(struct timer_list *timer)
159146
{
160147
timer->entry.next = NULL;
161-
timer->base = &per_cpu(tvec_bases, raw_smp_processor_id())->t_base;
148+
timer->base = per_cpu(tvec_bases, raw_smp_processor_id());
162149
}
163150
EXPORT_SYMBOL(init_timer);
164151

@@ -174,7 +161,7 @@ static inline void detach_timer(struct timer_list *timer,
174161
}
175162

176163
/*
177-
* We are using hashed locking: holding per_cpu(tvec_bases).t_base.lock
164+
* We are using hashed locking: holding per_cpu(tvec_bases).lock
178165
* means that all timers which are tied to this base via timer->base are
179166
* locked, and the base itself is locked too.
180167
*
@@ -185,10 +172,10 @@ static inline void detach_timer(struct timer_list *timer,
185172
* possible to set timer->base = NULL and drop the lock: the timer remains
186173
* locked.
187174
*/
188-
static timer_base_t *lock_timer_base(struct timer_list *timer,
175+
static tvec_base_t *lock_timer_base(struct timer_list *timer,
189176
unsigned long *flags)
190177
{
191-
timer_base_t *base;
178+
tvec_base_t *base;
192179

193180
for (;;) {
194181
base = timer->base;
@@ -205,8 +192,7 @@ static timer_base_t *lock_timer_base(struct timer_list *timer,
205192

206193
int __mod_timer(struct timer_list *timer, unsigned long expires)
207194
{
208-
timer_base_t *base;
209-
tvec_base_t *new_base;
195+
tvec_base_t *base, *new_base;
210196
unsigned long flags;
211197
int ret = 0;
212198

@@ -221,7 +207,7 @@ int __mod_timer(struct timer_list *timer, unsigned long expires)
221207

222208
new_base = __get_cpu_var(tvec_bases);
223209

224-
if (base != &new_base->t_base) {
210+
if (base != new_base) {
225211
/*
226212
* We are trying to schedule the timer on the local CPU.
227213
* However we can't change timer's base while it is running,
@@ -231,19 +217,19 @@ int __mod_timer(struct timer_list *timer, unsigned long expires)
231217
*/
232218
if (unlikely(base->running_timer == timer)) {
233219
/* The timer remains on a former base */
234-
new_base = container_of(base, tvec_base_t, t_base);
220+
new_base = base;
235221
} else {
236222
/* See the comment in lock_timer_base() */
237223
timer->base = NULL;
238224
spin_unlock(&base->lock);
239-
spin_lock(&new_base->t_base.lock);
240-
timer->base = &new_base->t_base;
225+
spin_lock(&new_base->lock);
226+
timer->base = new_base;
241227
}
242228
}
243229

244230
timer->expires = expires;
245231
internal_add_timer(new_base, timer);
246-
spin_unlock_irqrestore(&new_base->t_base.lock, flags);
232+
spin_unlock_irqrestore(&new_base->lock, flags);
247233

248234
return ret;
249235
}
@@ -263,10 +249,10 @@ void add_timer_on(struct timer_list *timer, int cpu)
263249
unsigned long flags;
264250

265251
BUG_ON(timer_pending(timer) || !timer->function);
266-
spin_lock_irqsave(&base->t_base.lock, flags);
267-
timer->base = &base->t_base;
252+
spin_lock_irqsave(&base->lock, flags);
253+
timer->base = base;
268254
internal_add_timer(base, timer);
269-
spin_unlock_irqrestore(&base->t_base.lock, flags);
255+
spin_unlock_irqrestore(&base->lock, flags);
270256
}
271257

272258

@@ -319,7 +305,7 @@ EXPORT_SYMBOL(mod_timer);
319305
*/
320306
int del_timer(struct timer_list *timer)
321307
{
322-
timer_base_t *base;
308+
tvec_base_t *base;
323309
unsigned long flags;
324310
int ret = 0;
325311

@@ -346,7 +332,7 @@ EXPORT_SYMBOL(del_timer);
346332
*/
347333
int try_to_del_timer_sync(struct timer_list *timer)
348334
{
349-
timer_base_t *base;
335+
tvec_base_t *base;
350336
unsigned long flags;
351337
int ret = -1;
352338

@@ -410,7 +396,7 @@ static int cascade(tvec_base_t *base, tvec_t *tv, int index)
410396
struct timer_list *tmp;
411397

412398
tmp = list_entry(curr, struct timer_list, entry);
413-
BUG_ON(tmp->base != &base->t_base);
399+
BUG_ON(tmp->base != base);
414400
curr = curr->next;
415401
internal_add_timer(base, tmp);
416402
}
@@ -432,7 +418,7 @@ static inline void __run_timers(tvec_base_t *base)
432418
{
433419
struct timer_list *timer;
434420

435-
spin_lock_irq(&base->t_base.lock);
421+
spin_lock_irq(&base->lock);
436422
while (time_after_eq(jiffies, base->timer_jiffies)) {
437423
struct list_head work_list = LIST_HEAD_INIT(work_list);
438424
struct list_head *head = &work_list;
@@ -458,7 +444,7 @@ static inline void __run_timers(tvec_base_t *base)
458444

459445
set_running_timer(base, timer);
460446
detach_timer(timer, 1);
461-
spin_unlock_irq(&base->t_base.lock);
447+
spin_unlock_irq(&base->lock);
462448
{
463449
int preempt_count = preempt_count();
464450
fn(data);
@@ -471,11 +457,11 @@ static inline void __run_timers(tvec_base_t *base)
471457
BUG();
472458
}
473459
}
474-
spin_lock_irq(&base->t_base.lock);
460+
spin_lock_irq(&base->lock);
475461
}
476462
}
477463
set_running_timer(base, NULL);
478-
spin_unlock_irq(&base->t_base.lock);
464+
spin_unlock_irq(&base->lock);
479465
}
480466

481467
#ifdef CONFIG_NO_IDLE_HZ
@@ -506,7 +492,7 @@ unsigned long next_timer_interrupt(void)
506492
hr_expires += jiffies;
507493

508494
base = __get_cpu_var(tvec_bases);
509-
spin_lock(&base->t_base.lock);
495+
spin_lock(&base->lock);
510496
expires = base->timer_jiffies + (LONG_MAX >> 1);
511497
list = NULL;
512498

@@ -554,7 +540,7 @@ unsigned long next_timer_interrupt(void)
554540
expires = nte->expires;
555541
}
556542
}
557-
spin_unlock(&base->t_base.lock);
543+
spin_unlock(&base->lock);
558544

559545
if (time_before(hr_expires, expires))
560546
return hr_expires;
@@ -1262,7 +1248,7 @@ static int __devinit init_timers_cpu(int cpu)
12621248
}
12631249
per_cpu(tvec_bases, cpu) = base;
12641250
}
1265-
spin_lock_init(&base->t_base.lock);
1251+
spin_lock_init(&base->lock);
12661252
for (j = 0; j < TVN_SIZE; j++) {
12671253
INIT_LIST_HEAD(base->tv5.vec + j);
12681254
INIT_LIST_HEAD(base->tv4.vec + j);
@@ -1284,7 +1270,7 @@ static void migrate_timer_list(tvec_base_t *new_base, struct list_head *head)
12841270
while (!list_empty(head)) {
12851271
timer = list_entry(head->next, struct timer_list, entry);
12861272
detach_timer(timer, 0);
1287-
timer->base = &new_base->t_base;
1273+
timer->base = new_base;
12881274
internal_add_timer(new_base, timer);
12891275
}
12901276
}
@@ -1300,11 +1286,11 @@ static void __devinit migrate_timers(int cpu)
13001286
new_base = get_cpu_var(tvec_bases);
13011287

13021288
local_irq_disable();
1303-
spin_lock(&new_base->t_base.lock);
1304-
spin_lock(&old_base->t_base.lock);
1289+
spin_lock(&new_base->lock);
1290+
spin_lock(&old_base->lock);
1291+
1292+
BUG_ON(old_base->running_timer);
13051293

1306-
if (old_base->t_base.running_timer)
1307-
BUG();
13081294
for (i = 0; i < TVR_SIZE; i++)
13091295
migrate_timer_list(new_base, old_base->tv1.vec + i);
13101296
for (i = 0; i < TVN_SIZE; i++) {
@@ -1314,8 +1300,8 @@ static void __devinit migrate_timers(int cpu)
13141300
migrate_timer_list(new_base, old_base->tv5.vec + i);
13151301
}
13161302

1317-
spin_unlock(&old_base->t_base.lock);
1318-
spin_unlock(&new_base->t_base.lock);
1303+
spin_unlock(&old_base->lock);
1304+
spin_unlock(&new_base->lock);
13191305
local_irq_enable();
13201306
put_cpu_var(tvec_bases);
13211307
}

0 commit comments

Comments
 (0)