[PATCH 3/3] timer: Don't initialize tvec_base on hotplug

From: Viresh Kumar
Date: Mon Mar 30 2015 - 01:17:51 EST


There is no need to call init_timers_cpu() on every cpu hotplug event, there is
not much we need to reset.

- Timer-lists are already empty at the end of migrate_timers().
- timer_jiffies will be refreshed while adding a new timer, after the CPU is
online again.
- active_timers and all_timers can be reset from migrate_timers().

Signed-off-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
---
kernel/time/timer.c | 101 +++++++++++++++++++++++-----------------------------
1 file changed, 45 insertions(+), 56 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 40918a5d3e1d..aa02d49b3748 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1532,44 +1532,6 @@ signed long __sched schedule_timeout_uninterruptible(signed long timeout)
}
EXPORT_SYMBOL(schedule_timeout_uninterruptible);

-static int init_timers_cpu(int cpu)
-{
- struct tvec_base *base = per_cpu(tvec_bases, cpu);
- static char tvec_base_done[NR_CPUS];
- static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
- int j;
-
- if (!tvec_base_done[cpu]) {
- static char boot_done;
-
- if (!boot_done) {
- boot_done = 1; /* skip the boot cpu */
- } else {
- base = per_cpu_ptr(&__tvec_bases, cpu);
- per_cpu(tvec_bases, cpu) = base;
- }
-
- spin_lock_init(&base->lock);
- tvec_base_done[cpu] = 1;
- base->cpu = cpu;
- }
-
- for (j = 0; j < TVN_SIZE; j++) {
- INIT_LIST_HEAD(base->tv5.vec + j);
- INIT_LIST_HEAD(base->tv4.vec + j);
- INIT_LIST_HEAD(base->tv3.vec + j);
- INIT_LIST_HEAD(base->tv2.vec + j);
- }
- for (j = 0; j < TVR_SIZE; j++)
- INIT_LIST_HEAD(base->tv1.vec + j);
-
- base->timer_jiffies = jiffies;
- base->next_timer = base->timer_jiffies;
- base->active_timers = 0;
- base->all_timers = 0;
- return 0;
-}
-
#ifdef CONFIG_HOTPLUG_CPU
static void migrate_timer_list(struct tvec_base *new_base, struct list_head *head)
{
@@ -1611,6 +1573,9 @@ static void migrate_timers(int cpu)
migrate_timer_list(new_base, old_base->tv5.vec + i);
}

+ old_base->active_timers = 0;
+ old_base->all_timers = 0;
+
spin_unlock(&old_base->lock);
spin_unlock_irq(&new_base->lock);
put_cpu_var(tvec_bases);
@@ -1620,25 +1585,16 @@ static void migrate_timers(int cpu)
static int timer_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
{
- long cpu = (long)hcpu;
- int err;
-
- switch(action) {
- case CPU_UP_PREPARE:
- case CPU_UP_PREPARE_FROZEN:
- err = init_timers_cpu(cpu);
- if (err < 0)
- return notifier_from_errno(err);
- break;
#ifdef CONFIG_HOTPLUG_CPU
+ switch (action) {
case CPU_DEAD:
case CPU_DEAD_FROZEN:
- migrate_timers(cpu);
+ migrate_timers((long)hcpu);
break;
-#endif
default:
break;
}
+#endif
return NOTIFY_OK;
}

@@ -1646,18 +1602,51 @@ static struct notifier_block timers_nb = {
.notifier_call = timer_cpu_notify,
};

+static void __init init_timer_cpu(struct tvec_base *base, int cpu)
+{
+ int j;

-void __init init_timers(void)
+ base->cpu = cpu;
+ per_cpu(tvec_bases, cpu) = base;
+ spin_lock_init(&base->lock);
+
+ for (j = 0; j < TVN_SIZE; j++) {
+ INIT_LIST_HEAD(base->tv5.vec + j);
+ INIT_LIST_HEAD(base->tv4.vec + j);
+ INIT_LIST_HEAD(base->tv3.vec + j);
+ INIT_LIST_HEAD(base->tv2.vec + j);
+ }
+ for (j = 0; j < TVR_SIZE; j++)
+ INIT_LIST_HEAD(base->tv1.vec + j);
+
+ base->timer_jiffies = jiffies;
+ base->next_timer = base->timer_jiffies;
+}
+
+static void __init init_timer_cpus(void)
{
- int err;
+ /* Used for all CPUs, except boot CPU (which uses boot_tvec_bases) */
+ static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
+ struct tvec_base *base;
+ int local_cpu = smp_processor_id();
+ int cpu;
+
+ for_each_possible_cpu(cpu) {
+ if (likely(cpu != local_cpu))
+ base = per_cpu_ptr(&__tvec_bases, cpu);
+ else
+ base = &boot_tvec_bases;
+
+ init_timer_cpu(base, cpu);
+ }
+}

+void __init init_timers(void)
+{
/* ensure there are enough low bits for flags in timer->base pointer */
BUILD_BUG_ON(__alignof__(struct tvec_base) & TIMER_FLAG_MASK);

- err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,
- (void *)(long)smp_processor_id());
- BUG_ON(err != NOTIFY_OK);
-
+ init_timer_cpus();
init_timer_stats();
register_cpu_notifier(&timers_nb);
open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
--
2.3.0.rc0.44.ga94655d

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/