xref: /openbmc/linux/kernel/time/tick-common.c (revision 050ded1bbaea3331745cf2782315f5bc2582d083)
1906568c9SThomas Gleixner /*
2906568c9SThomas Gleixner  * linux/kernel/time/tick-common.c
3906568c9SThomas Gleixner  *
4906568c9SThomas Gleixner  * This file contains the base functions to manage periodic tick
5906568c9SThomas Gleixner  * related events.
6906568c9SThomas Gleixner  *
7906568c9SThomas Gleixner  * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
8906568c9SThomas Gleixner  * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
9906568c9SThomas Gleixner  * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
10906568c9SThomas Gleixner  *
11906568c9SThomas Gleixner  * This code is licenced under the GPL version 2. For details see
12906568c9SThomas Gleixner  * kernel-base/COPYING.
13906568c9SThomas Gleixner  */
14906568c9SThomas Gleixner #include <linux/cpu.h>
15906568c9SThomas Gleixner #include <linux/err.h>
16906568c9SThomas Gleixner #include <linux/hrtimer.h>
17d7b90689SRussell King #include <linux/interrupt.h>
18906568c9SThomas Gleixner #include <linux/percpu.h>
19906568c9SThomas Gleixner #include <linux/profile.h>
20906568c9SThomas Gleixner #include <linux/sched.h>
21ccf33d68SThomas Gleixner #include <linux/module.h>
22906568c9SThomas Gleixner 
23d7b90689SRussell King #include <asm/irq_regs.h>
24d7b90689SRussell King 
25f8381cbaSThomas Gleixner #include "tick-internal.h"
26f8381cbaSThomas Gleixner 
27906568c9SThomas Gleixner /*
28906568c9SThomas Gleixner  * Tick devices
29906568c9SThomas Gleixner  */
30f8381cbaSThomas Gleixner DEFINE_PER_CPU(struct tick_device, tick_cpu_device);
31906568c9SThomas Gleixner /*
32906568c9SThomas Gleixner  * Tick next event: keeps track of the tick time
33906568c9SThomas Gleixner  */
34f8381cbaSThomas Gleixner ktime_t tick_next_period;
35f8381cbaSThomas Gleixner ktime_t tick_period;
36*050ded1bSAndrew Morton 
37*050ded1bSAndrew Morton /*
38*050ded1bSAndrew Morton  * tick_do_timer_cpu is a timer core internal variable which holds the CPU NR
39*050ded1bSAndrew Morton  * which is responsible for calling do_timer(), i.e. the timekeeping stuff. This
40*050ded1bSAndrew Morton  * variable has two functions:
41*050ded1bSAndrew Morton  *
42*050ded1bSAndrew Morton  * 1) Prevent a thundering herd issue of a gazillion of CPUs trying to grab the
43*050ded1bSAndrew Morton  *    timekeeping lock all at once. Only the CPU which is assigned to do the
44*050ded1bSAndrew Morton  *    update is handling it.
45*050ded1bSAndrew Morton  *
46*050ded1bSAndrew Morton  * 2) Hand off the duty in the NOHZ idle case by setting the value to
47*050ded1bSAndrew Morton  *    TICK_DO_TIMER_NONE, i.e. a non existing CPU. So the next cpu which looks
48*050ded1bSAndrew Morton  *    at it will take over and keep the time keeping alive.  The handover
49*050ded1bSAndrew Morton  *    procedure also covers cpu hotplug.
50*050ded1bSAndrew Morton  */
516441402bSThomas Gleixner int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT;
52906568c9SThomas Gleixner 
53289f480aSIngo Molnar /*
54289f480aSIngo Molnar  * Debugging: see timer_list.c
55289f480aSIngo Molnar  */
56289f480aSIngo Molnar struct tick_device *tick_get_device(int cpu)
57289f480aSIngo Molnar {
58289f480aSIngo Molnar 	return &per_cpu(tick_cpu_device, cpu);
59289f480aSIngo Molnar }
60289f480aSIngo Molnar 
6179bf2bb3SThomas Gleixner /**
6279bf2bb3SThomas Gleixner  * tick_is_oneshot_available - check for a oneshot capable event device
6379bf2bb3SThomas Gleixner  */
6479bf2bb3SThomas Gleixner int tick_is_oneshot_available(void)
6579bf2bb3SThomas Gleixner {
66909ea964SChristoph Lameter 	struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
6779bf2bb3SThomas Gleixner 
683a142a06SThomas Gleixner 	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
693a142a06SThomas Gleixner 		return 0;
703a142a06SThomas Gleixner 	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
713a142a06SThomas Gleixner 		return 1;
723a142a06SThomas Gleixner 	return tick_broadcast_oneshot_available();
7379bf2bb3SThomas Gleixner }
7479bf2bb3SThomas Gleixner 
75906568c9SThomas Gleixner /*
76906568c9SThomas Gleixner  * Periodic tick
77906568c9SThomas Gleixner  */
78906568c9SThomas Gleixner static void tick_periodic(int cpu)
79906568c9SThomas Gleixner {
80906568c9SThomas Gleixner 	if (tick_do_timer_cpu == cpu) {
81d6ad4187SJohn Stultz 		write_seqlock(&jiffies_lock);
82906568c9SThomas Gleixner 
83906568c9SThomas Gleixner 		/* Keep track of the next tick event */
84906568c9SThomas Gleixner 		tick_next_period = ktime_add(tick_next_period, tick_period);
85906568c9SThomas Gleixner 
86906568c9SThomas Gleixner 		do_timer(1);
87d6ad4187SJohn Stultz 		write_sequnlock(&jiffies_lock);
88906568c9SThomas Gleixner 	}
89906568c9SThomas Gleixner 
90906568c9SThomas Gleixner 	update_process_times(user_mode(get_irq_regs()));
91906568c9SThomas Gleixner 	profile_tick(CPU_PROFILING);
92906568c9SThomas Gleixner }
93906568c9SThomas Gleixner 
94906568c9SThomas Gleixner /*
95906568c9SThomas Gleixner  * Event handler for periodic ticks
96906568c9SThomas Gleixner  */
97906568c9SThomas Gleixner void tick_handle_periodic(struct clock_event_device *dev)
98906568c9SThomas Gleixner {
99906568c9SThomas Gleixner 	int cpu = smp_processor_id();
1003494c166SDavid S. Miller 	ktime_t next;
101906568c9SThomas Gleixner 
102906568c9SThomas Gleixner 	tick_periodic(cpu);
103906568c9SThomas Gleixner 
104906568c9SThomas Gleixner 	if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
105906568c9SThomas Gleixner 		return;
106906568c9SThomas Gleixner 	/*
107906568c9SThomas Gleixner 	 * Setup the next period for devices, which do not have
108906568c9SThomas Gleixner 	 * periodic mode:
109906568c9SThomas Gleixner 	 */
1103494c166SDavid S. Miller 	next = ktime_add(dev->next_event, tick_period);
111906568c9SThomas Gleixner 	for (;;) {
112d1748302SMartin Schwidefsky 		if (!clockevents_program_event(dev, next, false))
113906568c9SThomas Gleixner 			return;
11474a03b69Sjohn stultz 		/*
11574a03b69Sjohn stultz 		 * Have to be careful here. If we're in oneshot mode,
11674a03b69Sjohn stultz 		 * before we call tick_periodic() in a loop, we need
11774a03b69Sjohn stultz 		 * to be sure we're using a real hardware clocksource.
11874a03b69Sjohn stultz 		 * Otherwise we could get trapped in an infinite
11974a03b69Sjohn stultz 		 * loop, as the tick_periodic() increments jiffies,
12074a03b69Sjohn stultz 		 * when then will increment time, posibly causing
12174a03b69Sjohn stultz 		 * the loop to trigger again and again.
12274a03b69Sjohn stultz 		 */
12374a03b69Sjohn stultz 		if (timekeeping_valid_for_hres())
124906568c9SThomas Gleixner 			tick_periodic(cpu);
1253494c166SDavid S. Miller 		next = ktime_add(next, tick_period);
126906568c9SThomas Gleixner 	}
127906568c9SThomas Gleixner }
128906568c9SThomas Gleixner 
129906568c9SThomas Gleixner /*
130906568c9SThomas Gleixner  * Setup the device for a periodic tick
131906568c9SThomas Gleixner  */
132f8381cbaSThomas Gleixner void tick_setup_periodic(struct clock_event_device *dev, int broadcast)
133906568c9SThomas Gleixner {
134f8381cbaSThomas Gleixner 	tick_set_periodic_handler(dev, broadcast);
135f8381cbaSThomas Gleixner 
136f8381cbaSThomas Gleixner 	/* Broadcast setup ? */
137f8381cbaSThomas Gleixner 	if (!tick_device_is_functional(dev))
138f8381cbaSThomas Gleixner 		return;
139906568c9SThomas Gleixner 
14027ce4cb4SThomas Gleixner 	if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) &&
14127ce4cb4SThomas Gleixner 	    !tick_broadcast_oneshot_active()) {
142906568c9SThomas Gleixner 		clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC);
143906568c9SThomas Gleixner 	} else {
144906568c9SThomas Gleixner 		unsigned long seq;
145906568c9SThomas Gleixner 		ktime_t next;
146906568c9SThomas Gleixner 
147906568c9SThomas Gleixner 		do {
148d6ad4187SJohn Stultz 			seq = read_seqbegin(&jiffies_lock);
149906568c9SThomas Gleixner 			next = tick_next_period;
150d6ad4187SJohn Stultz 		} while (read_seqretry(&jiffies_lock, seq));
151906568c9SThomas Gleixner 
152906568c9SThomas Gleixner 		clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
153906568c9SThomas Gleixner 
154906568c9SThomas Gleixner 		for (;;) {
155d1748302SMartin Schwidefsky 			if (!clockevents_program_event(dev, next, false))
156906568c9SThomas Gleixner 				return;
157906568c9SThomas Gleixner 			next = ktime_add(next, tick_period);
158906568c9SThomas Gleixner 		}
159906568c9SThomas Gleixner 	}
160906568c9SThomas Gleixner }
161906568c9SThomas Gleixner 
162906568c9SThomas Gleixner /*
163906568c9SThomas Gleixner  * Setup the tick device
164906568c9SThomas Gleixner  */
165906568c9SThomas Gleixner static void tick_setup_device(struct tick_device *td,
166906568c9SThomas Gleixner 			      struct clock_event_device *newdev, int cpu,
1670de26520SRusty Russell 			      const struct cpumask *cpumask)
168906568c9SThomas Gleixner {
169906568c9SThomas Gleixner 	ktime_t next_event;
170906568c9SThomas Gleixner 	void (*handler)(struct clock_event_device *) = NULL;
171906568c9SThomas Gleixner 
172906568c9SThomas Gleixner 	/*
173906568c9SThomas Gleixner 	 * First device setup ?
174906568c9SThomas Gleixner 	 */
175906568c9SThomas Gleixner 	if (!td->evtdev) {
176906568c9SThomas Gleixner 		/*
177906568c9SThomas Gleixner 		 * If no cpu took the do_timer update, assign it to
178906568c9SThomas Gleixner 		 * this cpu:
179906568c9SThomas Gleixner 		 */
1806441402bSThomas Gleixner 		if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) {
181c5bfece2SFrederic Weisbecker 			if (!tick_nohz_full_cpu(cpu))
182906568c9SThomas Gleixner 				tick_do_timer_cpu = cpu;
183a382bf93SFrederic Weisbecker 			else
184a382bf93SFrederic Weisbecker 				tick_do_timer_cpu = TICK_DO_TIMER_NONE;
185906568c9SThomas Gleixner 			tick_next_period = ktime_get();
186906568c9SThomas Gleixner 			tick_period = ktime_set(0, NSEC_PER_SEC / HZ);
187906568c9SThomas Gleixner 		}
188906568c9SThomas Gleixner 
189906568c9SThomas Gleixner 		/*
190906568c9SThomas Gleixner 		 * Startup in periodic mode first.
191906568c9SThomas Gleixner 		 */
192906568c9SThomas Gleixner 		td->mode = TICKDEV_MODE_PERIODIC;
193906568c9SThomas Gleixner 	} else {
194906568c9SThomas Gleixner 		handler = td->evtdev->event_handler;
195906568c9SThomas Gleixner 		next_event = td->evtdev->next_event;
1967c1e7689SVenkatesh Pallipadi 		td->evtdev->event_handler = clockevents_handle_noop;
197906568c9SThomas Gleixner 	}
198906568c9SThomas Gleixner 
199906568c9SThomas Gleixner 	td->evtdev = newdev;
200906568c9SThomas Gleixner 
201906568c9SThomas Gleixner 	/*
202906568c9SThomas Gleixner 	 * When the device is not per cpu, pin the interrupt to the
203906568c9SThomas Gleixner 	 * current cpu:
204906568c9SThomas Gleixner 	 */
205320ab2b0SRusty Russell 	if (!cpumask_equal(newdev->cpumask, cpumask))
2060de26520SRusty Russell 		irq_set_affinity(newdev->irq, cpumask);
207906568c9SThomas Gleixner 
208f8381cbaSThomas Gleixner 	/*
209f8381cbaSThomas Gleixner 	 * When global broadcasting is active, check if the current
210f8381cbaSThomas Gleixner 	 * device is registered as a placeholder for broadcast mode.
211f8381cbaSThomas Gleixner 	 * This allows us to handle this x86 misfeature in a generic
21207bd1172SThomas Gleixner 	 * way. This function also returns !=0 when we keep the
21307bd1172SThomas Gleixner 	 * current active broadcast state for this CPU.
214f8381cbaSThomas Gleixner 	 */
215f8381cbaSThomas Gleixner 	if (tick_device_uses_broadcast(newdev, cpu))
216f8381cbaSThomas Gleixner 		return;
217f8381cbaSThomas Gleixner 
218906568c9SThomas Gleixner 	if (td->mode == TICKDEV_MODE_PERIODIC)
219906568c9SThomas Gleixner 		tick_setup_periodic(newdev, 0);
22079bf2bb3SThomas Gleixner 	else
22179bf2bb3SThomas Gleixner 		tick_setup_oneshot(newdev, handler, next_event);
222906568c9SThomas Gleixner }
223906568c9SThomas Gleixner 
22403e13cf5SThomas Gleixner void tick_install_replacement(struct clock_event_device *newdev)
22503e13cf5SThomas Gleixner {
22603e13cf5SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
22703e13cf5SThomas Gleixner 	int cpu = smp_processor_id();
22803e13cf5SThomas Gleixner 
22903e13cf5SThomas Gleixner 	clockevents_exchange_device(td->evtdev, newdev);
23003e13cf5SThomas Gleixner 	tick_setup_device(td, newdev, cpu, cpumask_of(cpu));
23103e13cf5SThomas Gleixner 	if (newdev->features & CLOCK_EVT_FEAT_ONESHOT)
23203e13cf5SThomas Gleixner 		tick_oneshot_notify();
23303e13cf5SThomas Gleixner }
23403e13cf5SThomas Gleixner 
23545cb8e01SThomas Gleixner static bool tick_check_percpu(struct clock_event_device *curdev,
23645cb8e01SThomas Gleixner 			      struct clock_event_device *newdev, int cpu)
23745cb8e01SThomas Gleixner {
23845cb8e01SThomas Gleixner 	if (!cpumask_test_cpu(cpu, newdev->cpumask))
23945cb8e01SThomas Gleixner 		return false;
24045cb8e01SThomas Gleixner 	if (cpumask_equal(newdev->cpumask, cpumask_of(cpu)))
24145cb8e01SThomas Gleixner 		return true;
24245cb8e01SThomas Gleixner 	/* Check if irq affinity can be set */
24345cb8e01SThomas Gleixner 	if (newdev->irq >= 0 && !irq_can_set_affinity(newdev->irq))
24445cb8e01SThomas Gleixner 		return false;
24545cb8e01SThomas Gleixner 	/* Prefer an existing cpu local device */
24645cb8e01SThomas Gleixner 	if (curdev && cpumask_equal(curdev->cpumask, cpumask_of(cpu)))
24745cb8e01SThomas Gleixner 		return false;
24845cb8e01SThomas Gleixner 	return true;
24945cb8e01SThomas Gleixner }
25045cb8e01SThomas Gleixner 
25145cb8e01SThomas Gleixner static bool tick_check_preferred(struct clock_event_device *curdev,
25245cb8e01SThomas Gleixner 				 struct clock_event_device *newdev)
25345cb8e01SThomas Gleixner {
25445cb8e01SThomas Gleixner 	/* Prefer oneshot capable device */
25545cb8e01SThomas Gleixner 	if (!(newdev->features & CLOCK_EVT_FEAT_ONESHOT)) {
25645cb8e01SThomas Gleixner 		if (curdev && (curdev->features & CLOCK_EVT_FEAT_ONESHOT))
25745cb8e01SThomas Gleixner 			return false;
25845cb8e01SThomas Gleixner 		if (tick_oneshot_mode_active())
25945cb8e01SThomas Gleixner 			return false;
26045cb8e01SThomas Gleixner 	}
26145cb8e01SThomas Gleixner 
26270e5975dSStephen Boyd 	/*
26370e5975dSStephen Boyd 	 * Use the higher rated one, but prefer a CPU local device with a lower
26470e5975dSStephen Boyd 	 * rating than a non-CPU local device
26570e5975dSStephen Boyd 	 */
26670e5975dSStephen Boyd 	return !curdev ||
26770e5975dSStephen Boyd 		newdev->rating > curdev->rating ||
26870e5975dSStephen Boyd 	       !cpumask_equal(curdev->cpumask, newdev->cpumask);
26945cb8e01SThomas Gleixner }
27045cb8e01SThomas Gleixner 
271906568c9SThomas Gleixner /*
27203e13cf5SThomas Gleixner  * Check whether the new device is a better fit than curdev. curdev
27303e13cf5SThomas Gleixner  * can be NULL !
27403e13cf5SThomas Gleixner  */
27503e13cf5SThomas Gleixner bool tick_check_replacement(struct clock_event_device *curdev,
27603e13cf5SThomas Gleixner 			    struct clock_event_device *newdev)
27703e13cf5SThomas Gleixner {
27803e13cf5SThomas Gleixner 	if (tick_check_percpu(curdev, newdev, smp_processor_id()))
27903e13cf5SThomas Gleixner 		return false;
28003e13cf5SThomas Gleixner 
28103e13cf5SThomas Gleixner 	return tick_check_preferred(curdev, newdev);
28203e13cf5SThomas Gleixner }
28303e13cf5SThomas Gleixner 
28403e13cf5SThomas Gleixner /*
2857126cac4SThomas Gleixner  * Check, if the new registered device should be used. Called with
2867126cac4SThomas Gleixner  * clockevents_lock held and interrupts disabled.
287906568c9SThomas Gleixner  */
2887172a286SThomas Gleixner void tick_check_new_device(struct clock_event_device *newdev)
289906568c9SThomas Gleixner {
290906568c9SThomas Gleixner 	struct clock_event_device *curdev;
291906568c9SThomas Gleixner 	struct tick_device *td;
2927172a286SThomas Gleixner 	int cpu;
293906568c9SThomas Gleixner 
294906568c9SThomas Gleixner 	cpu = smp_processor_id();
295320ab2b0SRusty Russell 	if (!cpumask_test_cpu(cpu, newdev->cpumask))
2964a93232dSVenki Pallipadi 		goto out_bc;
297906568c9SThomas Gleixner 
298906568c9SThomas Gleixner 	td = &per_cpu(tick_cpu_device, cpu);
299906568c9SThomas Gleixner 	curdev = td->evtdev;
300906568c9SThomas Gleixner 
301906568c9SThomas Gleixner 	/* cpu local device ? */
30245cb8e01SThomas Gleixner 	if (!tick_check_percpu(curdev, newdev, cpu))
303906568c9SThomas Gleixner 		goto out_bc;
304906568c9SThomas Gleixner 
30545cb8e01SThomas Gleixner 	/* Preference decision */
30645cb8e01SThomas Gleixner 	if (!tick_check_preferred(curdev, newdev))
307906568c9SThomas Gleixner 		goto out_bc;
308906568c9SThomas Gleixner 
309ccf33d68SThomas Gleixner 	if (!try_module_get(newdev->owner))
310ccf33d68SThomas Gleixner 		return;
311ccf33d68SThomas Gleixner 
312906568c9SThomas Gleixner 	/*
313906568c9SThomas Gleixner 	 * Replace the eventually existing device by the new
314f8381cbaSThomas Gleixner 	 * device. If the current device is the broadcast device, do
315f8381cbaSThomas Gleixner 	 * not give it back to the clockevents layer !
316906568c9SThomas Gleixner 	 */
317f8381cbaSThomas Gleixner 	if (tick_is_broadcast_device(curdev)) {
3182344abbcSThomas Gleixner 		clockevents_shutdown(curdev);
319f8381cbaSThomas Gleixner 		curdev = NULL;
320f8381cbaSThomas Gleixner 	}
321906568c9SThomas Gleixner 	clockevents_exchange_device(curdev, newdev);
3226b954823SRusty Russell 	tick_setup_device(td, newdev, cpu, cpumask_of(cpu));
32379bf2bb3SThomas Gleixner 	if (newdev->features & CLOCK_EVT_FEAT_ONESHOT)
32479bf2bb3SThomas Gleixner 		tick_oneshot_notify();
3257172a286SThomas Gleixner 	return;
326f8381cbaSThomas Gleixner 
327f8381cbaSThomas Gleixner out_bc:
328f8381cbaSThomas Gleixner 	/*
329f8381cbaSThomas Gleixner 	 * Can the new device be used as a broadcast device ?
330f8381cbaSThomas Gleixner 	 */
3317172a286SThomas Gleixner 	tick_install_broadcast_device(newdev);
332906568c9SThomas Gleixner }
333906568c9SThomas Gleixner 
334906568c9SThomas Gleixner /*
33594df7de0SSebastien Dugue  * Transfer the do_timer job away from a dying cpu.
33694df7de0SSebastien Dugue  *
33794df7de0SSebastien Dugue  * Called with interrupts disabled.
33894df7de0SSebastien Dugue  */
3398c53daf6SThomas Gleixner void tick_handover_do_timer(int *cpup)
34094df7de0SSebastien Dugue {
34194df7de0SSebastien Dugue 	if (*cpup == tick_do_timer_cpu) {
34294df7de0SSebastien Dugue 		int cpu = cpumask_first(cpu_online_mask);
34394df7de0SSebastien Dugue 
34494df7de0SSebastien Dugue 		tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu :
34594df7de0SSebastien Dugue 			TICK_DO_TIMER_NONE;
34694df7de0SSebastien Dugue 	}
34794df7de0SSebastien Dugue }
34894df7de0SSebastien Dugue 
34994df7de0SSebastien Dugue /*
350906568c9SThomas Gleixner  * Shutdown an event device on a given cpu:
351906568c9SThomas Gleixner  *
352906568c9SThomas Gleixner  * This is called on a life CPU, when a CPU is dead. So we cannot
353906568c9SThomas Gleixner  * access the hardware device itself.
354906568c9SThomas Gleixner  * We just set the mode and remove it from the lists.
355906568c9SThomas Gleixner  */
3568c53daf6SThomas Gleixner void tick_shutdown(unsigned int *cpup)
357906568c9SThomas Gleixner {
358906568c9SThomas Gleixner 	struct tick_device *td = &per_cpu(tick_cpu_device, *cpup);
359906568c9SThomas Gleixner 	struct clock_event_device *dev = td->evtdev;
360906568c9SThomas Gleixner 
361906568c9SThomas Gleixner 	td->mode = TICKDEV_MODE_PERIODIC;
362906568c9SThomas Gleixner 	if (dev) {
363906568c9SThomas Gleixner 		/*
364906568c9SThomas Gleixner 		 * Prevent that the clock events layer tries to call
365906568c9SThomas Gleixner 		 * the set mode function!
366906568c9SThomas Gleixner 		 */
367906568c9SThomas Gleixner 		dev->mode = CLOCK_EVT_MODE_UNUSED;
368906568c9SThomas Gleixner 		clockevents_exchange_device(dev, NULL);
3696f7a05d7SThomas Gleixner 		dev->event_handler = clockevents_handle_noop;
370906568c9SThomas Gleixner 		td->evtdev = NULL;
371906568c9SThomas Gleixner 	}
372906568c9SThomas Gleixner }
373906568c9SThomas Gleixner 
3748c53daf6SThomas Gleixner void tick_suspend(void)
3756321dd60SThomas Gleixner {
3766321dd60SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
3776321dd60SThomas Gleixner 
3782344abbcSThomas Gleixner 	clockevents_shutdown(td->evtdev);
3796321dd60SThomas Gleixner }
3806321dd60SThomas Gleixner 
3818c53daf6SThomas Gleixner void tick_resume(void)
3826321dd60SThomas Gleixner {
3836321dd60SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
38418de5bc4SThomas Gleixner 	int broadcast = tick_resume_broadcast();
3856321dd60SThomas Gleixner 
38618de5bc4SThomas Gleixner 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
38718de5bc4SThomas Gleixner 
38818de5bc4SThomas Gleixner 	if (!broadcast) {
3896321dd60SThomas Gleixner 		if (td->mode == TICKDEV_MODE_PERIODIC)
3906321dd60SThomas Gleixner 			tick_setup_periodic(td->evtdev, 0);
391cd05a1f8SThomas Gleixner 		else
392cd05a1f8SThomas Gleixner 			tick_resume_oneshot();
39318de5bc4SThomas Gleixner 	}
3946321dd60SThomas Gleixner }
3956321dd60SThomas Gleixner 
396906568c9SThomas Gleixner /**
397906568c9SThomas Gleixner  * tick_init - initialize the tick control
398906568c9SThomas Gleixner  */
399906568c9SThomas Gleixner void __init tick_init(void)
400906568c9SThomas Gleixner {
401b352bc1cSThomas Gleixner 	tick_broadcast_init();
402906568c9SThomas Gleixner }
403