Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/time/tick-broadcast.c |
| 3 | * |
| 4 | * This file contains functions which emulate a local clock-event |
| 5 | * device via a broadcast event source. |
| 6 | * |
| 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 |
| 10 | * |
| 11 | * This code is licenced under the GPL version 2. For details see |
| 12 | * kernel-base/COPYING. |
| 13 | */ |
| 14 | #include <linux/cpu.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/hrtimer.h> |
Russell King | d7b9068 | 2008-04-17 07:46:24 +0200 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 18 | #include <linux/percpu.h> |
| 19 | #include <linux/profile.h> |
| 20 | #include <linux/sched.h> |
Mark Rutland | 12ad100 | 2013-01-14 17:05:22 +0000 | [diff] [blame^] | 21 | #include <linux/smp.h> |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 22 | |
| 23 | #include "tick-internal.h" |
| 24 | |
| 25 | /* |
| 26 | * Broadcast support for broken x86 hardware, where the local apic |
| 27 | * timer stops in C3 state. |
| 28 | */ |
| 29 | |
Dmitri Vorobiev | a52f5c5 | 2009-05-01 13:10:21 -0700 | [diff] [blame] | 30 | static struct tick_device tick_broadcast_device; |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 31 | /* FIXME: Use cpumask_var_t. */ |
| 32 | static DECLARE_BITMAP(tick_broadcast_mask, NR_CPUS); |
| 33 | static DECLARE_BITMAP(tmpmask, NR_CPUS); |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 34 | static DEFINE_RAW_SPINLOCK(tick_broadcast_lock); |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 35 | static int tick_broadcast_force; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 36 | |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_TICK_ONESHOT |
| 38 | static void tick_broadcast_clear_oneshot(int cpu); |
| 39 | #else |
| 40 | static inline void tick_broadcast_clear_oneshot(int cpu) { } |
| 41 | #endif |
| 42 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 43 | /* |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 44 | * Debugging: see timer_list.c |
| 45 | */ |
| 46 | struct tick_device *tick_get_broadcast_device(void) |
| 47 | { |
| 48 | return &tick_broadcast_device; |
| 49 | } |
| 50 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 51 | struct cpumask *tick_get_broadcast_mask(void) |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 52 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 53 | return to_cpumask(tick_broadcast_mask); |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 57 | * Start the device in periodic mode |
| 58 | */ |
| 59 | static void tick_broadcast_start_periodic(struct clock_event_device *bc) |
| 60 | { |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 61 | if (bc) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 62 | tick_setup_periodic(bc, 1); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Check, if the device can be utilized as broadcast device: |
| 67 | */ |
| 68 | int tick_check_broadcast_device(struct clock_event_device *dev) |
| 69 | { |
Venki Pallipadi | 4a93232 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 70 | if ((tick_broadcast_device.evtdev && |
| 71 | tick_broadcast_device.evtdev->rating >= dev->rating) || |
| 72 | (dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 73 | return 0; |
| 74 | |
Thomas Gleixner | c1be843 | 2011-12-02 12:34:16 +0100 | [diff] [blame] | 75 | clockevents_exchange_device(tick_broadcast_device.evtdev, dev); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 76 | tick_broadcast_device.evtdev = dev; |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 77 | if (!cpumask_empty(tick_get_broadcast_mask())) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 78 | tick_broadcast_start_periodic(dev); |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Check, if the device is the broadcast device |
| 84 | */ |
| 85 | int tick_is_broadcast_device(struct clock_event_device *dev) |
| 86 | { |
| 87 | return (dev && tick_broadcast_device.evtdev == dev); |
| 88 | } |
| 89 | |
Mark Rutland | 12ad100 | 2013-01-14 17:05:22 +0000 | [diff] [blame^] | 90 | static void err_broadcast(const struct cpumask *mask) |
| 91 | { |
| 92 | pr_crit_once("Failed to broadcast timer tick. Some CPUs may be unresponsive.\n"); |
| 93 | } |
| 94 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 95 | /* |
| 96 | * Check, if the device is disfunctional and a place holder, which |
| 97 | * needs to be handled by the broadcast device. |
| 98 | */ |
| 99 | int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) |
| 100 | { |
| 101 | unsigned long flags; |
| 102 | int ret = 0; |
| 103 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 104 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Devices might be registered with both periodic and oneshot |
| 108 | * mode disabled. This signals, that the device needs to be |
| 109 | * operated from the broadcast device and is a placeholder for |
| 110 | * the cpu local device. |
| 111 | */ |
| 112 | if (!tick_device_is_functional(dev)) { |
| 113 | dev->event_handler = tick_handle_periodic; |
Mark Rutland | 12ad100 | 2013-01-14 17:05:22 +0000 | [diff] [blame^] | 114 | if (!dev->broadcast) |
| 115 | dev->broadcast = tick_broadcast; |
| 116 | if (!dev->broadcast) { |
| 117 | pr_warn_once("%s depends on broadcast, but no broadcast function available\n", |
| 118 | dev->name); |
| 119 | dev->broadcast = err_broadcast; |
| 120 | } |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 121 | cpumask_set_cpu(cpu, tick_get_broadcast_mask()); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 122 | tick_broadcast_start_periodic(tick_broadcast_device.evtdev); |
| 123 | ret = 1; |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 124 | } else { |
| 125 | /* |
| 126 | * When the new device is not affected by the stop |
| 127 | * feature and the cpu is marked in the broadcast mask |
| 128 | * then clear the broadcast bit. |
| 129 | */ |
| 130 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) { |
| 131 | int cpu = smp_processor_id(); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 132 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 133 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 134 | tick_broadcast_clear_oneshot(cpu); |
| 135 | } |
| 136 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 137 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 138 | return ret; |
| 139 | } |
| 140 | |
Mark Rutland | 12572db | 2013-01-14 17:05:21 +0000 | [diff] [blame] | 141 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 142 | int tick_receive_broadcast(void) |
| 143 | { |
| 144 | struct tick_device *td = this_cpu_ptr(&tick_cpu_device); |
| 145 | struct clock_event_device *evt = td->evtdev; |
| 146 | |
| 147 | if (!evt) |
| 148 | return -ENODEV; |
| 149 | |
| 150 | if (!evt->event_handler) |
| 151 | return -EINVAL; |
| 152 | |
| 153 | evt->event_handler(evt); |
| 154 | return 0; |
| 155 | } |
| 156 | #endif |
| 157 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 158 | /* |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 159 | * Broadcast the event to the cpus, which are set in the mask (mangled). |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 160 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 161 | static void tick_do_broadcast(struct cpumask *mask) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 162 | { |
Thomas Gleixner | 186e3cb | 2008-01-30 13:30:01 +0100 | [diff] [blame] | 163 | int cpu = smp_processor_id(); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 164 | struct tick_device *td; |
| 165 | |
| 166 | /* |
| 167 | * Check, if the current cpu is in the mask |
| 168 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 169 | if (cpumask_test_cpu(cpu, mask)) { |
| 170 | cpumask_clear_cpu(cpu, mask); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 171 | td = &per_cpu(tick_cpu_device, cpu); |
| 172 | td->evtdev->event_handler(td->evtdev); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 175 | if (!cpumask_empty(mask)) { |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 176 | /* |
| 177 | * It might be necessary to actually check whether the devices |
| 178 | * have different broadcast functions. For now, just use the |
| 179 | * one of the first device. This works as long as we have this |
| 180 | * misfeature only on x86 (lapic) |
| 181 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 182 | td = &per_cpu(tick_cpu_device, cpumask_first(mask)); |
| 183 | td->evtdev->broadcast(mask); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 184 | } |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Periodic broadcast: |
| 189 | * - invoke the broadcast handlers |
| 190 | */ |
| 191 | static void tick_do_periodic_broadcast(void) |
| 192 | { |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 193 | raw_spin_lock(&tick_broadcast_lock); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 194 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 195 | cpumask_and(to_cpumask(tmpmask), |
| 196 | cpu_online_mask, tick_get_broadcast_mask()); |
| 197 | tick_do_broadcast(to_cpumask(tmpmask)); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 198 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 199 | raw_spin_unlock(&tick_broadcast_lock); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Event handler for periodic broadcast ticks |
| 204 | */ |
| 205 | static void tick_handle_periodic_broadcast(struct clock_event_device *dev) |
| 206 | { |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 207 | ktime_t next; |
| 208 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 209 | tick_do_periodic_broadcast(); |
| 210 | |
| 211 | /* |
| 212 | * The device is in periodic mode. No reprogramming necessary: |
| 213 | */ |
| 214 | if (dev->mode == CLOCK_EVT_MODE_PERIODIC) |
| 215 | return; |
| 216 | |
| 217 | /* |
| 218 | * Setup the next period for devices, which do not have |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 219 | * periodic mode. We read dev->next_event first and add to it |
Uwe Kleine-König | 698f931 | 2010-07-02 20:41:51 +0200 | [diff] [blame] | 220 | * when the event already expired. clockevents_program_event() |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 221 | * sets dev->next_event only when the event is really |
| 222 | * programmed to the device. |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 223 | */ |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 224 | for (next = dev->next_event; ;) { |
| 225 | next = ktime_add(next, tick_period); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 226 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 227 | if (!clockevents_program_event(dev, next, false)) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 228 | return; |
| 229 | tick_do_periodic_broadcast(); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Powerstate information: The system enters/leaves a state, where |
| 235 | * affected devices might stop |
| 236 | */ |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 237 | static void tick_do_broadcast_on_off(unsigned long *reason) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 238 | { |
| 239 | struct clock_event_device *bc, *dev; |
| 240 | struct tick_device *td; |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 241 | unsigned long flags; |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 242 | int cpu, bc_stopped; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 243 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 244 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 245 | |
| 246 | cpu = smp_processor_id(); |
| 247 | td = &per_cpu(tick_cpu_device, cpu); |
| 248 | dev = td->evtdev; |
| 249 | bc = tick_broadcast_device.evtdev; |
| 250 | |
| 251 | /* |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 252 | * Is the device not affected by the powerstate ? |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 253 | */ |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 254 | if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 255 | goto out; |
| 256 | |
Thomas Gleixner | 3dfbc88 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 257 | if (!tick_device_is_functional(dev)) |
| 258 | goto out; |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 259 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 260 | bc_stopped = cpumask_empty(tick_get_broadcast_mask()); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 261 | |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 262 | switch (*reason) { |
| 263 | case CLOCK_EVT_NOTIFY_BROADCAST_ON: |
| 264 | case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 265 | if (!cpumask_test_cpu(cpu, tick_get_broadcast_mask())) { |
| 266 | cpumask_set_cpu(cpu, tick_get_broadcast_mask()); |
Thomas Gleixner | 07454bf | 2008-10-04 10:51:07 +0200 | [diff] [blame] | 267 | if (tick_broadcast_device.mode == |
| 268 | TICKDEV_MODE_PERIODIC) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 269 | clockevents_shutdown(dev); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 270 | } |
Thomas Gleixner | 3dfbc88 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 271 | if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE) |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 272 | tick_broadcast_force = 1; |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 273 | break; |
| 274 | case CLOCK_EVT_NOTIFY_BROADCAST_OFF: |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 275 | if (!tick_broadcast_force && |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 276 | cpumask_test_cpu(cpu, tick_get_broadcast_mask())) { |
| 277 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); |
Thomas Gleixner | 07454bf | 2008-10-04 10:51:07 +0200 | [diff] [blame] | 278 | if (tick_broadcast_device.mode == |
| 279 | TICKDEV_MODE_PERIODIC) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 280 | tick_setup_periodic(dev, 0); |
| 281 | } |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 282 | break; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 285 | if (cpumask_empty(tick_get_broadcast_mask())) { |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 286 | if (!bc_stopped) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 287 | clockevents_shutdown(bc); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 288 | } else if (bc_stopped) { |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 289 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
| 290 | tick_broadcast_start_periodic(bc); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 291 | else |
| 292 | tick_broadcast_setup_oneshot(bc); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 293 | } |
| 294 | out: |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 295 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Powerstate information: The system enters/leaves a state, where |
| 300 | * affected devices might stop. |
| 301 | */ |
| 302 | void tick_broadcast_on_off(unsigned long reason, int *oncpu) |
| 303 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 304 | if (!cpumask_test_cpu(*oncpu, cpu_online_mask)) |
Glauber Costa | 833df31 | 2008-04-18 13:38:58 -0700 | [diff] [blame] | 305 | printk(KERN_ERR "tick-broadcast: ignoring broadcast for " |
Thomas Gleixner | 72fcde9 | 2007-05-23 13:57:30 -0700 | [diff] [blame] | 306 | "offline CPU #%d\n", *oncpu); |
Avi Kivity | bf020cb | 2007-10-16 23:26:24 -0700 | [diff] [blame] | 307 | else |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 308 | tick_do_broadcast_on_off(&reason); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* |
| 312 | * Set the periodic handler depending on broadcast on/off |
| 313 | */ |
| 314 | void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast) |
| 315 | { |
| 316 | if (!broadcast) |
| 317 | dev->event_handler = tick_handle_periodic; |
| 318 | else |
| 319 | dev->event_handler = tick_handle_periodic_broadcast; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Remove a CPU from broadcasting |
| 324 | */ |
| 325 | void tick_shutdown_broadcast(unsigned int *cpup) |
| 326 | { |
| 327 | struct clock_event_device *bc; |
| 328 | unsigned long flags; |
| 329 | unsigned int cpu = *cpup; |
| 330 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 331 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 332 | |
| 333 | bc = tick_broadcast_device.evtdev; |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 334 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 335 | |
| 336 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 337 | if (bc && cpumask_empty(tick_get_broadcast_mask())) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 338 | clockevents_shutdown(bc); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 341 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 342 | } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 343 | |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 344 | void tick_suspend_broadcast(void) |
| 345 | { |
| 346 | struct clock_event_device *bc; |
| 347 | unsigned long flags; |
| 348 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 349 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 350 | |
| 351 | bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 352 | if (bc) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 353 | clockevents_shutdown(bc); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 354 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 355 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | int tick_resume_broadcast(void) |
| 359 | { |
| 360 | struct clock_event_device *bc; |
| 361 | unsigned long flags; |
| 362 | int broadcast = 0; |
| 363 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 364 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 365 | |
| 366 | bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 367 | |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 368 | if (bc) { |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 369 | clockevents_set_mode(bc, CLOCK_EVT_MODE_RESUME); |
| 370 | |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 371 | switch (tick_broadcast_device.mode) { |
| 372 | case TICKDEV_MODE_PERIODIC: |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 373 | if (!cpumask_empty(tick_get_broadcast_mask())) |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 374 | tick_broadcast_start_periodic(bc); |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 375 | broadcast = cpumask_test_cpu(smp_processor_id(), |
| 376 | tick_get_broadcast_mask()); |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 377 | break; |
| 378 | case TICKDEV_MODE_ONESHOT: |
Suresh Siddha | a6371f8 | 2012-04-18 19:27:39 -0700 | [diff] [blame] | 379 | if (!cpumask_empty(tick_get_broadcast_mask())) |
| 380 | broadcast = tick_resume_broadcast_oneshot(bc); |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 381 | break; |
| 382 | } |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 383 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 384 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 385 | |
| 386 | return broadcast; |
| 387 | } |
| 388 | |
| 389 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 390 | #ifdef CONFIG_TICK_ONESHOT |
| 391 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 392 | /* FIXME: use cpumask_var_t. */ |
| 393 | static DECLARE_BITMAP(tick_broadcast_oneshot_mask, NR_CPUS); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 394 | |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 395 | /* |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 396 | * Exposed for debugging: see timer_list.c |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 397 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 398 | struct cpumask *tick_get_broadcast_oneshot_mask(void) |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 399 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 400 | return to_cpumask(tick_broadcast_oneshot_mask); |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 403 | static int tick_broadcast_set_event(ktime_t expires, int force) |
| 404 | { |
| 405 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 406 | |
Thomas Gleixner | b9a6a235 | 2012-04-18 17:31:58 +0200 | [diff] [blame] | 407 | if (bc->mode != CLOCK_EVT_MODE_ONESHOT) |
| 408 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); |
| 409 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 410 | return clockevents_program_event(bc, expires, force); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 413 | int tick_resume_broadcast_oneshot(struct clock_event_device *bc) |
| 414 | { |
| 415 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); |
Thomas Gleixner | b7e113d | 2007-09-22 22:29:06 +0000 | [diff] [blame] | 416 | return 0; |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 419 | /* |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 420 | * Called from irq_enter() when idle was interrupted to reenable the |
| 421 | * per cpu device. |
| 422 | */ |
| 423 | void tick_check_oneshot_broadcast(int cpu) |
| 424 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 425 | if (cpumask_test_cpu(cpu, to_cpumask(tick_broadcast_oneshot_mask))) { |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 426 | struct tick_device *td = &per_cpu(tick_cpu_device, cpu); |
| 427 | |
| 428 | clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_ONESHOT); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /* |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 433 | * Handle oneshot mode broadcasting |
| 434 | */ |
| 435 | static void tick_handle_oneshot_broadcast(struct clock_event_device *dev) |
| 436 | { |
| 437 | struct tick_device *td; |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 438 | ktime_t now, next_event; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 439 | int cpu; |
| 440 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 441 | raw_spin_lock(&tick_broadcast_lock); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 442 | again: |
| 443 | dev->next_event.tv64 = KTIME_MAX; |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 444 | next_event.tv64 = KTIME_MAX; |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 445 | cpumask_clear(to_cpumask(tmpmask)); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 446 | now = ktime_get(); |
| 447 | /* Find all expired events */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 448 | for_each_cpu(cpu, tick_get_broadcast_oneshot_mask()) { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 449 | td = &per_cpu(tick_cpu_device, cpu); |
| 450 | if (td->evtdev->next_event.tv64 <= now.tv64) |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 451 | cpumask_set_cpu(cpu, to_cpumask(tmpmask)); |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 452 | else if (td->evtdev->next_event.tv64 < next_event.tv64) |
| 453 | next_event.tv64 = td->evtdev->next_event.tv64; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 457 | * Wakeup the cpus which have an expired event. |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 458 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 459 | tick_do_broadcast(to_cpumask(tmpmask)); |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 460 | |
| 461 | /* |
| 462 | * Two reasons for reprogram: |
| 463 | * |
| 464 | * - The global event did not expire any CPU local |
| 465 | * events. This happens in dyntick mode, as the maximum PIT |
| 466 | * delta is quite small. |
| 467 | * |
| 468 | * - There are pending events on sleeping CPUs which were not |
| 469 | * in the event mask |
| 470 | */ |
| 471 | if (next_event.tv64 != KTIME_MAX) { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 472 | /* |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 473 | * Rearm the broadcast device. If event expired, |
| 474 | * repeat the above |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 475 | */ |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 476 | if (tick_broadcast_set_event(next_event, 0)) |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 477 | goto again; |
| 478 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 479 | raw_spin_unlock(&tick_broadcast_lock); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* |
| 483 | * Powerstate information: The system enters/leaves a state, where |
| 484 | * affected devices might stop |
| 485 | */ |
| 486 | void tick_broadcast_oneshot_control(unsigned long reason) |
| 487 | { |
| 488 | struct clock_event_device *bc, *dev; |
| 489 | struct tick_device *td; |
| 490 | unsigned long flags; |
| 491 | int cpu; |
| 492 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 493 | /* |
| 494 | * Periodic mode does not care about the enter/exit of power |
| 495 | * states |
| 496 | */ |
| 497 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 498 | return; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 499 | |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 500 | /* |
| 501 | * We are called with preemtion disabled from the depth of the |
| 502 | * idle code, so we can't be moved away. |
| 503 | */ |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 504 | cpu = smp_processor_id(); |
| 505 | td = &per_cpu(tick_cpu_device, cpu); |
| 506 | dev = td->evtdev; |
| 507 | |
| 508 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 509 | return; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 510 | |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 511 | bc = tick_broadcast_device.evtdev; |
| 512 | |
| 513 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 514 | if (reason == CLOCK_EVT_NOTIFY_BROADCAST_ENTER) { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 515 | if (!cpumask_test_cpu(cpu, tick_get_broadcast_oneshot_mask())) { |
| 516 | cpumask_set_cpu(cpu, tick_get_broadcast_oneshot_mask()); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 517 | clockevents_set_mode(dev, CLOCK_EVT_MODE_SHUTDOWN); |
| 518 | if (dev->next_event.tv64 < bc->next_event.tv64) |
| 519 | tick_broadcast_set_event(dev->next_event, 1); |
| 520 | } |
| 521 | } else { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 522 | if (cpumask_test_cpu(cpu, tick_get_broadcast_oneshot_mask())) { |
| 523 | cpumask_clear_cpu(cpu, |
| 524 | tick_get_broadcast_oneshot_mask()); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 525 | clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT); |
| 526 | if (dev->next_event.tv64 != KTIME_MAX) |
| 527 | tick_program_event(dev->next_event, 1); |
| 528 | } |
| 529 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 530 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Reset the one shot broadcast for a cpu |
| 535 | * |
| 536 | * Called with tick_broadcast_lock held |
| 537 | */ |
| 538 | static void tick_broadcast_clear_oneshot(int cpu) |
| 539 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 540 | cpumask_clear_cpu(cpu, tick_get_broadcast_oneshot_mask()); |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 543 | static void tick_broadcast_init_next_event(struct cpumask *mask, |
| 544 | ktime_t expires) |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 545 | { |
| 546 | struct tick_device *td; |
| 547 | int cpu; |
| 548 | |
Rusty Russell | 5db0e1e | 2009-01-01 10:12:29 +1030 | [diff] [blame] | 549 | for_each_cpu(cpu, mask) { |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 550 | td = &per_cpu(tick_cpu_device, cpu); |
| 551 | if (td->evtdev) |
| 552 | td->evtdev->next_event = expires; |
| 553 | } |
| 554 | } |
| 555 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 556 | /** |
Li Zefan | 8dce39c | 2007-11-05 14:51:10 -0800 | [diff] [blame] | 557 | * tick_broadcast_setup_oneshot - setup the broadcast device |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 558 | */ |
| 559 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
| 560 | { |
Thomas Gleixner | 07f4beb | 2011-05-16 11:07:48 +0200 | [diff] [blame] | 561 | int cpu = smp_processor_id(); |
| 562 | |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 563 | /* Set it up only once ! */ |
| 564 | if (bc->event_handler != tick_handle_oneshot_broadcast) { |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 565 | int was_periodic = bc->mode == CLOCK_EVT_MODE_PERIODIC; |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 566 | |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 567 | bc->event_handler = tick_handle_oneshot_broadcast; |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 568 | |
| 569 | /* Take the do_timer update */ |
| 570 | tick_do_timer_cpu = cpu; |
| 571 | |
| 572 | /* |
| 573 | * We must be careful here. There might be other CPUs |
| 574 | * waiting for periodic broadcast. We need to set the |
| 575 | * oneshot_mask bits for those and program the |
| 576 | * broadcast device to fire. |
| 577 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 578 | cpumask_copy(to_cpumask(tmpmask), tick_get_broadcast_mask()); |
| 579 | cpumask_clear_cpu(cpu, to_cpumask(tmpmask)); |
| 580 | cpumask_or(tick_get_broadcast_oneshot_mask(), |
| 581 | tick_get_broadcast_oneshot_mask(), |
| 582 | to_cpumask(tmpmask)); |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 583 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 584 | if (was_periodic && !cpumask_empty(to_cpumask(tmpmask))) { |
Thomas Gleixner | b435092 | 2012-04-18 12:08:23 +0200 | [diff] [blame] | 585 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 586 | tick_broadcast_init_next_event(to_cpumask(tmpmask), |
| 587 | tick_next_period); |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 588 | tick_broadcast_set_event(tick_next_period, 1); |
| 589 | } else |
| 590 | bc->next_event.tv64 = KTIME_MAX; |
Thomas Gleixner | 07f4beb | 2011-05-16 11:07:48 +0200 | [diff] [blame] | 591 | } else { |
| 592 | /* |
| 593 | * The first cpu which switches to oneshot mode sets |
| 594 | * the bit for all other cpus which are in the general |
| 595 | * (periodic) broadcast mask. So the bit is set and |
| 596 | * would prevent the first broadcast enter after this |
| 597 | * to program the bc device. |
| 598 | */ |
| 599 | tick_broadcast_clear_oneshot(cpu); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 600 | } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /* |
| 604 | * Select oneshot operating mode for the broadcast device |
| 605 | */ |
| 606 | void tick_broadcast_switch_to_oneshot(void) |
| 607 | { |
| 608 | struct clock_event_device *bc; |
| 609 | unsigned long flags; |
| 610 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 611 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Suresh Siddha | fa4da36 | 2012-04-09 15:41:44 -0700 | [diff] [blame] | 612 | |
| 613 | tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 614 | bc = tick_broadcast_device.evtdev; |
| 615 | if (bc) |
| 616 | tick_broadcast_setup_oneshot(bc); |
Suresh Siddha | 77b0d60 | 2011-11-04 17:18:21 -0700 | [diff] [blame] | 617 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 618 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | |
| 622 | /* |
| 623 | * Remove a dead CPU from broadcasting |
| 624 | */ |
| 625 | void tick_shutdown_broadcast_oneshot(unsigned int *cpup) |
| 626 | { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 627 | unsigned long flags; |
| 628 | unsigned int cpu = *cpup; |
| 629 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 630 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 631 | |
Thomas Gleixner | 31d9b39 | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 632 | /* |
| 633 | * Clear the broadcast mask flag for the dead cpu, but do not |
| 634 | * stop the broadcast device! |
| 635 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 636 | cpumask_clear_cpu(cpu, tick_get_broadcast_oneshot_mask()); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 637 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 638 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Thomas Gleixner | 27ce4cb | 2008-09-22 19:04:02 +0200 | [diff] [blame] | 641 | /* |
| 642 | * Check, whether the broadcast device is in one shot mode |
| 643 | */ |
| 644 | int tick_broadcast_oneshot_active(void) |
| 645 | { |
| 646 | return tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT; |
| 647 | } |
| 648 | |
Thomas Gleixner | 3a142a0 | 2011-02-25 22:34:23 +0100 | [diff] [blame] | 649 | /* |
| 650 | * Check whether the broadcast device supports oneshot. |
| 651 | */ |
| 652 | bool tick_broadcast_oneshot_available(void) |
| 653 | { |
| 654 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
| 655 | |
| 656 | return bc ? bc->features & CLOCK_EVT_FEAT_ONESHOT : false; |
| 657 | } |
| 658 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 659 | #endif |