futex: futex_wake_op, fix sign_extend32 sign bits
[linux/fpc-iii.git] / kernel / time / tick-oneshot.c
blobc1f518e7aa808a281b5dab69f3961a02b2c14315
1 /*
2 * linux/kernel/time/tick-oneshot.c
4 * This file contains functions which manage high resolution tick
5 * related events.
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"
24 /**
25 * tick_program_event
27 int tick_program_event(ktime_t expires, int force)
29 struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
31 if (unlikely(expires == KTIME_MAX)) {
33 * We don't need the clock event device any more, stop it.
35 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
36 dev->next_event = KTIME_MAX;
37 return 0;
40 if (unlikely(clockevent_state_oneshot_stopped(dev))) {
42 * We need the clock event again, configure it in ONESHOT mode
43 * before using it.
45 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
48 return clockevents_program_event(dev, expires, force);
51 /**
52 * tick_resume_onshot - resume oneshot mode
54 void tick_resume_oneshot(void)
56 struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
58 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
59 clockevents_program_event(dev, ktime_get(), true);
62 /**
63 * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
65 void tick_setup_oneshot(struct clock_event_device *newdev,
66 void (*handler)(struct clock_event_device *),
67 ktime_t next_event)
69 newdev->event_handler = handler;
70 clockevents_switch_state(newdev, CLOCK_EVT_STATE_ONESHOT);
71 clockevents_program_event(newdev, next_event, true);
74 /**
75 * tick_switch_to_oneshot - switch to oneshot mode
77 int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
79 struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
80 struct clock_event_device *dev = td->evtdev;
82 if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
83 !tick_device_is_functional(dev)) {
85 printk(KERN_INFO "Clockevents: "
86 "could not switch to one-shot mode:");
87 if (!dev) {
88 printk(" no tick device\n");
89 } else {
90 if (!tick_device_is_functional(dev))
91 printk(" %s is not functional.\n", dev->name);
92 else
93 printk(" %s does not support one-shot mode.\n",
94 dev->name);
96 return -EINVAL;
99 td->mode = TICKDEV_MODE_ONESHOT;
100 dev->event_handler = handler;
101 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
102 tick_broadcast_switch_to_oneshot();
103 return 0;
107 * tick_check_oneshot_mode - check whether the system is in oneshot mode
109 * returns 1 when either nohz or highres are enabled. otherwise 0.
111 int tick_oneshot_mode_active(void)
113 unsigned long flags;
114 int ret;
116 local_irq_save(flags);
117 ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
118 local_irq_restore(flags);
120 return ret;
123 #ifdef CONFIG_HIGH_RES_TIMERS
125 * tick_init_highres - switch to high resolution mode
127 * Called with interrupts disabled.
129 int tick_init_highres(void)
131 return tick_switch_to_oneshot(hrtimer_interrupt);
133 #endif