aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2015-03-31 11:19:00 -0400
committerIngo Molnar <mingo@kernel.org>2015-04-02 11:46:00 -0400
commitb337a9380f7effd60d082569dd7e0b97a7549730 (patch)
tree2cf1f6d3e69a57782d3d0ed71533aace12e00150 /kernel/time
parent345527b1edce8df719e0884500c76832a18211c3 (diff)
timer: Allocate per-cpu tvec_base's statically
Memory for the 'tvec_base' array is allocated separately for the boot CPU (statically) and non-boot CPUs (dynamically). The reason is because __TIMER_INITIALIZER() needs to set ->base to a valid pointer (because we've made NULL special, hint: lock_timer_base()) and we cannot get a compile time pointer to per-cpu entries because we don't know where we'll map the section, even for the boot cpu. This can be simplified a bit by statically allocating per-cpu memory. The only disadvantage is that memory for one of the structures will stay unused, i.e. for the boot CPU, which uses boot_tvec_bases. This will also guarantee that tvec_base is cacheline aligned. Even though tvec_base has ____cacheline_aligned stuck on, kzalloc_node() does not actually respect that (but guarantees a minimum u64 alignment). Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/17cdf560f2727f687ab159707d0aa591f8a2f82d.1427814611.git.viresh.kumar@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/timer.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 2d3f5c504939..f3cc653f876c 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -90,8 +90,19 @@ struct tvec_base {
90 struct tvec tv5; 90 struct tvec tv5;
91} ____cacheline_aligned; 91} ____cacheline_aligned;
92 92
93/*
94 * __TIMER_INITIALIZER() needs to set ->base to a valid pointer (because we've
95 * made NULL special, hint: lock_timer_base()) and we cannot get a compile time
96 * pointer to per-cpu entries because we don't know where we'll map the section,
97 * even for the boot cpu.
98 *
99 * And so we use boot_tvec_bases for boot CPU and per-cpu __tvec_bases for the
100 * rest of them.
101 */
93struct tvec_base boot_tvec_bases; 102struct tvec_base boot_tvec_bases;
94EXPORT_SYMBOL(boot_tvec_bases); 103EXPORT_SYMBOL(boot_tvec_bases);
104static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
105
95static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases; 106static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases;
96 107
97/* Functions below help us manage 'deferrable' flag */ 108/* Functions below help us manage 'deferrable' flag */
@@ -1534,46 +1545,25 @@ EXPORT_SYMBOL(schedule_timeout_uninterruptible);
1534 1545
1535static int init_timers_cpu(int cpu) 1546static int init_timers_cpu(int cpu)
1536{ 1547{
1537 int j; 1548 struct tvec_base *base = per_cpu(tvec_bases, cpu);
1538 struct tvec_base *base;
1539 static char tvec_base_done[NR_CPUS]; 1549 static char tvec_base_done[NR_CPUS];
1550 int j;
1540 1551
1541 if (!tvec_base_done[cpu]) { 1552 if (!tvec_base_done[cpu]) {
1542 static char boot_done; 1553 static char boot_cpu_skipped;
1543 1554
1544 if (boot_done) { 1555 if (!boot_cpu_skipped) {
1545 /* 1556 boot_cpu_skipped = 1; /* skip the boot cpu */
1546 * The APs use this path later in boot
1547 */
1548 base = kzalloc_node(sizeof(*base), GFP_KERNEL,
1549 cpu_to_node(cpu));
1550 if (!base)
1551 return -ENOMEM;
1552
1553 /* Make sure tvec_base has TIMER_FLAG_MASK bits free */
1554 if (WARN_ON(base != tbase_get_base(base))) {
1555 kfree(base);
1556 return -ENOMEM;
1557 }
1558 per_cpu(tvec_bases, cpu) = base;
1559 } else { 1557 } else {
1560 /* 1558 base = per_cpu_ptr(&__tvec_bases, cpu);
1561 * This is for the boot CPU - we use compile-time 1559 per_cpu(tvec_bases, cpu) = base;
1562 * static initialisation because per-cpu memory isn't
1563 * ready yet and because the memory allocators are not
1564 * initialised either.
1565 */
1566 boot_done = 1;
1567 base = &boot_tvec_bases;
1568 } 1560 }
1561
1569 spin_lock_init(&base->lock); 1562 spin_lock_init(&base->lock);
1570 tvec_base_done[cpu] = 1; 1563 tvec_base_done[cpu] = 1;
1571 base->cpu = cpu; 1564 base->cpu = cpu;
1572 } else {
1573 base = per_cpu(tvec_bases, cpu);
1574 } 1565 }
1575 1566
1576
1577 for (j = 0; j < TVN_SIZE; j++) { 1567 for (j = 0; j < TVN_SIZE; j++) {
1578 INIT_LIST_HEAD(base->tv5.vec + j); 1568 INIT_LIST_HEAD(base->tv5.vec + j);
1579 INIT_LIST_HEAD(base->tv4.vec + j); 1569 INIT_LIST_HEAD(base->tv4.vec + j);