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 | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 22 | #include <linux/module.h> |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 23 | |
| 24 | #include "tick-internal.h" |
| 25 | |
| 26 | /* |
| 27 | * Broadcast support for broken x86 hardware, where the local apic |
| 28 | * timer stops in C3 state. |
| 29 | */ |
| 30 | |
Dmitri Vorobiev | a52f5c5 | 2009-05-01 13:10:21 -0700 | [diff] [blame] | 31 | static struct tick_device tick_broadcast_device; |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 32 | static cpumask_var_t tick_broadcast_mask; |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 33 | static cpumask_var_t tick_broadcast_on; |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 34 | static cpumask_var_t tmpmask; |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 35 | static DEFINE_RAW_SPINLOCK(tick_broadcast_lock); |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 36 | static int tick_broadcast_force; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 37 | |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_TICK_ONESHOT |
| 39 | static void tick_broadcast_clear_oneshot(int cpu); |
Thomas Gleixner | 080873c | 2015-03-25 13:09:55 +0100 | [diff] [blame^] | 40 | static void tick_resume_broadcast_oneshot(struct clock_event_device *bc); |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 41 | #else |
| 42 | static inline void tick_broadcast_clear_oneshot(int cpu) { } |
Thomas Gleixner | 080873c | 2015-03-25 13:09:55 +0100 | [diff] [blame^] | 43 | static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { } |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 46 | /* |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 47 | * Debugging: see timer_list.c |
| 48 | */ |
| 49 | struct tick_device *tick_get_broadcast_device(void) |
| 50 | { |
| 51 | return &tick_broadcast_device; |
| 52 | } |
| 53 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 54 | struct cpumask *tick_get_broadcast_mask(void) |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 55 | { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 56 | return tick_broadcast_mask; |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 60 | * Start the device in periodic mode |
| 61 | */ |
| 62 | static void tick_broadcast_start_periodic(struct clock_event_device *bc) |
| 63 | { |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 64 | if (bc) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 65 | tick_setup_periodic(bc, 1); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Check, if the device can be utilized as broadcast device: |
| 70 | */ |
Thomas Gleixner | 45cb8e0 | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 71 | static bool tick_check_broadcast_device(struct clock_event_device *curdev, |
| 72 | struct clock_event_device *newdev) |
| 73 | { |
| 74 | if ((newdev->features & CLOCK_EVT_FEAT_DUMMY) || |
Soren Brinkmann | 245a349 | 2013-09-18 11:48:37 -0700 | [diff] [blame] | 75 | (newdev->features & CLOCK_EVT_FEAT_PERCPU) || |
Thomas Gleixner | 45cb8e0 | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 76 | (newdev->features & CLOCK_EVT_FEAT_C3STOP)) |
| 77 | return false; |
| 78 | |
| 79 | if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT && |
| 80 | !(newdev->features & CLOCK_EVT_FEAT_ONESHOT)) |
| 81 | return false; |
| 82 | |
| 83 | return !curdev || newdev->rating > curdev->rating; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Conditionally install/replace broadcast device |
| 88 | */ |
Thomas Gleixner | 7172a28 | 2013-04-25 20:31:47 +0000 | [diff] [blame] | 89 | void tick_install_broadcast_device(struct clock_event_device *dev) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 90 | { |
Thomas Gleixner | 6f7a05d | 2013-04-25 11:45:53 +0200 | [diff] [blame] | 91 | struct clock_event_device *cur = tick_broadcast_device.evtdev; |
| 92 | |
Thomas Gleixner | 45cb8e0 | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 93 | if (!tick_check_broadcast_device(cur, dev)) |
Thomas Gleixner | 7172a28 | 2013-04-25 20:31:47 +0000 | [diff] [blame] | 94 | return; |
Thomas Gleixner | 45cb8e0 | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 95 | |
Thomas Gleixner | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 96 | if (!try_module_get(dev->owner)) |
| 97 | return; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 98 | |
Thomas Gleixner | 45cb8e0 | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 99 | clockevents_exchange_device(cur, dev); |
Thomas Gleixner | 6f7a05d | 2013-04-25 11:45:53 +0200 | [diff] [blame] | 100 | if (cur) |
| 101 | cur->event_handler = clockevents_handle_noop; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 102 | tick_broadcast_device.evtdev = dev; |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 103 | if (!cpumask_empty(tick_broadcast_mask)) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 104 | tick_broadcast_start_periodic(dev); |
Stephen Boyd | c038c1c | 2013-04-17 10:26:06 -0700 | [diff] [blame] | 105 | /* |
| 106 | * Inform all cpus about this. We might be in a situation |
| 107 | * where we did not switch to oneshot mode because the per cpu |
| 108 | * devices are affected by CLOCK_EVT_FEAT_C3STOP and the lack |
| 109 | * of a oneshot capable broadcast device. Without that |
| 110 | * notification the systems stays stuck in periodic mode |
| 111 | * forever. |
| 112 | */ |
| 113 | if (dev->features & CLOCK_EVT_FEAT_ONESHOT) |
| 114 | tick_clock_notify(); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Check, if the device is the broadcast device |
| 119 | */ |
| 120 | int tick_is_broadcast_device(struct clock_event_device *dev) |
| 121 | { |
| 122 | return (dev && tick_broadcast_device.evtdev == dev); |
| 123 | } |
| 124 | |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 125 | int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) |
| 126 | { |
| 127 | int ret = -ENODEV; |
| 128 | |
| 129 | if (tick_is_broadcast_device(dev)) { |
| 130 | raw_spin_lock(&tick_broadcast_lock); |
| 131 | ret = __clockevents_update_freq(dev, freq); |
| 132 | raw_spin_unlock(&tick_broadcast_lock); |
| 133 | } |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | |
Mark Rutland | 12ad100 | 2013-01-14 17:05:22 +0000 | [diff] [blame] | 138 | static void err_broadcast(const struct cpumask *mask) |
| 139 | { |
| 140 | pr_crit_once("Failed to broadcast timer tick. Some CPUs may be unresponsive.\n"); |
| 141 | } |
| 142 | |
Mark Rutland | 5d1d9a2 | 2013-02-08 15:24:07 +0000 | [diff] [blame] | 143 | static void tick_device_setup_broadcast_func(struct clock_event_device *dev) |
| 144 | { |
| 145 | if (!dev->broadcast) |
| 146 | dev->broadcast = tick_broadcast; |
| 147 | if (!dev->broadcast) { |
| 148 | pr_warn_once("%s depends on broadcast, but no broadcast function available\n", |
| 149 | dev->name); |
| 150 | dev->broadcast = err_broadcast; |
| 151 | } |
| 152 | } |
| 153 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 154 | /* |
| 155 | * Check, if the device is disfunctional and a place holder, which |
| 156 | * needs to be handled by the broadcast device. |
| 157 | */ |
| 158 | int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) |
| 159 | { |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 160 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 161 | unsigned long flags; |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 162 | int ret; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 163 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 164 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * Devices might be registered with both periodic and oneshot |
| 168 | * mode disabled. This signals, that the device needs to be |
| 169 | * operated from the broadcast device and is a placeholder for |
| 170 | * the cpu local device. |
| 171 | */ |
| 172 | if (!tick_device_is_functional(dev)) { |
| 173 | dev->event_handler = tick_handle_periodic; |
Mark Rutland | 5d1d9a2 | 2013-02-08 15:24:07 +0000 | [diff] [blame] | 174 | tick_device_setup_broadcast_func(dev); |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 175 | cpumask_set_cpu(cpu, tick_broadcast_mask); |
Stephen Boyd | a272dcc | 2013-07-11 07:00:59 -0700 | [diff] [blame] | 176 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
| 177 | tick_broadcast_start_periodic(bc); |
| 178 | else |
| 179 | tick_broadcast_setup_oneshot(bc); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 180 | ret = 1; |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 181 | } else { |
| 182 | /* |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 183 | * Clear the broadcast bit for this cpu if the |
| 184 | * device is not power state affected. |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 185 | */ |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 186 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 187 | cpumask_clear_cpu(cpu, tick_broadcast_mask); |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 188 | else |
Mark Rutland | 5d1d9a2 | 2013-02-08 15:24:07 +0000 | [diff] [blame] | 189 | tick_device_setup_broadcast_func(dev); |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Clear the broadcast bit if the CPU is not in |
| 193 | * periodic broadcast on state. |
| 194 | */ |
| 195 | if (!cpumask_test_cpu(cpu, tick_broadcast_on)) |
| 196 | cpumask_clear_cpu(cpu, tick_broadcast_mask); |
| 197 | |
| 198 | switch (tick_broadcast_device.mode) { |
| 199 | case TICKDEV_MODE_ONESHOT: |
| 200 | /* |
| 201 | * If the system is in oneshot mode we can |
| 202 | * unconditionally clear the oneshot mask bit, |
| 203 | * because the CPU is running and therefore |
| 204 | * not in an idle state which causes the power |
| 205 | * state affected device to stop. Let the |
| 206 | * caller initialize the device. |
| 207 | */ |
| 208 | tick_broadcast_clear_oneshot(cpu); |
| 209 | ret = 0; |
| 210 | break; |
| 211 | |
| 212 | case TICKDEV_MODE_PERIODIC: |
| 213 | /* |
| 214 | * If the system is in periodic mode, check |
| 215 | * whether the broadcast device can be |
| 216 | * switched off now. |
| 217 | */ |
| 218 | if (cpumask_empty(tick_broadcast_mask) && bc) |
| 219 | clockevents_shutdown(bc); |
| 220 | /* |
| 221 | * If we kept the cpu in the broadcast mask, |
| 222 | * tell the caller to leave the per cpu device |
| 223 | * in shutdown state. The periodic interrupt |
| 224 | * is delivered by the broadcast device. |
| 225 | */ |
| 226 | ret = cpumask_test_cpu(cpu, tick_broadcast_mask); |
| 227 | break; |
| 228 | default: |
| 229 | /* Nothing to do */ |
| 230 | ret = 0; |
| 231 | break; |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 234 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 235 | return ret; |
| 236 | } |
| 237 | |
Mark Rutland | 12572db | 2013-01-14 17:05:21 +0000 | [diff] [blame] | 238 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 239 | int tick_receive_broadcast(void) |
| 240 | { |
| 241 | struct tick_device *td = this_cpu_ptr(&tick_cpu_device); |
| 242 | struct clock_event_device *evt = td->evtdev; |
| 243 | |
| 244 | if (!evt) |
| 245 | return -ENODEV; |
| 246 | |
| 247 | if (!evt->event_handler) |
| 248 | return -EINVAL; |
| 249 | |
| 250 | evt->event_handler(evt); |
| 251 | return 0; |
| 252 | } |
| 253 | #endif |
| 254 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 255 | /* |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 256 | * 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] | 257 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 258 | static void tick_do_broadcast(struct cpumask *mask) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 259 | { |
Thomas Gleixner | 186e3cb | 2008-01-30 13:30:01 +0100 | [diff] [blame] | 260 | int cpu = smp_processor_id(); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 261 | struct tick_device *td; |
| 262 | |
| 263 | /* |
| 264 | * Check, if the current cpu is in the mask |
| 265 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 266 | if (cpumask_test_cpu(cpu, mask)) { |
| 267 | cpumask_clear_cpu(cpu, mask); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 268 | td = &per_cpu(tick_cpu_device, cpu); |
| 269 | td->evtdev->event_handler(td->evtdev); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 272 | if (!cpumask_empty(mask)) { |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 273 | /* |
| 274 | * It might be necessary to actually check whether the devices |
| 275 | * have different broadcast functions. For now, just use the |
| 276 | * one of the first device. This works as long as we have this |
| 277 | * misfeature only on x86 (lapic) |
| 278 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 279 | td = &per_cpu(tick_cpu_device, cpumask_first(mask)); |
| 280 | td->evtdev->broadcast(mask); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 281 | } |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Periodic broadcast: |
| 286 | * - invoke the broadcast handlers |
| 287 | */ |
| 288 | static void tick_do_periodic_broadcast(void) |
| 289 | { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 290 | cpumask_and(tmpmask, cpu_online_mask, tick_broadcast_mask); |
| 291 | tick_do_broadcast(tmpmask); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Event handler for periodic broadcast ticks |
| 296 | */ |
| 297 | static void tick_handle_periodic_broadcast(struct clock_event_device *dev) |
| 298 | { |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 299 | ktime_t next; |
| 300 | |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 301 | raw_spin_lock(&tick_broadcast_lock); |
| 302 | |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 303 | tick_do_periodic_broadcast(); |
| 304 | |
| 305 | /* |
| 306 | * The device is in periodic mode. No reprogramming necessary: |
| 307 | */ |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 308 | if (dev->state == CLOCK_EVT_STATE_PERIODIC) |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 309 | goto unlock; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * Setup the next period for devices, which do not have |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 313 | * 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] | 314 | * when the event already expired. clockevents_program_event() |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 315 | * sets dev->next_event only when the event is really |
| 316 | * programmed to the device. |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 317 | */ |
Thomas Gleixner | d4496b3 | 2008-09-03 21:36:57 +0000 | [diff] [blame] | 318 | for (next = dev->next_event; ;) { |
| 319 | next = ktime_add(next, tick_period); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 320 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 321 | if (!clockevents_program_event(dev, next, false)) |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 322 | goto unlock; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 323 | tick_do_periodic_broadcast(); |
| 324 | } |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 325 | unlock: |
| 326 | raw_spin_unlock(&tick_broadcast_lock); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Powerstate information: The system enters/leaves a state, where |
| 331 | * affected devices might stop |
| 332 | */ |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 333 | static void tick_do_broadcast_on_off(unsigned long *reason) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 334 | { |
| 335 | struct clock_event_device *bc, *dev; |
| 336 | struct tick_device *td; |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 337 | unsigned long flags; |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 338 | int cpu, bc_stopped; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 339 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 340 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 341 | |
| 342 | cpu = smp_processor_id(); |
| 343 | td = &per_cpu(tick_cpu_device, cpu); |
| 344 | dev = td->evtdev; |
| 345 | bc = tick_broadcast_device.evtdev; |
| 346 | |
| 347 | /* |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 348 | * Is the device not affected by the powerstate ? |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 349 | */ |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 350 | if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 351 | goto out; |
| 352 | |
Thomas Gleixner | 3dfbc88 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 353 | if (!tick_device_is_functional(dev)) |
| 354 | goto out; |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 355 | |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 356 | bc_stopped = cpumask_empty(tick_broadcast_mask); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 357 | |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 358 | switch (*reason) { |
| 359 | case CLOCK_EVT_NOTIFY_BROADCAST_ON: |
| 360 | case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 361 | cpumask_set_cpu(cpu, tick_broadcast_on); |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 362 | if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_mask)) { |
Thomas Gleixner | 07454bf | 2008-10-04 10:51:07 +0200 | [diff] [blame] | 363 | if (tick_broadcast_device.mode == |
| 364 | TICKDEV_MODE_PERIODIC) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 365 | clockevents_shutdown(dev); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 366 | } |
Thomas Gleixner | 3dfbc88 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 367 | if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE) |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 368 | tick_broadcast_force = 1; |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 369 | break; |
| 370 | case CLOCK_EVT_NOTIFY_BROADCAST_OFF: |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 371 | if (tick_broadcast_force) |
| 372 | break; |
| 373 | cpumask_clear_cpu(cpu, tick_broadcast_on); |
| 374 | if (!tick_device_is_functional(dev)) |
| 375 | break; |
| 376 | if (cpumask_test_and_clear_cpu(cpu, tick_broadcast_mask)) { |
Thomas Gleixner | 07454bf | 2008-10-04 10:51:07 +0200 | [diff] [blame] | 377 | if (tick_broadcast_device.mode == |
| 378 | TICKDEV_MODE_PERIODIC) |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 379 | tick_setup_periodic(dev, 0); |
| 380 | } |
Thomas Gleixner | 1595f45 | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 381 | break; |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 384 | if (cpumask_empty(tick_broadcast_mask)) { |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 385 | if (!bc_stopped) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 386 | clockevents_shutdown(bc); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 387 | } else if (bc_stopped) { |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 388 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
| 389 | tick_broadcast_start_periodic(bc); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 390 | else |
| 391 | tick_broadcast_setup_oneshot(bc); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 392 | } |
| 393 | out: |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 394 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* |
| 398 | * Powerstate information: The system enters/leaves a state, where |
| 399 | * affected devices might stop. |
| 400 | */ |
| 401 | void tick_broadcast_on_off(unsigned long reason, int *oncpu) |
| 402 | { |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 403 | if (!cpumask_test_cpu(*oncpu, cpu_online_mask)) |
Glauber Costa | 833df31 | 2008-04-18 13:38:58 -0700 | [diff] [blame] | 404 | printk(KERN_ERR "tick-broadcast: ignoring broadcast for " |
Thomas Gleixner | 72fcde9 | 2007-05-23 13:57:30 -0700 | [diff] [blame] | 405 | "offline CPU #%d\n", *oncpu); |
Avi Kivity | bf020cb | 2007-10-16 23:26:24 -0700 | [diff] [blame] | 406 | else |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 407 | tick_do_broadcast_on_off(&reason); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* |
| 411 | * Set the periodic handler depending on broadcast on/off |
| 412 | */ |
| 413 | void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast) |
| 414 | { |
| 415 | if (!broadcast) |
| 416 | dev->event_handler = tick_handle_periodic; |
| 417 | else |
| 418 | dev->event_handler = tick_handle_periodic_broadcast; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Remove a CPU from broadcasting |
| 423 | */ |
| 424 | void tick_shutdown_broadcast(unsigned int *cpup) |
| 425 | { |
| 426 | struct clock_event_device *bc; |
| 427 | unsigned long flags; |
| 428 | unsigned int cpu = *cpup; |
| 429 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 430 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 431 | |
| 432 | bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 433 | cpumask_clear_cpu(cpu, tick_broadcast_mask); |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 434 | cpumask_clear_cpu(cpu, tick_broadcast_on); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 435 | |
| 436 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 437 | if (bc && cpumask_empty(tick_broadcast_mask)) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 438 | clockevents_shutdown(bc); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 441 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | f8381cb | 2007-02-16 01:28:02 -0800 | [diff] [blame] | 442 | } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 443 | |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 444 | void tick_suspend_broadcast(void) |
| 445 | { |
| 446 | struct clock_event_device *bc; |
| 447 | unsigned long flags; |
| 448 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 449 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 450 | |
| 451 | bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 452 | if (bc) |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 453 | clockevents_shutdown(bc); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 454 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 455 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | int tick_resume_broadcast(void) |
| 459 | { |
| 460 | struct clock_event_device *bc; |
| 461 | unsigned long flags; |
| 462 | int broadcast = 0; |
| 463 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 464 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 465 | |
| 466 | bc = tick_broadcast_device.evtdev; |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 467 | |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 468 | if (bc) { |
Viresh Kumar | 554ef38 | 2015-02-27 17:21:32 +0530 | [diff] [blame] | 469 | clockevents_tick_resume(bc); |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 470 | |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 471 | switch (tick_broadcast_device.mode) { |
| 472 | case TICKDEV_MODE_PERIODIC: |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 473 | if (!cpumask_empty(tick_broadcast_mask)) |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 474 | tick_broadcast_start_periodic(bc); |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 475 | broadcast = cpumask_test_cpu(smp_processor_id(), |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 476 | tick_broadcast_mask); |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 477 | break; |
| 478 | case TICKDEV_MODE_ONESHOT: |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 479 | if (!cpumask_empty(tick_broadcast_mask)) |
Thomas Gleixner | 080873c | 2015-03-25 13:09:55 +0100 | [diff] [blame^] | 480 | tick_resume_broadcast_oneshot(bc); |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 481 | break; |
| 482 | } |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 483 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 484 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 6321dd6 | 2007-03-06 08:25:42 +0100 | [diff] [blame] | 485 | |
| 486 | return broadcast; |
| 487 | } |
| 488 | |
| 489 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 490 | #ifdef CONFIG_TICK_ONESHOT |
| 491 | |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 492 | static cpumask_var_t tick_broadcast_oneshot_mask; |
Thomas Gleixner | 26517f3 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 493 | static cpumask_var_t tick_broadcast_pending_mask; |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 494 | static cpumask_var_t tick_broadcast_force_mask; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 495 | |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 496 | /* |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 497 | * Exposed for debugging: see timer_list.c |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 498 | */ |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 499 | struct cpumask *tick_get_broadcast_oneshot_mask(void) |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 500 | { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 501 | return tick_broadcast_oneshot_mask; |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 504 | /* |
Thomas Gleixner | eaa907c | 2013-03-06 11:18:36 +0000 | [diff] [blame] | 505 | * Called before going idle with interrupts disabled. Checks whether a |
| 506 | * broadcast event from the other core is about to happen. We detected |
| 507 | * that in tick_broadcast_oneshot_control(). The callsite can use this |
| 508 | * to avoid a deep idle transition as we are about to get the |
| 509 | * broadcast IPI right away. |
| 510 | */ |
| 511 | int tick_check_broadcast_expired(void) |
| 512 | { |
| 513 | return cpumask_test_cpu(smp_processor_id(), tick_broadcast_force_mask); |
| 514 | } |
| 515 | |
| 516 | /* |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 517 | * Set broadcast interrupt affinity |
| 518 | */ |
| 519 | static void tick_broadcast_set_affinity(struct clock_event_device *bc, |
| 520 | const struct cpumask *cpumask) |
| 521 | { |
| 522 | if (!(bc->features & CLOCK_EVT_FEAT_DYNIRQ)) |
| 523 | return; |
| 524 | |
| 525 | if (cpumask_equal(bc->cpumask, cpumask)) |
| 526 | return; |
| 527 | |
| 528 | bc->cpumask = cpumask; |
| 529 | irq_set_affinity(bc->irq, bc->cpumask); |
| 530 | } |
| 531 | |
| 532 | static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu, |
Daniel Lezcano | f9ae39d | 2013-03-02 11:10:10 +0100 | [diff] [blame] | 533 | ktime_t expires, int force) |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 534 | { |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 535 | int ret; |
| 536 | |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 537 | if (bc->state != CLOCK_EVT_STATE_ONESHOT) |
| 538 | clockevents_set_state(bc, CLOCK_EVT_STATE_ONESHOT); |
Thomas Gleixner | b9a6a235 | 2012-04-18 17:31:58 +0200 | [diff] [blame] | 539 | |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 540 | ret = clockevents_program_event(bc, expires, force); |
| 541 | if (!ret) |
| 542 | tick_broadcast_set_affinity(bc, cpumask_of(cpu)); |
| 543 | return ret; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Thomas Gleixner | 080873c | 2015-03-25 13:09:55 +0100 | [diff] [blame^] | 546 | static void tick_resume_broadcast_oneshot(struct clock_event_device *bc) |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 547 | { |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 548 | clockevents_set_state(bc, CLOCK_EVT_STATE_ONESHOT); |
Thomas Gleixner | cd05a1f | 2007-03-17 00:25:52 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 551 | /* |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 552 | * Called from irq_enter() when idle was interrupted to reenable the |
| 553 | * per cpu device. |
| 554 | */ |
Frederic Weisbecker | e8fcaa5 | 2013-08-07 22:28:01 +0200 | [diff] [blame] | 555 | void tick_check_oneshot_broadcast_this_cpu(void) |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 556 | { |
Frederic Weisbecker | e8fcaa5 | 2013-08-07 22:28:01 +0200 | [diff] [blame] | 557 | if (cpumask_test_cpu(smp_processor_id(), tick_broadcast_oneshot_mask)) { |
Christoph Lameter | 22127e9 | 2014-08-17 12:30:25 -0500 | [diff] [blame] | 558 | struct tick_device *td = this_cpu_ptr(&tick_cpu_device); |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 559 | |
Thomas Gleixner | 1f73a98 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 560 | /* |
| 561 | * We might be in the middle of switching over from |
| 562 | * periodic to oneshot. If the CPU has not yet |
| 563 | * switched over, leave the device alone. |
| 564 | */ |
| 565 | if (td->mode == TICKDEV_MODE_ONESHOT) { |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 566 | clockevents_set_state(td->evtdev, |
| 567 | CLOCK_EVT_STATE_ONESHOT); |
Thomas Gleixner | 1f73a98 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 568 | } |
Thomas Gleixner | fb02fbc | 2008-10-17 10:01:23 +0200 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | /* |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 573 | * Handle oneshot mode broadcasting |
| 574 | */ |
| 575 | static void tick_handle_oneshot_broadcast(struct clock_event_device *dev) |
| 576 | { |
| 577 | struct tick_device *td; |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 578 | ktime_t now, next_event; |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 579 | int cpu, next_cpu = 0; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 580 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 581 | raw_spin_lock(&tick_broadcast_lock); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 582 | again: |
| 583 | dev->next_event.tv64 = KTIME_MAX; |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 584 | next_event.tv64 = KTIME_MAX; |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 585 | cpumask_clear(tmpmask); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 586 | now = ktime_get(); |
| 587 | /* Find all expired events */ |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 588 | for_each_cpu(cpu, tick_broadcast_oneshot_mask) { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 589 | td = &per_cpu(tick_cpu_device, cpu); |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 590 | if (td->evtdev->next_event.tv64 <= now.tv64) { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 591 | cpumask_set_cpu(cpu, tmpmask); |
Thomas Gleixner | 26517f3 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 592 | /* |
| 593 | * Mark the remote cpu in the pending mask, so |
| 594 | * it can avoid reprogramming the cpu local |
| 595 | * timer in tick_broadcast_oneshot_control(). |
| 596 | */ |
| 597 | cpumask_set_cpu(cpu, tick_broadcast_pending_mask); |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 598 | } else if (td->evtdev->next_event.tv64 < next_event.tv64) { |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 599 | next_event.tv64 = td->evtdev->next_event.tv64; |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 600 | next_cpu = cpu; |
| 601 | } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 602 | } |
| 603 | |
Thomas Gleixner | 2938d27 | 2013-05-28 09:33:01 +0200 | [diff] [blame] | 604 | /* |
| 605 | * Remove the current cpu from the pending mask. The event is |
| 606 | * delivered immediately in tick_do_broadcast() ! |
| 607 | */ |
| 608 | cpumask_clear_cpu(smp_processor_id(), tick_broadcast_pending_mask); |
| 609 | |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 610 | /* Take care of enforced broadcast requests */ |
| 611 | cpumask_or(tmpmask, tmpmask, tick_broadcast_force_mask); |
| 612 | cpumask_clear(tick_broadcast_force_mask); |
| 613 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 614 | /* |
Thomas Gleixner | c9b5a26 | 2013-06-26 12:17:32 +0200 | [diff] [blame] | 615 | * Sanity check. Catch the case where we try to broadcast to |
| 616 | * offline cpus. |
| 617 | */ |
| 618 | if (WARN_ON_ONCE(!cpumask_subset(tmpmask, cpu_online_mask))) |
| 619 | cpumask_and(tmpmask, tmpmask, cpu_online_mask); |
| 620 | |
| 621 | /* |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 622 | * Wakeup the cpus which have an expired event. |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 623 | */ |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 624 | tick_do_broadcast(tmpmask); |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * Two reasons for reprogram: |
| 628 | * |
| 629 | * - The global event did not expire any CPU local |
| 630 | * events. This happens in dyntick mode, as the maximum PIT |
| 631 | * delta is quite small. |
| 632 | * |
| 633 | * - There are pending events on sleeping CPUs which were not |
| 634 | * in the event mask |
| 635 | */ |
| 636 | if (next_event.tv64 != KTIME_MAX) { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 637 | /* |
Thomas Gleixner | cdc6f27 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 638 | * Rearm the broadcast device. If event expired, |
| 639 | * repeat the above |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 640 | */ |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 641 | if (tick_broadcast_set_event(dev, next_cpu, next_event, 0)) |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 642 | goto again; |
| 643 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 644 | raw_spin_unlock(&tick_broadcast_lock); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 645 | } |
| 646 | |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 647 | static int broadcast_needs_cpu(struct clock_event_device *bc, int cpu) |
| 648 | { |
| 649 | if (!(bc->features & CLOCK_EVT_FEAT_HRTIMER)) |
| 650 | return 0; |
| 651 | if (bc->next_event.tv64 == KTIME_MAX) |
| 652 | return 0; |
| 653 | return bc->bound_on == cpu ? -EBUSY : 0; |
| 654 | } |
| 655 | |
| 656 | static void broadcast_shutdown_local(struct clock_event_device *bc, |
| 657 | struct clock_event_device *dev) |
| 658 | { |
| 659 | /* |
| 660 | * For hrtimer based broadcasting we cannot shutdown the cpu |
| 661 | * local device if our own event is the first one to expire or |
| 662 | * if we own the broadcast timer. |
| 663 | */ |
| 664 | if (bc->features & CLOCK_EVT_FEAT_HRTIMER) { |
| 665 | if (broadcast_needs_cpu(bc, smp_processor_id())) |
| 666 | return; |
| 667 | if (dev->next_event.tv64 < bc->next_event.tv64) |
| 668 | return; |
| 669 | } |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 670 | clockevents_set_state(dev, CLOCK_EVT_STATE_SHUTDOWN); |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | static void broadcast_move_bc(int deadcpu) |
| 674 | { |
| 675 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
| 676 | |
| 677 | if (!bc || !broadcast_needs_cpu(bc, deadcpu)) |
| 678 | return; |
| 679 | /* This moves the broadcast assignment to this cpu */ |
| 680 | clockevents_program_event(bc, bc->next_event, 1); |
| 681 | } |
| 682 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 683 | /* |
| 684 | * Powerstate information: The system enters/leaves a state, where |
| 685 | * affected devices might stop |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 686 | * Returns 0 on success, -EBUSY if the cpu is used to broadcast wakeups. |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 687 | */ |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 688 | int tick_broadcast_oneshot_control(unsigned long reason) |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 689 | { |
| 690 | struct clock_event_device *bc, *dev; |
| 691 | struct tick_device *td; |
| 692 | unsigned long flags; |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 693 | ktime_t now; |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 694 | int cpu, ret = 0; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 695 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 696 | /* |
| 697 | * Periodic mode does not care about the enter/exit of power |
| 698 | * states |
| 699 | */ |
| 700 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 701 | return 0; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 702 | |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 703 | /* |
| 704 | * We are called with preemtion disabled from the depth of the |
| 705 | * idle code, so we can't be moved away. |
| 706 | */ |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 707 | cpu = smp_processor_id(); |
| 708 | td = &per_cpu(tick_cpu_device, cpu); |
| 709 | dev = td->evtdev; |
| 710 | |
| 711 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 712 | return 0; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 713 | |
Andi Kleen | 7372b0b | 2011-05-04 15:09:27 -0700 | [diff] [blame] | 714 | bc = tick_broadcast_device.evtdev; |
| 715 | |
| 716 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 717 | if (reason == CLOCK_EVT_NOTIFY_BROADCAST_ENTER) { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 718 | if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) { |
Thomas Gleixner | 2938d27 | 2013-05-28 09:33:01 +0200 | [diff] [blame] | 719 | WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask)); |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 720 | broadcast_shutdown_local(bc, dev); |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 721 | /* |
| 722 | * We only reprogram the broadcast timer if we |
| 723 | * did not mark ourself in the force mask and |
| 724 | * if the cpu local event is earlier than the |
| 725 | * broadcast event. If the current CPU is in |
| 726 | * the force mask, then we are going to be |
| 727 | * woken by the IPI right away. |
| 728 | */ |
| 729 | if (!cpumask_test_cpu(cpu, tick_broadcast_force_mask) && |
| 730 | dev->next_event.tv64 < bc->next_event.tv64) |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 731 | tick_broadcast_set_event(bc, cpu, dev->next_event, 1); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 732 | } |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 733 | /* |
| 734 | * If the current CPU owns the hrtimer broadcast |
| 735 | * mechanism, it cannot go deep idle and we remove the |
| 736 | * CPU from the broadcast mask. We don't have to go |
| 737 | * through the EXIT path as the local timer is not |
| 738 | * shutdown. |
| 739 | */ |
| 740 | ret = broadcast_needs_cpu(bc, cpu); |
| 741 | if (ret) |
| 742 | cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 743 | } else { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 744 | if (cpumask_test_and_clear_cpu(cpu, tick_broadcast_oneshot_mask)) { |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 745 | clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT); |
Thomas Gleixner | 26517f3 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 746 | /* |
| 747 | * The cpu which was handling the broadcast |
| 748 | * timer marked this cpu in the broadcast |
| 749 | * pending mask and fired the broadcast |
| 750 | * IPI. So we are going to handle the expired |
| 751 | * event anyway via the broadcast IPI |
| 752 | * handler. No need to reprogram the timer |
| 753 | * with an already expired event. |
| 754 | */ |
| 755 | if (cpumask_test_and_clear_cpu(cpu, |
| 756 | tick_broadcast_pending_mask)) |
| 757 | goto out; |
| 758 | |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 759 | /* |
Daniel Lezcano | ea8deb8 | 2013-06-17 18:15:35 +0200 | [diff] [blame] | 760 | * Bail out if there is no next event. |
| 761 | */ |
| 762 | if (dev->next_event.tv64 == KTIME_MAX) |
| 763 | goto out; |
| 764 | /* |
Thomas Gleixner | 989dcb6 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 765 | * If the pending bit is not set, then we are |
| 766 | * either the CPU handling the broadcast |
| 767 | * interrupt or we got woken by something else. |
| 768 | * |
| 769 | * We are not longer in the broadcast mask, so |
| 770 | * if the cpu local expiry time is already |
| 771 | * reached, we would reprogram the cpu local |
| 772 | * timer with an already expired event. |
| 773 | * |
| 774 | * This can lead to a ping-pong when we return |
| 775 | * to idle and therefor rearm the broadcast |
| 776 | * timer before the cpu local timer was able |
| 777 | * to fire. This happens because the forced |
| 778 | * reprogramming makes sure that the event |
| 779 | * will happen in the future and depending on |
| 780 | * the min_delta setting this might be far |
| 781 | * enough out that the ping-pong starts. |
| 782 | * |
| 783 | * If the cpu local next_event has expired |
| 784 | * then we know that the broadcast timer |
| 785 | * next_event has expired as well and |
| 786 | * broadcast is about to be handled. So we |
| 787 | * avoid reprogramming and enforce that the |
| 788 | * broadcast handler, which did not run yet, |
| 789 | * will invoke the cpu local handler. |
| 790 | * |
| 791 | * We cannot call the handler directly from |
| 792 | * here, because we might be in a NOHZ phase |
| 793 | * and we did not go through the irq_enter() |
| 794 | * nohz fixups. |
| 795 | */ |
| 796 | now = ktime_get(); |
| 797 | if (dev->next_event.tv64 <= now.tv64) { |
| 798 | cpumask_set_cpu(cpu, tick_broadcast_force_mask); |
| 799 | goto out; |
| 800 | } |
| 801 | /* |
| 802 | * We got woken by something else. Reprogram |
| 803 | * the cpu local timer device. |
| 804 | */ |
Thomas Gleixner | 26517f3 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 805 | tick_program_event(dev->next_event, 1); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 806 | } |
| 807 | } |
Thomas Gleixner | 26517f3 | 2013-03-06 11:18:35 +0000 | [diff] [blame] | 808 | out: |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 809 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 810 | return ret; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 811 | } |
| 812 | |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 813 | /* |
| 814 | * Reset the one shot broadcast for a cpu |
| 815 | * |
| 816 | * Called with tick_broadcast_lock held |
| 817 | */ |
| 818 | static void tick_broadcast_clear_oneshot(int cpu) |
| 819 | { |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 820 | cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); |
Thomas Gleixner | dd5fd9b | 2014-02-11 14:35:40 +0100 | [diff] [blame] | 821 | cpumask_clear_cpu(cpu, tick_broadcast_pending_mask); |
Thomas Gleixner | 5590a53 | 2007-07-21 04:37:35 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 824 | static void tick_broadcast_init_next_event(struct cpumask *mask, |
| 825 | ktime_t expires) |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 826 | { |
| 827 | struct tick_device *td; |
| 828 | int cpu; |
| 829 | |
Rusty Russell | 5db0e1e | 2009-01-01 10:12:29 +1030 | [diff] [blame] | 830 | for_each_cpu(cpu, mask) { |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 831 | td = &per_cpu(tick_cpu_device, cpu); |
| 832 | if (td->evtdev) |
| 833 | td->evtdev->next_event = expires; |
| 834 | } |
| 835 | } |
| 836 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 837 | /** |
Li Zefan | 8dce39c | 2007-11-05 14:51:10 -0800 | [diff] [blame] | 838 | * tick_broadcast_setup_oneshot - setup the broadcast device |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 839 | */ |
| 840 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
| 841 | { |
Thomas Gleixner | 07f4beb | 2011-05-16 11:07:48 +0200 | [diff] [blame] | 842 | int cpu = smp_processor_id(); |
| 843 | |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 844 | /* Set it up only once ! */ |
| 845 | if (bc->event_handler != tick_handle_oneshot_broadcast) { |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 846 | int was_periodic = bc->state == CLOCK_EVT_STATE_PERIODIC; |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 847 | |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 848 | bc->event_handler = tick_handle_oneshot_broadcast; |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 849 | |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 850 | /* |
| 851 | * We must be careful here. There might be other CPUs |
| 852 | * waiting for periodic broadcast. We need to set the |
| 853 | * oneshot_mask bits for those and program the |
| 854 | * broadcast device to fire. |
| 855 | */ |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 856 | cpumask_copy(tmpmask, tick_broadcast_mask); |
| 857 | cpumask_clear_cpu(cpu, tmpmask); |
| 858 | cpumask_or(tick_broadcast_oneshot_mask, |
| 859 | tick_broadcast_oneshot_mask, tmpmask); |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 860 | |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 861 | if (was_periodic && !cpumask_empty(tmpmask)) { |
Viresh Kumar | 77e32c8 | 2015-02-27 17:21:33 +0530 | [diff] [blame] | 862 | clockevents_set_state(bc, CLOCK_EVT_STATE_ONESHOT); |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 863 | tick_broadcast_init_next_event(tmpmask, |
Rusty Russell | 6b95482 | 2009-01-01 10:12:25 +1030 | [diff] [blame] | 864 | tick_next_period); |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 865 | tick_broadcast_set_event(bc, cpu, tick_next_period, 1); |
Thomas Gleixner | 7300711 | 2008-09-06 03:01:45 +0200 | [diff] [blame] | 866 | } else |
| 867 | bc->next_event.tv64 = KTIME_MAX; |
Thomas Gleixner | 07f4beb | 2011-05-16 11:07:48 +0200 | [diff] [blame] | 868 | } else { |
| 869 | /* |
| 870 | * The first cpu which switches to oneshot mode sets |
| 871 | * the bit for all other cpus which are in the general |
| 872 | * (periodic) broadcast mask. So the bit is set and |
| 873 | * would prevent the first broadcast enter after this |
| 874 | * to program the bc device. |
| 875 | */ |
| 876 | tick_broadcast_clear_oneshot(cpu); |
Thomas Gleixner | 9c17bcd | 2008-09-03 21:37:08 +0000 | [diff] [blame] | 877 | } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Select oneshot operating mode for the broadcast device |
| 882 | */ |
| 883 | void tick_broadcast_switch_to_oneshot(void) |
| 884 | { |
| 885 | struct clock_event_device *bc; |
| 886 | unsigned long flags; |
| 887 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 888 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Suresh Siddha | fa4da36 | 2012-04-09 15:41:44 -0700 | [diff] [blame] | 889 | |
| 890 | tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT; |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 891 | bc = tick_broadcast_device.evtdev; |
| 892 | if (bc) |
| 893 | tick_broadcast_setup_oneshot(bc); |
Suresh Siddha | 77b0d60 | 2011-11-04 17:18:21 -0700 | [diff] [blame] | 894 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 895 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | |
| 899 | /* |
| 900 | * Remove a dead CPU from broadcasting |
| 901 | */ |
| 902 | void tick_shutdown_broadcast_oneshot(unsigned int *cpup) |
| 903 | { |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 904 | unsigned long flags; |
| 905 | unsigned int cpu = *cpup; |
| 906 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 907 | raw_spin_lock_irqsave(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 908 | |
Thomas Gleixner | 31d9b39 | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 909 | /* |
Thomas Gleixner | c9b5a26 | 2013-06-26 12:17:32 +0200 | [diff] [blame] | 910 | * Clear the broadcast masks for the dead cpu, but do not stop |
| 911 | * the broadcast device! |
Thomas Gleixner | 31d9b39 | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 912 | */ |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 913 | cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); |
Thomas Gleixner | c9b5a26 | 2013-06-26 12:17:32 +0200 | [diff] [blame] | 914 | cpumask_clear_cpu(cpu, tick_broadcast_pending_mask); |
| 915 | cpumask_clear_cpu(cpu, tick_broadcast_force_mask); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 916 | |
Preeti U Murthy | 5d1638a | 2014-02-07 13:36:32 +0530 | [diff] [blame] | 917 | broadcast_move_bc(cpu); |
| 918 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 919 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 920 | } |
| 921 | |
Thomas Gleixner | 27ce4cb | 2008-09-22 19:04:02 +0200 | [diff] [blame] | 922 | /* |
| 923 | * Check, whether the broadcast device is in one shot mode |
| 924 | */ |
| 925 | int tick_broadcast_oneshot_active(void) |
| 926 | { |
| 927 | return tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT; |
| 928 | } |
| 929 | |
Thomas Gleixner | 3a142a0 | 2011-02-25 22:34:23 +0100 | [diff] [blame] | 930 | /* |
| 931 | * Check whether the broadcast device supports oneshot. |
| 932 | */ |
| 933 | bool tick_broadcast_oneshot_available(void) |
| 934 | { |
| 935 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
| 936 | |
| 937 | return bc ? bc->features & CLOCK_EVT_FEAT_ONESHOT : false; |
| 938 | } |
| 939 | |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 940 | #endif |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 941 | |
| 942 | void __init tick_broadcast_init(void) |
| 943 | { |
Thomas Gleixner | fbd44a6 | 2013-05-03 20:22:36 +0200 | [diff] [blame] | 944 | zalloc_cpumask_var(&tick_broadcast_mask, GFP_NOWAIT); |
Thomas Gleixner | 07bd117 | 2013-07-01 22:14:10 +0200 | [diff] [blame] | 945 | zalloc_cpumask_var(&tick_broadcast_on, GFP_NOWAIT); |
Thomas Gleixner | fbd44a6 | 2013-05-03 20:22:36 +0200 | [diff] [blame] | 946 | zalloc_cpumask_var(&tmpmask, GFP_NOWAIT); |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 947 | #ifdef CONFIG_TICK_ONESHOT |
Thomas Gleixner | fbd44a6 | 2013-05-03 20:22:36 +0200 | [diff] [blame] | 948 | zalloc_cpumask_var(&tick_broadcast_oneshot_mask, GFP_NOWAIT); |
| 949 | zalloc_cpumask_var(&tick_broadcast_pending_mask, GFP_NOWAIT); |
| 950 | zalloc_cpumask_var(&tick_broadcast_force_mask, GFP_NOWAIT); |
Thomas Gleixner | b352bc1 | 2013-03-05 14:25:32 +0100 | [diff] [blame] | 951 | #endif |
| 952 | } |