xref: /openbmc/linux/kernel/time/tick-common.c (revision cacb3c76c2012ade52124e8c6fdc5cb125625772)
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;
36050ded1bSAndrew Morton 
37050ded1bSAndrew Morton /*
38050ded1bSAndrew Morton  * tick_do_timer_cpu is a timer core internal variable which holds the CPU NR
39050ded1bSAndrew Morton  * which is responsible for calling do_timer(), i.e. the timekeeping stuff. This
40050ded1bSAndrew Morton  * variable has two functions:
41050ded1bSAndrew Morton  *
42050ded1bSAndrew Morton  * 1) Prevent a thundering herd issue of a gazillion of CPUs trying to grab the
43050ded1bSAndrew Morton  *    timekeeping lock all at once. Only the CPU which is assigned to do the
44050ded1bSAndrew Morton  *    update is handling it.
45050ded1bSAndrew Morton  *
46050ded1bSAndrew Morton  * 2) Hand off the duty in the NOHZ idle case by setting the value to
47050ded1bSAndrew Morton  *    TICK_DO_TIMER_NONE, i.e. a non existing CPU. So the next cpu which looks
48050ded1bSAndrew Morton  *    at it will take over and keep the time keeping alive.  The handover
49050ded1bSAndrew Morton  *    procedure also covers cpu hotplug.
50050ded1bSAndrew 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);
8847a1b796SJohn Stultz 		update_wall_time();
89906568c9SThomas Gleixner 	}
90906568c9SThomas Gleixner 
91906568c9SThomas Gleixner 	update_process_times(user_mode(get_irq_regs()));
92906568c9SThomas Gleixner 	profile_tick(CPU_PROFILING);
93906568c9SThomas Gleixner }
94906568c9SThomas Gleixner 
95906568c9SThomas Gleixner /*
96906568c9SThomas Gleixner  * Event handler for periodic ticks
97906568c9SThomas Gleixner  */
98906568c9SThomas Gleixner void tick_handle_periodic(struct clock_event_device *dev)
99906568c9SThomas Gleixner {
100906568c9SThomas Gleixner 	int cpu = smp_processor_id();
1013494c166SDavid S. Miller 	ktime_t next;
102906568c9SThomas Gleixner 
103906568c9SThomas Gleixner 	tick_periodic(cpu);
104906568c9SThomas Gleixner 
105906568c9SThomas Gleixner 	if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
106906568c9SThomas Gleixner 		return;
107906568c9SThomas Gleixner 	/*
108906568c9SThomas Gleixner 	 * Setup the next period for devices, which do not have
109906568c9SThomas Gleixner 	 * periodic mode:
110906568c9SThomas Gleixner 	 */
1113494c166SDavid S. Miller 	next = ktime_add(dev->next_event, tick_period);
112906568c9SThomas Gleixner 	for (;;) {
113d1748302SMartin Schwidefsky 		if (!clockevents_program_event(dev, next, false))
114906568c9SThomas Gleixner 			return;
11574a03b69Sjohn stultz 		/*
11674a03b69Sjohn stultz 		 * Have to be careful here. If we're in oneshot mode,
11774a03b69Sjohn stultz 		 * before we call tick_periodic() in a loop, we need
11874a03b69Sjohn stultz 		 * to be sure we're using a real hardware clocksource.
11974a03b69Sjohn stultz 		 * Otherwise we could get trapped in an infinite
12074a03b69Sjohn stultz 		 * loop, as the tick_periodic() increments jiffies,
121*cacb3c76SViresh Kumar 		 * which then will increment time, possibly causing
12274a03b69Sjohn stultz 		 * the loop to trigger again and again.
12374a03b69Sjohn stultz 		 */
12474a03b69Sjohn stultz 		if (timekeeping_valid_for_hres())
125906568c9SThomas Gleixner 			tick_periodic(cpu);
1263494c166SDavid S. Miller 		next = ktime_add(next, tick_period);
127906568c9SThomas Gleixner 	}
128906568c9SThomas Gleixner }
129906568c9SThomas Gleixner 
130906568c9SThomas Gleixner /*
131906568c9SThomas Gleixner  * Setup the device for a periodic tick
132906568c9SThomas Gleixner  */
133f8381cbaSThomas Gleixner void tick_setup_periodic(struct clock_event_device *dev, int broadcast)
134906568c9SThomas Gleixner {
135f8381cbaSThomas Gleixner 	tick_set_periodic_handler(dev, broadcast);
136f8381cbaSThomas Gleixner 
137f8381cbaSThomas Gleixner 	/* Broadcast setup ? */
138f8381cbaSThomas Gleixner 	if (!tick_device_is_functional(dev))
139f8381cbaSThomas Gleixner 		return;
140906568c9SThomas Gleixner 
14127ce4cb4SThomas Gleixner 	if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) &&
14227ce4cb4SThomas Gleixner 	    !tick_broadcast_oneshot_active()) {
143906568c9SThomas Gleixner 		clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC);
144906568c9SThomas Gleixner 	} else {
145906568c9SThomas Gleixner 		unsigned long seq;
146906568c9SThomas Gleixner 		ktime_t next;
147906568c9SThomas Gleixner 
148906568c9SThomas Gleixner 		do {
149d6ad4187SJohn Stultz 			seq = read_seqbegin(&jiffies_lock);
150906568c9SThomas Gleixner 			next = tick_next_period;
151d6ad4187SJohn Stultz 		} while (read_seqretry(&jiffies_lock, seq));
152906568c9SThomas Gleixner 
153906568c9SThomas Gleixner 		clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
154906568c9SThomas Gleixner 
155906568c9SThomas Gleixner 		for (;;) {
156d1748302SMartin Schwidefsky 			if (!clockevents_program_event(dev, next, false))
157906568c9SThomas Gleixner 				return;
158906568c9SThomas Gleixner 			next = ktime_add(next, tick_period);
159906568c9SThomas Gleixner 		}
160906568c9SThomas Gleixner 	}
161906568c9SThomas Gleixner }
162906568c9SThomas Gleixner 
163906568c9SThomas Gleixner /*
164906568c9SThomas Gleixner  * Setup the tick device
165906568c9SThomas Gleixner  */
166906568c9SThomas Gleixner static void tick_setup_device(struct tick_device *td,
167906568c9SThomas Gleixner 			      struct clock_event_device *newdev, int cpu,
1680de26520SRusty Russell 			      const struct cpumask *cpumask)
169906568c9SThomas Gleixner {
170906568c9SThomas Gleixner 	ktime_t next_event;
171906568c9SThomas Gleixner 	void (*handler)(struct clock_event_device *) = NULL;
172906568c9SThomas Gleixner 
173906568c9SThomas Gleixner 	/*
174906568c9SThomas Gleixner 	 * First device setup ?
175906568c9SThomas Gleixner 	 */
176906568c9SThomas Gleixner 	if (!td->evtdev) {
177906568c9SThomas Gleixner 		/*
178906568c9SThomas Gleixner 		 * If no cpu took the do_timer update, assign it to
179906568c9SThomas Gleixner 		 * this cpu:
180906568c9SThomas Gleixner 		 */
1816441402bSThomas Gleixner 		if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) {
182c5bfece2SFrederic Weisbecker 			if (!tick_nohz_full_cpu(cpu))
183906568c9SThomas Gleixner 				tick_do_timer_cpu = cpu;
184a382bf93SFrederic Weisbecker 			else
185a382bf93SFrederic Weisbecker 				tick_do_timer_cpu = TICK_DO_TIMER_NONE;
186906568c9SThomas Gleixner 			tick_next_period = ktime_get();
187906568c9SThomas Gleixner 			tick_period = ktime_set(0, NSEC_PER_SEC / HZ);
188906568c9SThomas Gleixner 		}
189906568c9SThomas Gleixner 
190906568c9SThomas Gleixner 		/*
191906568c9SThomas Gleixner 		 * Startup in periodic mode first.
192906568c9SThomas Gleixner 		 */
193906568c9SThomas Gleixner 		td->mode = TICKDEV_MODE_PERIODIC;
194906568c9SThomas Gleixner 	} else {
195906568c9SThomas Gleixner 		handler = td->evtdev->event_handler;
196906568c9SThomas Gleixner 		next_event = td->evtdev->next_event;
1977c1e7689SVenkatesh Pallipadi 		td->evtdev->event_handler = clockevents_handle_noop;
198906568c9SThomas Gleixner 	}
199906568c9SThomas Gleixner 
200906568c9SThomas Gleixner 	td->evtdev = newdev;
201906568c9SThomas Gleixner 
202906568c9SThomas Gleixner 	/*
203906568c9SThomas Gleixner 	 * When the device is not per cpu, pin the interrupt to the
204906568c9SThomas Gleixner 	 * current cpu:
205906568c9SThomas Gleixner 	 */
206320ab2b0SRusty Russell 	if (!cpumask_equal(newdev->cpumask, cpumask))
2070de26520SRusty Russell 		irq_set_affinity(newdev->irq, cpumask);
208906568c9SThomas Gleixner 
209f8381cbaSThomas Gleixner 	/*
210f8381cbaSThomas Gleixner 	 * When global broadcasting is active, check if the current
211f8381cbaSThomas Gleixner 	 * device is registered as a placeholder for broadcast mode.
212f8381cbaSThomas Gleixner 	 * This allows us to handle this x86 misfeature in a generic
21307bd1172SThomas Gleixner 	 * way. This function also returns !=0 when we keep the
21407bd1172SThomas Gleixner 	 * current active broadcast state for this CPU.
215f8381cbaSThomas Gleixner 	 */
216f8381cbaSThomas Gleixner 	if (tick_device_uses_broadcast(newdev, cpu))
217f8381cbaSThomas Gleixner 		return;
218f8381cbaSThomas Gleixner 
219906568c9SThomas Gleixner 	if (td->mode == TICKDEV_MODE_PERIODIC)
220906568c9SThomas Gleixner 		tick_setup_periodic(newdev, 0);
22179bf2bb3SThomas Gleixner 	else
22279bf2bb3SThomas Gleixner 		tick_setup_oneshot(newdev, handler, next_event);
223906568c9SThomas Gleixner }
224906568c9SThomas Gleixner 
22503e13cf5SThomas Gleixner void tick_install_replacement(struct clock_event_device *newdev)
22603e13cf5SThomas Gleixner {
22703e13cf5SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
22803e13cf5SThomas Gleixner 	int cpu = smp_processor_id();
22903e13cf5SThomas Gleixner 
23003e13cf5SThomas Gleixner 	clockevents_exchange_device(td->evtdev, newdev);
23103e13cf5SThomas Gleixner 	tick_setup_device(td, newdev, cpu, cpumask_of(cpu));
23203e13cf5SThomas Gleixner 	if (newdev->features & CLOCK_EVT_FEAT_ONESHOT)
23303e13cf5SThomas Gleixner 		tick_oneshot_notify();
23403e13cf5SThomas Gleixner }
23503e13cf5SThomas Gleixner 
23645cb8e01SThomas Gleixner static bool tick_check_percpu(struct clock_event_device *curdev,
23745cb8e01SThomas Gleixner 			      struct clock_event_device *newdev, int cpu)
23845cb8e01SThomas Gleixner {
23945cb8e01SThomas Gleixner 	if (!cpumask_test_cpu(cpu, newdev->cpumask))
24045cb8e01SThomas Gleixner 		return false;
24145cb8e01SThomas Gleixner 	if (cpumask_equal(newdev->cpumask, cpumask_of(cpu)))
24245cb8e01SThomas Gleixner 		return true;
24345cb8e01SThomas Gleixner 	/* Check if irq affinity can be set */
24445cb8e01SThomas Gleixner 	if (newdev->irq >= 0 && !irq_can_set_affinity(newdev->irq))
24545cb8e01SThomas Gleixner 		return false;
24645cb8e01SThomas Gleixner 	/* Prefer an existing cpu local device */
24745cb8e01SThomas Gleixner 	if (curdev && cpumask_equal(curdev->cpumask, cpumask_of(cpu)))
24845cb8e01SThomas Gleixner 		return false;
24945cb8e01SThomas Gleixner 	return true;
25045cb8e01SThomas Gleixner }
25145cb8e01SThomas Gleixner 
25245cb8e01SThomas Gleixner static bool tick_check_preferred(struct clock_event_device *curdev,
25345cb8e01SThomas Gleixner 				 struct clock_event_device *newdev)
25445cb8e01SThomas Gleixner {
25545cb8e01SThomas Gleixner 	/* Prefer oneshot capable device */
25645cb8e01SThomas Gleixner 	if (!(newdev->features & CLOCK_EVT_FEAT_ONESHOT)) {
25745cb8e01SThomas Gleixner 		if (curdev && (curdev->features & CLOCK_EVT_FEAT_ONESHOT))
25845cb8e01SThomas Gleixner 			return false;
25945cb8e01SThomas Gleixner 		if (tick_oneshot_mode_active())
26045cb8e01SThomas Gleixner 			return false;
26145cb8e01SThomas Gleixner 	}
26245cb8e01SThomas Gleixner 
26370e5975dSStephen Boyd 	/*
26470e5975dSStephen Boyd 	 * Use the higher rated one, but prefer a CPU local device with a lower
26570e5975dSStephen Boyd 	 * rating than a non-CPU local device
26670e5975dSStephen Boyd 	 */
26770e5975dSStephen Boyd 	return !curdev ||
26870e5975dSStephen Boyd 		newdev->rating > curdev->rating ||
26970e5975dSStephen Boyd 	       !cpumask_equal(curdev->cpumask, newdev->cpumask);
27045cb8e01SThomas Gleixner }
27145cb8e01SThomas Gleixner 
272906568c9SThomas Gleixner /*
27303e13cf5SThomas Gleixner  * Check whether the new device is a better fit than curdev. curdev
27403e13cf5SThomas Gleixner  * can be NULL !
27503e13cf5SThomas Gleixner  */
27603e13cf5SThomas Gleixner bool tick_check_replacement(struct clock_event_device *curdev,
27703e13cf5SThomas Gleixner 			    struct clock_event_device *newdev)
27803e13cf5SThomas Gleixner {
27903e13cf5SThomas Gleixner 	if (tick_check_percpu(curdev, newdev, smp_processor_id()))
28003e13cf5SThomas Gleixner 		return false;
28103e13cf5SThomas Gleixner 
28203e13cf5SThomas Gleixner 	return tick_check_preferred(curdev, newdev);
28303e13cf5SThomas Gleixner }
28403e13cf5SThomas Gleixner 
28503e13cf5SThomas Gleixner /*
2867126cac4SThomas Gleixner  * Check, if the new registered device should be used. Called with
2877126cac4SThomas Gleixner  * clockevents_lock held and interrupts disabled.
288906568c9SThomas Gleixner  */
2897172a286SThomas Gleixner void tick_check_new_device(struct clock_event_device *newdev)
290906568c9SThomas Gleixner {
291906568c9SThomas Gleixner 	struct clock_event_device *curdev;
292906568c9SThomas Gleixner 	struct tick_device *td;
2937172a286SThomas Gleixner 	int cpu;
294906568c9SThomas Gleixner 
295906568c9SThomas Gleixner 	cpu = smp_processor_id();
296320ab2b0SRusty Russell 	if (!cpumask_test_cpu(cpu, newdev->cpumask))
2974a93232dSVenki Pallipadi 		goto out_bc;
298906568c9SThomas Gleixner 
299906568c9SThomas Gleixner 	td = &per_cpu(tick_cpu_device, cpu);
300906568c9SThomas Gleixner 	curdev = td->evtdev;
301906568c9SThomas Gleixner 
302906568c9SThomas Gleixner 	/* cpu local device ? */
30345cb8e01SThomas Gleixner 	if (!tick_check_percpu(curdev, newdev, cpu))
304906568c9SThomas Gleixner 		goto out_bc;
305906568c9SThomas Gleixner 
30645cb8e01SThomas Gleixner 	/* Preference decision */
30745cb8e01SThomas Gleixner 	if (!tick_check_preferred(curdev, newdev))
308906568c9SThomas Gleixner 		goto out_bc;
309906568c9SThomas Gleixner 
310ccf33d68SThomas Gleixner 	if (!try_module_get(newdev->owner))
311ccf33d68SThomas Gleixner 		return;
312ccf33d68SThomas Gleixner 
313906568c9SThomas Gleixner 	/*
314906568c9SThomas Gleixner 	 * Replace the eventually existing device by the new
315f8381cbaSThomas Gleixner 	 * device. If the current device is the broadcast device, do
316f8381cbaSThomas Gleixner 	 * not give it back to the clockevents layer !
317906568c9SThomas Gleixner 	 */
318f8381cbaSThomas Gleixner 	if (tick_is_broadcast_device(curdev)) {
3192344abbcSThomas Gleixner 		clockevents_shutdown(curdev);
320f8381cbaSThomas Gleixner 		curdev = NULL;
321f8381cbaSThomas Gleixner 	}
322906568c9SThomas Gleixner 	clockevents_exchange_device(curdev, newdev);
3236b954823SRusty Russell 	tick_setup_device(td, newdev, cpu, cpumask_of(cpu));
32479bf2bb3SThomas Gleixner 	if (newdev->features & CLOCK_EVT_FEAT_ONESHOT)
32579bf2bb3SThomas Gleixner 		tick_oneshot_notify();
3267172a286SThomas Gleixner 	return;
327f8381cbaSThomas Gleixner 
328f8381cbaSThomas Gleixner out_bc:
329f8381cbaSThomas Gleixner 	/*
330f8381cbaSThomas Gleixner 	 * Can the new device be used as a broadcast device ?
331f8381cbaSThomas Gleixner 	 */
3327172a286SThomas Gleixner 	tick_install_broadcast_device(newdev);
333906568c9SThomas Gleixner }
334906568c9SThomas Gleixner 
335906568c9SThomas Gleixner /*
33694df7de0SSebastien Dugue  * Transfer the do_timer job away from a dying cpu.
33794df7de0SSebastien Dugue  *
33894df7de0SSebastien Dugue  * Called with interrupts disabled.
33994df7de0SSebastien Dugue  */
3408c53daf6SThomas Gleixner void tick_handover_do_timer(int *cpup)
34194df7de0SSebastien Dugue {
34294df7de0SSebastien Dugue 	if (*cpup == tick_do_timer_cpu) {
34394df7de0SSebastien Dugue 		int cpu = cpumask_first(cpu_online_mask);
34494df7de0SSebastien Dugue 
34594df7de0SSebastien Dugue 		tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu :
34694df7de0SSebastien Dugue 			TICK_DO_TIMER_NONE;
34794df7de0SSebastien Dugue 	}
34894df7de0SSebastien Dugue }
34994df7de0SSebastien Dugue 
35094df7de0SSebastien Dugue /*
351906568c9SThomas Gleixner  * Shutdown an event device on a given cpu:
352906568c9SThomas Gleixner  *
353906568c9SThomas Gleixner  * This is called on a life CPU, when a CPU is dead. So we cannot
354906568c9SThomas Gleixner  * access the hardware device itself.
355906568c9SThomas Gleixner  * We just set the mode and remove it from the lists.
356906568c9SThomas Gleixner  */
3578c53daf6SThomas Gleixner void tick_shutdown(unsigned int *cpup)
358906568c9SThomas Gleixner {
359906568c9SThomas Gleixner 	struct tick_device *td = &per_cpu(tick_cpu_device, *cpup);
360906568c9SThomas Gleixner 	struct clock_event_device *dev = td->evtdev;
361906568c9SThomas Gleixner 
362906568c9SThomas Gleixner 	td->mode = TICKDEV_MODE_PERIODIC;
363906568c9SThomas Gleixner 	if (dev) {
364906568c9SThomas Gleixner 		/*
365906568c9SThomas Gleixner 		 * Prevent that the clock events layer tries to call
366906568c9SThomas Gleixner 		 * the set mode function!
367906568c9SThomas Gleixner 		 */
368906568c9SThomas Gleixner 		dev->mode = CLOCK_EVT_MODE_UNUSED;
369906568c9SThomas Gleixner 		clockevents_exchange_device(dev, NULL);
3706f7a05d7SThomas Gleixner 		dev->event_handler = clockevents_handle_noop;
371906568c9SThomas Gleixner 		td->evtdev = NULL;
372906568c9SThomas Gleixner 	}
373906568c9SThomas Gleixner }
374906568c9SThomas Gleixner 
3758c53daf6SThomas Gleixner void tick_suspend(void)
3766321dd60SThomas Gleixner {
3776321dd60SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
3786321dd60SThomas Gleixner 
3792344abbcSThomas Gleixner 	clockevents_shutdown(td->evtdev);
3806321dd60SThomas Gleixner }
3816321dd60SThomas Gleixner 
3828c53daf6SThomas Gleixner void tick_resume(void)
3836321dd60SThomas Gleixner {
3846321dd60SThomas Gleixner 	struct tick_device *td = &__get_cpu_var(tick_cpu_device);
38518de5bc4SThomas Gleixner 	int broadcast = tick_resume_broadcast();
3866321dd60SThomas Gleixner 
38718de5bc4SThomas Gleixner 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
38818de5bc4SThomas Gleixner 
38918de5bc4SThomas Gleixner 	if (!broadcast) {
3906321dd60SThomas Gleixner 		if (td->mode == TICKDEV_MODE_PERIODIC)
3916321dd60SThomas Gleixner 			tick_setup_periodic(td->evtdev, 0);
392cd05a1f8SThomas Gleixner 		else
393cd05a1f8SThomas Gleixner 			tick_resume_oneshot();
39418de5bc4SThomas Gleixner 	}
3956321dd60SThomas Gleixner }
3966321dd60SThomas Gleixner 
397906568c9SThomas Gleixner /**
398906568c9SThomas Gleixner  * tick_init - initialize the tick control
399906568c9SThomas Gleixner  */
400906568c9SThomas Gleixner void __init tick_init(void)
401906568c9SThomas Gleixner {
402b352bc1cSThomas Gleixner 	tick_broadcast_init();
403906568c9SThomas Gleixner }
404