Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Split spinlock implementation out into its own file, so it can be |
| 3 | * compiled in a FTRACE-compatible way. |
| 4 | */ |
| 5 | #include <linux/kernel_stat.h> |
| 6 | #include <linux/spinlock.h> |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 7 | #include <linux/debugfs.h> |
| 8 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/gfp.h> |
Konrad Rzeszutek Wilk | 354e7b7 | 2013-06-05 10:44:47 -0400 | [diff] [blame] | 10 | #include <linux/slab.h> |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 11 | |
| 12 | #include <asm/paravirt.h> |
| 13 | |
| 14 | #include <xen/interface/xen.h> |
| 15 | #include <xen/events.h> |
| 16 | |
| 17 | #include "xen-ops.h" |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 18 | #include "debugfs.h" |
| 19 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 20 | enum xen_contention_stat { |
| 21 | TAKEN_SLOW, |
| 22 | TAKEN_SLOW_PICKUP, |
| 23 | TAKEN_SLOW_SPURIOUS, |
| 24 | RELEASED_SLOW, |
| 25 | RELEASED_SLOW_KICKED, |
| 26 | NR_CONTENTION_STATS |
| 27 | }; |
| 28 | |
| 29 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 30 | #ifdef CONFIG_XEN_DEBUG_FS |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 31 | #define HISTO_BUCKETS 30 |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 32 | static struct xen_spinlock_stats |
| 33 | { |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 34 | u32 contention_stats[NR_CONTENTION_STATS]; |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 35 | u32 histo_spin_blocked[HISTO_BUCKETS+1]; |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 36 | u64 time_blocked; |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 37 | } spinlock_stats; |
| 38 | |
| 39 | static u8 zero_stats; |
| 40 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 41 | static inline void check_zero(void) |
| 42 | { |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 43 | u8 ret; |
| 44 | u8 old = ACCESS_ONCE(zero_stats); |
| 45 | if (unlikely(old)) { |
| 46 | ret = cmpxchg(&zero_stats, old, 0); |
| 47 | /* This ensures only one fellow resets the stat */ |
| 48 | if (ret == old) |
| 49 | memset(&spinlock_stats, 0, sizeof(spinlock_stats)); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 53 | static inline void add_stats(enum xen_contention_stat var, u32 val) |
| 54 | { |
| 55 | check_zero(); |
| 56 | spinlock_stats.contention_stats[var] += val; |
| 57 | } |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 58 | |
| 59 | static inline u64 spin_time_start(void) |
| 60 | { |
| 61 | return xen_clocksource_read(); |
| 62 | } |
| 63 | |
| 64 | static void __spin_time_accum(u64 delta, u32 *array) |
| 65 | { |
| 66 | unsigned index = ilog2(delta); |
| 67 | |
| 68 | check_zero(); |
| 69 | |
| 70 | if (index < HISTO_BUCKETS) |
| 71 | array[index]++; |
| 72 | else |
| 73 | array[HISTO_BUCKETS]++; |
| 74 | } |
| 75 | |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 76 | static inline void spin_time_accum_blocked(u64 start) |
| 77 | { |
| 78 | u32 delta = xen_clocksource_read() - start; |
| 79 | |
| 80 | __spin_time_accum(delta, spinlock_stats.histo_spin_blocked); |
| 81 | spinlock_stats.time_blocked += delta; |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 82 | } |
| 83 | #else /* !CONFIG_XEN_DEBUG_FS */ |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 84 | static inline void add_stats(enum xen_contention_stat var, u32 val) |
| 85 | { |
| 86 | } |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 87 | |
| 88 | static inline u64 spin_time_start(void) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 93 | static inline void spin_time_accum_blocked(u64 start) |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 94 | { |
| 95 | } |
| 96 | #endif /* CONFIG_XEN_DEBUG_FS */ |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 97 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 98 | struct xen_lock_waiting { |
| 99 | struct arch_spinlock *lock; |
| 100 | __ticket_t want; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Jeremy Fitzhardinge | 545ac13 | 2013-08-09 19:51:49 +0530 | [diff] [blame] | 103 | static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; |
Konrad Rzeszutek Wilk | 354e7b7 | 2013-06-05 10:44:47 -0400 | [diff] [blame] | 104 | static DEFINE_PER_CPU(char *, irq_name); |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 105 | static DEFINE_PER_CPU(struct xen_lock_waiting, lock_waiting); |
| 106 | static cpumask_t waiting_cpus; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 107 | |
Konrad Rzeszutek Wilk | c3b7cb1 | 2013-09-09 13:08:49 -0400 | [diff] [blame] | 108 | static bool xen_pvspin = true; |
Andi Kleen | dd41f81 | 2013-10-22 09:07:58 -0700 | [diff] [blame] | 109 | __visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want) |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 110 | { |
Christoph Lameter | 780f36d | 2010-12-06 11:16:29 -0600 | [diff] [blame] | 111 | int irq = __this_cpu_read(lock_kicker_irq); |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 112 | struct xen_lock_waiting *w = this_cpu_ptr(&lock_waiting); |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 113 | int cpu = smp_processor_id(); |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 114 | u64 start; |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 115 | unsigned long flags; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 116 | |
| 117 | /* If kicker interrupts not initialized yet, just spin */ |
| 118 | if (irq == -1) |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 119 | return; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 120 | |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 121 | start = spin_time_start(); |
| 122 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 123 | /* |
| 124 | * Make sure an interrupt handler can't upset things in a |
| 125 | * partially setup state. |
| 126 | */ |
| 127 | local_irq_save(flags); |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 128 | /* |
| 129 | * We don't really care if we're overwriting some other |
| 130 | * (lock,want) pair, as that would mean that we're currently |
| 131 | * in an interrupt context, and the outer context had |
| 132 | * interrupts enabled. That has already kicked the VCPU out |
| 133 | * of xen_poll_irq(), so it will just return spuriously and |
| 134 | * retry with newly setup (lock,want). |
| 135 | * |
| 136 | * The ordering protocol on this is that the "lock" pointer |
| 137 | * may only be set non-NULL if the "want" ticket is correct. |
| 138 | * If we're updating "want", we must first clear "lock". |
| 139 | */ |
| 140 | w->lock = NULL; |
| 141 | smp_wmb(); |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 142 | w->want = want; |
| 143 | smp_wmb(); |
| 144 | w->lock = lock; |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 145 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 146 | /* This uses set_bit, which atomic and therefore a barrier */ |
| 147 | cpumask_set_cpu(cpu, &waiting_cpus); |
| 148 | add_stats(TAKEN_SLOW, 1); |
Jeremy Fitzhardinge | 4d576b5 | 2009-09-09 12:33:51 -0700 | [diff] [blame] | 149 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 150 | /* clear pending */ |
| 151 | xen_clear_irq_pending(irq); |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 152 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 153 | /* Only check lock once pending cleared */ |
| 154 | barrier(); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 155 | |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 156 | /* |
| 157 | * Mark entry to slowpath before doing the pickup test to make |
| 158 | * sure we don't deadlock with an unlocker. |
| 159 | */ |
Jeremy Fitzhardinge | 96f853e | 2013-08-09 19:51:58 +0530 | [diff] [blame] | 160 | __ticket_enter_slowpath(lock); |
| 161 | |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 162 | /* |
| 163 | * check again make sure it didn't become free while |
| 164 | * we weren't looking |
| 165 | */ |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 166 | if (ACCESS_ONCE(lock->tickets.head) == want) { |
| 167 | add_stats(TAKEN_SLOW_PICKUP, 1); |
| 168 | goto out; |
| 169 | } |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 170 | |
| 171 | /* Allow interrupts while blocked */ |
| 172 | local_irq_restore(flags); |
| 173 | |
| 174 | /* |
| 175 | * If an interrupt happens here, it will leave the wakeup irq |
| 176 | * pending, which will cause xen_poll_irq() to return |
| 177 | * immediately. |
| 178 | */ |
| 179 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 180 | /* Block until irq becomes pending (or perhaps a spurious wakeup) */ |
| 181 | xen_poll_irq(irq); |
| 182 | add_stats(TAKEN_SLOW_SPURIOUS, !xen_test_irq_pending(irq)); |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 183 | |
| 184 | local_irq_save(flags); |
| 185 | |
Thomas Gleixner | 770144e | 2014-02-23 21:40:16 +0000 | [diff] [blame] | 186 | kstat_incr_irq_this_cpu(irq); |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 187 | out: |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 188 | cpumask_clear_cpu(cpu, &waiting_cpus); |
| 189 | w->lock = NULL; |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 190 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 191 | local_irq_restore(flags); |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 192 | |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 193 | spin_time_accum_blocked(start); |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 194 | } |
Jeremy Fitzhardinge | 354714d | 2013-08-09 19:51:55 +0530 | [diff] [blame] | 195 | PV_CALLEE_SAVE_REGS_THUNK(xen_lock_spinning); |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 196 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 197 | static void xen_unlock_kick(struct arch_spinlock *lock, __ticket_t next) |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 198 | { |
| 199 | int cpu; |
| 200 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 201 | add_stats(RELEASED_SLOW, 1); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 202 | |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 203 | for_each_cpu(cpu, &waiting_cpus) { |
| 204 | const struct xen_lock_waiting *w = &per_cpu(lock_waiting, cpu); |
| 205 | |
Jeremy Fitzhardinge | 1ed7bf5 | 2013-08-09 19:51:59 +0530 | [diff] [blame] | 206 | /* Make sure we read lock before want */ |
| 207 | if (ACCESS_ONCE(w->lock) == lock && |
| 208 | ACCESS_ONCE(w->want) == next) { |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 209 | add_stats(RELEASED_SLOW_KICKED, 1); |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 210 | xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 211 | break; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 216 | static irqreturn_t dummy_handler(int irq, void *dev_id) |
| 217 | { |
| 218 | BUG(); |
| 219 | return IRQ_HANDLED; |
| 220 | } |
| 221 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 222 | void xen_init_lock_cpu(int cpu) |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 223 | { |
| 224 | int irq; |
Konrad Rzeszutek Wilk | 354e7b7 | 2013-06-05 10:44:47 -0400 | [diff] [blame] | 225 | char *name; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 226 | |
Konrad Rzeszutek Wilk | 3310bbe | 2013-08-26 14:28:06 -0400 | [diff] [blame] | 227 | if (!xen_pvspin) |
| 228 | return; |
| 229 | |
Konrad Rzeszutek Wilk | cb91f8f | 2013-05-06 08:33:15 -0400 | [diff] [blame] | 230 | WARN(per_cpu(lock_kicker_irq, cpu) >= 0, "spinlock on CPU%d exists on IRQ%d!\n", |
Konrad Rzeszutek Wilk | cb9c6f1 | 2013-04-16 14:33:20 -0400 | [diff] [blame] | 231 | cpu, per_cpu(lock_kicker_irq, cpu)); |
| 232 | |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 233 | name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); |
| 234 | irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, |
| 235 | cpu, |
| 236 | dummy_handler, |
Michael Opdenacker | 9d71cee | 2013-09-07 08:46:49 +0200 | [diff] [blame] | 237 | IRQF_PERCPU|IRQF_NOBALANCING, |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 238 | name, |
| 239 | NULL); |
| 240 | |
| 241 | if (irq >= 0) { |
| 242 | disable_irq(irq); /* make sure it's never delivered */ |
| 243 | per_cpu(lock_kicker_irq, cpu) = irq; |
Konrad Rzeszutek Wilk | 354e7b7 | 2013-06-05 10:44:47 -0400 | [diff] [blame] | 244 | per_cpu(irq_name, cpu) = name; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | printk("cpu %d spinlock event irq %d\n", cpu, irq); |
| 248 | } |
| 249 | |
Alex Nixon | d68d82a | 2008-08-22 11:52:15 +0100 | [diff] [blame] | 250 | void xen_uninit_lock_cpu(int cpu) |
| 251 | { |
Konrad Rzeszutek Wilk | 3310bbe | 2013-08-26 14:28:06 -0400 | [diff] [blame] | 252 | if (!xen_pvspin) |
| 253 | return; |
| 254 | |
Alex Nixon | d68d82a | 2008-08-22 11:52:15 +0100 | [diff] [blame] | 255 | unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL); |
Konrad Rzeszutek Wilk | cb9c6f1 | 2013-04-16 14:33:20 -0400 | [diff] [blame] | 256 | per_cpu(lock_kicker_irq, cpu) = -1; |
Konrad Rzeszutek Wilk | 354e7b7 | 2013-06-05 10:44:47 -0400 | [diff] [blame] | 257 | kfree(per_cpu(irq_name, cpu)); |
| 258 | per_cpu(irq_name, cpu) = NULL; |
Alex Nixon | d68d82a | 2008-08-22 11:52:15 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Jeremy Fitzhardinge | b8fa70b | 2013-08-09 19:51:54 +0530 | [diff] [blame] | 261 | |
Konrad Rzeszutek Wilk | a945928 | 2013-09-12 22:29:44 -0400 | [diff] [blame] | 262 | /* |
| 263 | * Our init of PV spinlocks is split in two init functions due to us |
| 264 | * using paravirt patching and jump labels patching and having to do |
| 265 | * all of this before SMP code is invoked. |
| 266 | * |
| 267 | * The paravirt patching needs to be done _before_ the alternative asm code |
| 268 | * is started, otherwise we would not patch the core kernel code. |
| 269 | */ |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 270 | void __init xen_init_spinlocks(void) |
| 271 | { |
Konrad Rzeszutek Wilk | 70dd499 | 2013-04-16 14:34:45 -0400 | [diff] [blame] | 272 | |
Jeremy Fitzhardinge | b8fa70b | 2013-08-09 19:51:54 +0530 | [diff] [blame] | 273 | if (!xen_pvspin) { |
| 274 | printk(KERN_DEBUG "xen: PV spinlocks disabled\n"); |
| 275 | return; |
| 276 | } |
Konrad Rzeszutek Wilk | e0fc17a | 2014-04-04 14:48:04 -0400 | [diff] [blame] | 277 | printk(KERN_DEBUG "xen: PV spinlocks enabled\n"); |
Jeremy Fitzhardinge | 354714d | 2013-08-09 19:51:55 +0530 | [diff] [blame] | 278 | pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(xen_lock_spinning); |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 279 | pv_lock_ops.unlock_kick = xen_unlock_kick; |
Jeremy Fitzhardinge | d5de884 | 2008-07-23 13:28:58 -0700 | [diff] [blame] | 280 | } |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 281 | |
Konrad Rzeszutek Wilk | a945928 | 2013-09-12 22:29:44 -0400 | [diff] [blame] | 282 | /* |
| 283 | * While the jump_label init code needs to happend _after_ the jump labels are |
| 284 | * enabled and before SMP is started. Hence we use pre-SMP initcall level |
| 285 | * init. We cannot do it in xen_init_spinlocks as that is done before |
| 286 | * jump labels are activated. |
| 287 | */ |
| 288 | static __init int xen_init_spinlocks_jump(void) |
| 289 | { |
| 290 | if (!xen_pvspin) |
| 291 | return 0; |
| 292 | |
Konrad Rzeszutek Wilk | e0fc17a | 2014-04-04 14:48:04 -0400 | [diff] [blame] | 293 | if (!xen_domain()) |
| 294 | return 0; |
| 295 | |
Konrad Rzeszutek Wilk | a945928 | 2013-09-12 22:29:44 -0400 | [diff] [blame] | 296 | static_key_slow_inc(¶virt_ticketlocks_enabled); |
| 297 | return 0; |
| 298 | } |
| 299 | early_initcall(xen_init_spinlocks_jump); |
| 300 | |
Jeremy Fitzhardinge | b8fa70b | 2013-08-09 19:51:54 +0530 | [diff] [blame] | 301 | static __init int xen_parse_nopvspin(char *arg) |
| 302 | { |
| 303 | xen_pvspin = false; |
| 304 | return 0; |
| 305 | } |
| 306 | early_param("xen_nopvspin", xen_parse_nopvspin); |
| 307 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 308 | #ifdef CONFIG_XEN_DEBUG_FS |
| 309 | |
| 310 | static struct dentry *d_spin_debug; |
| 311 | |
| 312 | static int __init xen_spinlock_debugfs(void) |
| 313 | { |
| 314 | struct dentry *d_xen = xen_init_debugfs(); |
| 315 | |
| 316 | if (d_xen == NULL) |
| 317 | return -ENOMEM; |
| 318 | |
Konrad Rzeszutek Wilk | 3310bbe | 2013-08-26 14:28:06 -0400 | [diff] [blame] | 319 | if (!xen_pvspin) |
| 320 | return 0; |
| 321 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 322 | d_spin_debug = debugfs_create_dir("spinlocks", d_xen); |
| 323 | |
| 324 | debugfs_create_u8("zero_stats", 0644, d_spin_debug, &zero_stats); |
| 325 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 326 | debugfs_create_u32("taken_slow", 0444, d_spin_debug, |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 327 | &spinlock_stats.contention_stats[TAKEN_SLOW]); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 328 | debugfs_create_u32("taken_slow_pickup", 0444, d_spin_debug, |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 329 | &spinlock_stats.contention_stats[TAKEN_SLOW_PICKUP]); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 330 | debugfs_create_u32("taken_slow_spurious", 0444, d_spin_debug, |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 331 | &spinlock_stats.contention_stats[TAKEN_SLOW_SPURIOUS]); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 332 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 333 | debugfs_create_u32("released_slow", 0444, d_spin_debug, |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 334 | &spinlock_stats.contention_stats[RELEASED_SLOW]); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 335 | debugfs_create_u32("released_slow_kicked", 0444, d_spin_debug, |
Jeremy Fitzhardinge | 80bd58f | 2013-08-09 19:51:53 +0530 | [diff] [blame] | 336 | &spinlock_stats.contention_stats[RELEASED_SLOW_KICKED]); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 337 | |
Jeremy Fitzhardinge | f8eca41 | 2008-08-20 17:02:21 -0700 | [diff] [blame] | 338 | debugfs_create_u64("time_blocked", 0444, d_spin_debug, |
| 339 | &spinlock_stats.time_blocked); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 340 | |
Srivatsa Vaddagiri | 9fe2a70 | 2012-03-23 13:36:28 +0530 | [diff] [blame] | 341 | debugfs_create_u32_array("histo_blocked", 0444, d_spin_debug, |
| 342 | spinlock_stats.histo_spin_blocked, HISTO_BUCKETS + 1); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | fs_initcall(xen_spinlock_debugfs); |
| 347 | |
| 348 | #endif /* CONFIG_XEN_DEBUG_FS */ |