2 * linux/kernel/time/tick-oneshot.c
4 * This file contains functions which manage high resolution tick
7 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
8 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
9 * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
11 * This code is licenced under the GPL version 2. For details see
12 * kernel-base/COPYING.
14 #include <linux/cpu.h>
15 #include <linux/err.h>
16 #include <linux/hrtimer.h>
17 #include <linux/interrupt.h>
18 #include <linux/percpu.h>
19 #include <linux/profile.h>
20 #include <linux/sched.h>
22 #include "tick-internal.h"
27 int tick_program_event(ktime_t expires
, int force
)
29 struct clock_event_device
*dev
= __this_cpu_read(tick_cpu_device
.evtdev
);
31 return clockevents_program_event(dev
, expires
, force
);
35 * tick_resume_onshot - resume oneshot mode
37 void tick_resume_oneshot(void)
39 struct clock_event_device
*dev
= __this_cpu_read(tick_cpu_device
.evtdev
);
41 clockevents_set_state(dev
, CLOCK_EVT_STATE_ONESHOT
);
42 clockevents_program_event(dev
, ktime_get(), true);
46 * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
48 void tick_setup_oneshot(struct clock_event_device
*newdev
,
49 void (*handler
)(struct clock_event_device
*),
52 newdev
->event_handler
= handler
;
53 clockevents_set_state(newdev
, CLOCK_EVT_STATE_ONESHOT
);
54 clockevents_program_event(newdev
, next_event
, true);
58 * tick_switch_to_oneshot - switch to oneshot mode
60 int tick_switch_to_oneshot(void (*handler
)(struct clock_event_device
*))
62 struct tick_device
*td
= this_cpu_ptr(&tick_cpu_device
);
63 struct clock_event_device
*dev
= td
->evtdev
;
65 if (!dev
|| !(dev
->features
& CLOCK_EVT_FEAT_ONESHOT
) ||
66 !tick_device_is_functional(dev
)) {
68 printk(KERN_INFO
"Clockevents: "
69 "could not switch to one-shot mode:");
71 printk(" no tick device\n");
73 if (!tick_device_is_functional(dev
))
74 printk(" %s is not functional.\n", dev
->name
);
76 printk(" %s does not support one-shot mode.\n",
82 td
->mode
= TICKDEV_MODE_ONESHOT
;
83 dev
->event_handler
= handler
;
84 clockevents_set_state(dev
, CLOCK_EVT_STATE_ONESHOT
);
85 tick_broadcast_switch_to_oneshot();
90 * tick_check_oneshot_mode - check whether the system is in oneshot mode
92 * returns 1 when either nohz or highres are enabled. otherwise 0.
94 int tick_oneshot_mode_active(void)
99 local_irq_save(flags
);
100 ret
= __this_cpu_read(tick_cpu_device
.mode
) == TICKDEV_MODE_ONESHOT
;
101 local_irq_restore(flags
);
106 #ifdef CONFIG_HIGH_RES_TIMERS
108 * tick_init_highres - switch to high resolution mode
110 * Called with interrupts disabled.
112 int tick_init_highres(void)
114 return tick_switch_to_oneshot(hrtimer_interrupt
);