1d5de8841SJeremy Fitzhardinge /* 2d5de8841SJeremy Fitzhardinge * Split spinlock implementation out into its own file, so it can be 3d5de8841SJeremy Fitzhardinge * compiled in a FTRACE-compatible way. 4d5de8841SJeremy Fitzhardinge */ 5d5de8841SJeremy Fitzhardinge #include <linux/kernel_stat.h> 6d5de8841SJeremy Fitzhardinge #include <linux/spinlock.h> 7994025caSJeremy Fitzhardinge #include <linux/debugfs.h> 8994025caSJeremy Fitzhardinge #include <linux/log2.h> 9d5de8841SJeremy Fitzhardinge 10d5de8841SJeremy Fitzhardinge #include <asm/paravirt.h> 11d5de8841SJeremy Fitzhardinge 12d5de8841SJeremy Fitzhardinge #include <xen/interface/xen.h> 13d5de8841SJeremy Fitzhardinge #include <xen/events.h> 14d5de8841SJeremy Fitzhardinge 15d5de8841SJeremy Fitzhardinge #include "xen-ops.h" 16994025caSJeremy Fitzhardinge #include "debugfs.h" 17994025caSJeremy Fitzhardinge 18994025caSJeremy Fitzhardinge #ifdef CONFIG_XEN_DEBUG_FS 19994025caSJeremy Fitzhardinge static struct xen_spinlock_stats 20994025caSJeremy Fitzhardinge { 21994025caSJeremy Fitzhardinge u64 taken; 22994025caSJeremy Fitzhardinge u32 taken_slow; 23994025caSJeremy Fitzhardinge u32 taken_slow_nested; 24994025caSJeremy Fitzhardinge u32 taken_slow_pickup; 25994025caSJeremy Fitzhardinge u32 taken_slow_spurious; 261e696f63SJeremy Fitzhardinge u32 taken_slow_irqenable; 27994025caSJeremy Fitzhardinge 28994025caSJeremy Fitzhardinge u64 released; 29994025caSJeremy Fitzhardinge u32 released_slow; 30994025caSJeremy Fitzhardinge u32 released_slow_kicked; 31994025caSJeremy Fitzhardinge 32f8eca41fSJeremy Fitzhardinge #define HISTO_BUCKETS 30 33f8eca41fSJeremy Fitzhardinge u32 histo_spin_total[HISTO_BUCKETS+1]; 34f8eca41fSJeremy Fitzhardinge u32 histo_spin_spinning[HISTO_BUCKETS+1]; 35f8eca41fSJeremy Fitzhardinge u32 histo_spin_blocked[HISTO_BUCKETS+1]; 36994025caSJeremy Fitzhardinge 37f8eca41fSJeremy Fitzhardinge u64 time_total; 38f8eca41fSJeremy Fitzhardinge u64 time_spinning; 39f8eca41fSJeremy Fitzhardinge u64 time_blocked; 40994025caSJeremy Fitzhardinge } spinlock_stats; 41994025caSJeremy Fitzhardinge 42994025caSJeremy Fitzhardinge static u8 zero_stats; 43994025caSJeremy Fitzhardinge 44994025caSJeremy Fitzhardinge static unsigned lock_timeout = 1 << 10; 45994025caSJeremy Fitzhardinge #define TIMEOUT lock_timeout 46994025caSJeremy Fitzhardinge 47994025caSJeremy Fitzhardinge static inline void check_zero(void) 48994025caSJeremy Fitzhardinge { 49994025caSJeremy Fitzhardinge if (unlikely(zero_stats)) { 50994025caSJeremy Fitzhardinge memset(&spinlock_stats, 0, sizeof(spinlock_stats)); 51994025caSJeremy Fitzhardinge zero_stats = 0; 52994025caSJeremy Fitzhardinge } 53994025caSJeremy Fitzhardinge } 54994025caSJeremy Fitzhardinge 55994025caSJeremy Fitzhardinge #define ADD_STATS(elem, val) \ 56994025caSJeremy Fitzhardinge do { check_zero(); spinlock_stats.elem += (val); } while(0) 57994025caSJeremy Fitzhardinge 58994025caSJeremy Fitzhardinge static inline u64 spin_time_start(void) 59994025caSJeremy Fitzhardinge { 60994025caSJeremy Fitzhardinge return xen_clocksource_read(); 61994025caSJeremy Fitzhardinge } 62994025caSJeremy Fitzhardinge 63994025caSJeremy Fitzhardinge static void __spin_time_accum(u64 delta, u32 *array) 64994025caSJeremy Fitzhardinge { 65994025caSJeremy Fitzhardinge unsigned index = ilog2(delta); 66994025caSJeremy Fitzhardinge 67994025caSJeremy Fitzhardinge check_zero(); 68994025caSJeremy Fitzhardinge 69994025caSJeremy Fitzhardinge if (index < HISTO_BUCKETS) 70994025caSJeremy Fitzhardinge array[index]++; 71994025caSJeremy Fitzhardinge else 72994025caSJeremy Fitzhardinge array[HISTO_BUCKETS]++; 73994025caSJeremy Fitzhardinge } 74994025caSJeremy Fitzhardinge 75f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_spinning(u64 start) 76994025caSJeremy Fitzhardinge { 77994025caSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 78994025caSJeremy Fitzhardinge 79f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_spinning); 80f8eca41fSJeremy Fitzhardinge spinlock_stats.time_spinning += delta; 81994025caSJeremy Fitzhardinge } 82994025caSJeremy Fitzhardinge 83f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_total(u64 start) 84994025caSJeremy Fitzhardinge { 85994025caSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 86994025caSJeremy Fitzhardinge 87f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_total); 88f8eca41fSJeremy Fitzhardinge spinlock_stats.time_total += delta; 89f8eca41fSJeremy Fitzhardinge } 90f8eca41fSJeremy Fitzhardinge 91f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_blocked(u64 start) 92f8eca41fSJeremy Fitzhardinge { 93f8eca41fSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 94f8eca41fSJeremy Fitzhardinge 95f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_blocked); 96f8eca41fSJeremy Fitzhardinge spinlock_stats.time_blocked += delta; 97994025caSJeremy Fitzhardinge } 98994025caSJeremy Fitzhardinge #else /* !CONFIG_XEN_DEBUG_FS */ 99994025caSJeremy Fitzhardinge #define TIMEOUT (1 << 10) 100994025caSJeremy Fitzhardinge #define ADD_STATS(elem, val) do { (void)(val); } while(0) 101994025caSJeremy Fitzhardinge 102994025caSJeremy Fitzhardinge static inline u64 spin_time_start(void) 103994025caSJeremy Fitzhardinge { 104994025caSJeremy Fitzhardinge return 0; 105994025caSJeremy Fitzhardinge } 106994025caSJeremy Fitzhardinge 107f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_total(u64 start) 108994025caSJeremy Fitzhardinge { 109994025caSJeremy Fitzhardinge } 110f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_spinning(u64 start) 111f8eca41fSJeremy Fitzhardinge { 112f8eca41fSJeremy Fitzhardinge } 113f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_blocked(u64 start) 114994025caSJeremy Fitzhardinge { 115994025caSJeremy Fitzhardinge } 116994025caSJeremy Fitzhardinge #endif /* CONFIG_XEN_DEBUG_FS */ 117d5de8841SJeremy Fitzhardinge 118d5de8841SJeremy Fitzhardinge struct xen_spinlock { 119d5de8841SJeremy Fitzhardinge unsigned char lock; /* 0 -> free; 1 -> locked */ 120d5de8841SJeremy Fitzhardinge unsigned short spinners; /* count of waiting cpus */ 121d5de8841SJeremy Fitzhardinge }; 122d5de8841SJeremy Fitzhardinge 123d5de8841SJeremy Fitzhardinge static int xen_spin_is_locked(struct raw_spinlock *lock) 124d5de8841SJeremy Fitzhardinge { 125d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 126d5de8841SJeremy Fitzhardinge 127d5de8841SJeremy Fitzhardinge return xl->lock != 0; 128d5de8841SJeremy Fitzhardinge } 129d5de8841SJeremy Fitzhardinge 130d5de8841SJeremy Fitzhardinge static int xen_spin_is_contended(struct raw_spinlock *lock) 131d5de8841SJeremy Fitzhardinge { 132d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 133d5de8841SJeremy Fitzhardinge 134d5de8841SJeremy Fitzhardinge /* Not strictly true; this is only the count of contended 135d5de8841SJeremy Fitzhardinge lock-takers entering the slow path. */ 136d5de8841SJeremy Fitzhardinge return xl->spinners != 0; 137d5de8841SJeremy Fitzhardinge } 138d5de8841SJeremy Fitzhardinge 139d5de8841SJeremy Fitzhardinge static int xen_spin_trylock(struct raw_spinlock *lock) 140d5de8841SJeremy Fitzhardinge { 141d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 142d5de8841SJeremy Fitzhardinge u8 old = 1; 143d5de8841SJeremy Fitzhardinge 144d5de8841SJeremy Fitzhardinge asm("xchgb %b0,%1" 145d5de8841SJeremy Fitzhardinge : "+q" (old), "+m" (xl->lock) : : "memory"); 146d5de8841SJeremy Fitzhardinge 147d5de8841SJeremy Fitzhardinge return old == 0; 148d5de8841SJeremy Fitzhardinge } 149d5de8841SJeremy Fitzhardinge 150d5de8841SJeremy Fitzhardinge static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; 151d5de8841SJeremy Fitzhardinge static DEFINE_PER_CPU(struct xen_spinlock *, lock_spinners); 152d5de8841SJeremy Fitzhardinge 153168d2f46SJeremy Fitzhardinge /* 154168d2f46SJeremy Fitzhardinge * Mark a cpu as interested in a lock. Returns the CPU's previous 155168d2f46SJeremy Fitzhardinge * lock of interest, in case we got preempted by an interrupt. 156168d2f46SJeremy Fitzhardinge */ 157168d2f46SJeremy Fitzhardinge static inline struct xen_spinlock *spinning_lock(struct xen_spinlock *xl) 158d5de8841SJeremy Fitzhardinge { 159168d2f46SJeremy Fitzhardinge struct xen_spinlock *prev; 160168d2f46SJeremy Fitzhardinge 161168d2f46SJeremy Fitzhardinge prev = __get_cpu_var(lock_spinners); 162d5de8841SJeremy Fitzhardinge __get_cpu_var(lock_spinners) = xl; 163168d2f46SJeremy Fitzhardinge 164d5de8841SJeremy Fitzhardinge wmb(); /* set lock of interest before count */ 165168d2f46SJeremy Fitzhardinge 166d5de8841SJeremy Fitzhardinge asm(LOCK_PREFIX " incw %0" 167d5de8841SJeremy Fitzhardinge : "+m" (xl->spinners) : : "memory"); 168168d2f46SJeremy Fitzhardinge 169168d2f46SJeremy Fitzhardinge return prev; 170d5de8841SJeremy Fitzhardinge } 171d5de8841SJeremy Fitzhardinge 172168d2f46SJeremy Fitzhardinge /* 173168d2f46SJeremy Fitzhardinge * Mark a cpu as no longer interested in a lock. Restores previous 174168d2f46SJeremy Fitzhardinge * lock of interest (NULL for none). 175168d2f46SJeremy Fitzhardinge */ 176168d2f46SJeremy Fitzhardinge static inline void unspinning_lock(struct xen_spinlock *xl, struct xen_spinlock *prev) 177d5de8841SJeremy Fitzhardinge { 178d5de8841SJeremy Fitzhardinge asm(LOCK_PREFIX " decw %0" 179d5de8841SJeremy Fitzhardinge : "+m" (xl->spinners) : : "memory"); 180168d2f46SJeremy Fitzhardinge wmb(); /* decrement count before restoring lock */ 181168d2f46SJeremy Fitzhardinge __get_cpu_var(lock_spinners) = prev; 182d5de8841SJeremy Fitzhardinge } 183d5de8841SJeremy Fitzhardinge 1841e696f63SJeremy Fitzhardinge static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enable) 185d5de8841SJeremy Fitzhardinge { 186d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 187168d2f46SJeremy Fitzhardinge struct xen_spinlock *prev; 188d5de8841SJeremy Fitzhardinge int irq = __get_cpu_var(lock_kicker_irq); 189d5de8841SJeremy Fitzhardinge int ret; 190f8eca41fSJeremy Fitzhardinge u64 start; 191d5de8841SJeremy Fitzhardinge 192d5de8841SJeremy Fitzhardinge /* If kicker interrupts not initialized yet, just spin */ 193d5de8841SJeremy Fitzhardinge if (irq == -1) 194d5de8841SJeremy Fitzhardinge return 0; 195d5de8841SJeremy Fitzhardinge 196f8eca41fSJeremy Fitzhardinge start = spin_time_start(); 197f8eca41fSJeremy Fitzhardinge 198d5de8841SJeremy Fitzhardinge /* announce we're spinning */ 199168d2f46SJeremy Fitzhardinge prev = spinning_lock(xl); 200d5de8841SJeremy Fitzhardinge 201994025caSJeremy Fitzhardinge ADD_STATS(taken_slow, 1); 202994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_nested, prev != NULL); 203994025caSJeremy Fitzhardinge 204168d2f46SJeremy Fitzhardinge do { 2054d576b57SJeremy Fitzhardinge unsigned long flags; 2064d576b57SJeremy Fitzhardinge 207d5de8841SJeremy Fitzhardinge /* clear pending */ 208d5de8841SJeremy Fitzhardinge xen_clear_irq_pending(irq); 209d5de8841SJeremy Fitzhardinge 210d5de8841SJeremy Fitzhardinge /* check again make sure it didn't become free while 211d5de8841SJeremy Fitzhardinge we weren't looking */ 212d5de8841SJeremy Fitzhardinge ret = xen_spin_trylock(lock); 213168d2f46SJeremy Fitzhardinge if (ret) { 214994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_pickup, 1); 215994025caSJeremy Fitzhardinge 216168d2f46SJeremy Fitzhardinge /* 217168d2f46SJeremy Fitzhardinge * If we interrupted another spinlock while it 218168d2f46SJeremy Fitzhardinge * was blocking, make sure it doesn't block 219168d2f46SJeremy Fitzhardinge * without rechecking the lock. 220168d2f46SJeremy Fitzhardinge */ 221168d2f46SJeremy Fitzhardinge if (prev != NULL) 222168d2f46SJeremy Fitzhardinge xen_set_irq_pending(irq); 223d5de8841SJeremy Fitzhardinge goto out; 224168d2f46SJeremy Fitzhardinge } 225d5de8841SJeremy Fitzhardinge 2264d576b57SJeremy Fitzhardinge flags = __raw_local_save_flags(); 2274d576b57SJeremy Fitzhardinge if (irq_enable) { 2284d576b57SJeremy Fitzhardinge ADD_STATS(taken_slow_irqenable, 1); 2294d576b57SJeremy Fitzhardinge raw_local_irq_enable(); 2304d576b57SJeremy Fitzhardinge } 2314d576b57SJeremy Fitzhardinge 232168d2f46SJeremy Fitzhardinge /* 233168d2f46SJeremy Fitzhardinge * Block until irq becomes pending. If we're 234168d2f46SJeremy Fitzhardinge * interrupted at this point (after the trylock but 235168d2f46SJeremy Fitzhardinge * before entering the block), then the nested lock 236168d2f46SJeremy Fitzhardinge * handler guarantees that the irq will be left 237168d2f46SJeremy Fitzhardinge * pending if there's any chance the lock became free; 238168d2f46SJeremy Fitzhardinge * xen_poll_irq() returns immediately if the irq is 239168d2f46SJeremy Fitzhardinge * pending. 240168d2f46SJeremy Fitzhardinge */ 241d5de8841SJeremy Fitzhardinge xen_poll_irq(irq); 2424d576b57SJeremy Fitzhardinge 2434d576b57SJeremy Fitzhardinge raw_local_irq_restore(flags); 2444d576b57SJeremy Fitzhardinge 245994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_spurious, !xen_test_irq_pending(irq)); 246168d2f46SJeremy Fitzhardinge } while (!xen_test_irq_pending(irq)); /* check for spurious wakeups */ 247168d2f46SJeremy Fitzhardinge 248d6c88a50SThomas Gleixner kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq)); 249d5de8841SJeremy Fitzhardinge 250d5de8841SJeremy Fitzhardinge out: 251168d2f46SJeremy Fitzhardinge unspinning_lock(xl, prev); 252f8eca41fSJeremy Fitzhardinge spin_time_accum_blocked(start); 253f8eca41fSJeremy Fitzhardinge 254d5de8841SJeremy Fitzhardinge return ret; 255d5de8841SJeremy Fitzhardinge } 256d5de8841SJeremy Fitzhardinge 2571e696f63SJeremy Fitzhardinge static inline void __xen_spin_lock(struct raw_spinlock *lock, bool irq_enable) 258d5de8841SJeremy Fitzhardinge { 259d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 260994025caSJeremy Fitzhardinge unsigned timeout; 261d5de8841SJeremy Fitzhardinge u8 oldval; 262994025caSJeremy Fitzhardinge u64 start_spin; 263994025caSJeremy Fitzhardinge 264994025caSJeremy Fitzhardinge ADD_STATS(taken, 1); 265994025caSJeremy Fitzhardinge 266994025caSJeremy Fitzhardinge start_spin = spin_time_start(); 267d5de8841SJeremy Fitzhardinge 268d5de8841SJeremy Fitzhardinge do { 269994025caSJeremy Fitzhardinge u64 start_spin_fast = spin_time_start(); 270994025caSJeremy Fitzhardinge 271994025caSJeremy Fitzhardinge timeout = TIMEOUT; 272d5de8841SJeremy Fitzhardinge 273d5de8841SJeremy Fitzhardinge asm("1: xchgb %1,%0\n" 274d5de8841SJeremy Fitzhardinge " testb %1,%1\n" 275d5de8841SJeremy Fitzhardinge " jz 3f\n" 276d5de8841SJeremy Fitzhardinge "2: rep;nop\n" 277d5de8841SJeremy Fitzhardinge " cmpb $0,%0\n" 278d5de8841SJeremy Fitzhardinge " je 1b\n" 279d5de8841SJeremy Fitzhardinge " dec %2\n" 280d5de8841SJeremy Fitzhardinge " jnz 2b\n" 281d5de8841SJeremy Fitzhardinge "3:\n" 282d5de8841SJeremy Fitzhardinge : "+m" (xl->lock), "=q" (oldval), "+r" (timeout) 283d5de8841SJeremy Fitzhardinge : "1" (1) 284d5de8841SJeremy Fitzhardinge : "memory"); 285d5de8841SJeremy Fitzhardinge 286f8eca41fSJeremy Fitzhardinge spin_time_accum_spinning(start_spin_fast); 2871e696f63SJeremy Fitzhardinge 2881e696f63SJeremy Fitzhardinge } while (unlikely(oldval != 0 && 2891e696f63SJeremy Fitzhardinge (TIMEOUT == ~0 || !xen_spin_lock_slow(lock, irq_enable)))); 290994025caSJeremy Fitzhardinge 291f8eca41fSJeremy Fitzhardinge spin_time_accum_total(start_spin); 292d5de8841SJeremy Fitzhardinge } 293d5de8841SJeremy Fitzhardinge 2941e696f63SJeremy Fitzhardinge static void xen_spin_lock(struct raw_spinlock *lock) 2951e696f63SJeremy Fitzhardinge { 2961e696f63SJeremy Fitzhardinge __xen_spin_lock(lock, false); 2971e696f63SJeremy Fitzhardinge } 2981e696f63SJeremy Fitzhardinge 2991e696f63SJeremy Fitzhardinge static void xen_spin_lock_flags(struct raw_spinlock *lock, unsigned long flags) 3001e696f63SJeremy Fitzhardinge { 3011e696f63SJeremy Fitzhardinge __xen_spin_lock(lock, !raw_irqs_disabled_flags(flags)); 3021e696f63SJeremy Fitzhardinge } 3031e696f63SJeremy Fitzhardinge 304d5de8841SJeremy Fitzhardinge static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) 305d5de8841SJeremy Fitzhardinge { 306d5de8841SJeremy Fitzhardinge int cpu; 307d5de8841SJeremy Fitzhardinge 308994025caSJeremy Fitzhardinge ADD_STATS(released_slow, 1); 309994025caSJeremy Fitzhardinge 310d5de8841SJeremy Fitzhardinge for_each_online_cpu(cpu) { 311d5de8841SJeremy Fitzhardinge /* XXX should mix up next cpu selection */ 312d5de8841SJeremy Fitzhardinge if (per_cpu(lock_spinners, cpu) == xl) { 313994025caSJeremy Fitzhardinge ADD_STATS(released_slow_kicked, 1); 314d5de8841SJeremy Fitzhardinge xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); 315d5de8841SJeremy Fitzhardinge break; 316d5de8841SJeremy Fitzhardinge } 317d5de8841SJeremy Fitzhardinge } 318d5de8841SJeremy Fitzhardinge } 319d5de8841SJeremy Fitzhardinge 320d5de8841SJeremy Fitzhardinge static void xen_spin_unlock(struct raw_spinlock *lock) 321d5de8841SJeremy Fitzhardinge { 322d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 323d5de8841SJeremy Fitzhardinge 324994025caSJeremy Fitzhardinge ADD_STATS(released, 1); 325994025caSJeremy Fitzhardinge 326d5de8841SJeremy Fitzhardinge smp_wmb(); /* make sure no writes get moved after unlock */ 327d5de8841SJeremy Fitzhardinge xl->lock = 0; /* release lock */ 328d5de8841SJeremy Fitzhardinge 329*2496afbfSYang Xiaowei /* 330*2496afbfSYang Xiaowei * Make sure unlock happens before checking for waiting 331*2496afbfSYang Xiaowei * spinners. We need a strong barrier to enforce the 332*2496afbfSYang Xiaowei * write-read ordering to different memory locations, as the 333*2496afbfSYang Xiaowei * CPU makes no implied guarantees about their ordering. 334*2496afbfSYang Xiaowei */ 335*2496afbfSYang Xiaowei mb(); 336d5de8841SJeremy Fitzhardinge 337d5de8841SJeremy Fitzhardinge if (unlikely(xl->spinners)) 338d5de8841SJeremy Fitzhardinge xen_spin_unlock_slow(xl); 339d5de8841SJeremy Fitzhardinge } 340d5de8841SJeremy Fitzhardinge 341d5de8841SJeremy Fitzhardinge static irqreturn_t dummy_handler(int irq, void *dev_id) 342d5de8841SJeremy Fitzhardinge { 343d5de8841SJeremy Fitzhardinge BUG(); 344d5de8841SJeremy Fitzhardinge return IRQ_HANDLED; 345d5de8841SJeremy Fitzhardinge } 346d5de8841SJeremy Fitzhardinge 347d5de8841SJeremy Fitzhardinge void __cpuinit xen_init_lock_cpu(int cpu) 348d5de8841SJeremy Fitzhardinge { 349d5de8841SJeremy Fitzhardinge int irq; 350d5de8841SJeremy Fitzhardinge const char *name; 351d5de8841SJeremy Fitzhardinge 352d5de8841SJeremy Fitzhardinge name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 353d5de8841SJeremy Fitzhardinge irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 354d5de8841SJeremy Fitzhardinge cpu, 355d5de8841SJeremy Fitzhardinge dummy_handler, 356d5de8841SJeremy Fitzhardinge IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING, 357d5de8841SJeremy Fitzhardinge name, 358d5de8841SJeremy Fitzhardinge NULL); 359d5de8841SJeremy Fitzhardinge 360d5de8841SJeremy Fitzhardinge if (irq >= 0) { 361d5de8841SJeremy Fitzhardinge disable_irq(irq); /* make sure it's never delivered */ 362d5de8841SJeremy Fitzhardinge per_cpu(lock_kicker_irq, cpu) = irq; 363d5de8841SJeremy Fitzhardinge } 364d5de8841SJeremy Fitzhardinge 365d5de8841SJeremy Fitzhardinge printk("cpu %d spinlock event irq %d\n", cpu, irq); 366d5de8841SJeremy Fitzhardinge } 367d5de8841SJeremy Fitzhardinge 368d68d82afSAlex Nixon void xen_uninit_lock_cpu(int cpu) 369d68d82afSAlex Nixon { 370d68d82afSAlex Nixon unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL); 371d68d82afSAlex Nixon } 372d68d82afSAlex Nixon 373d5de8841SJeremy Fitzhardinge void __init xen_init_spinlocks(void) 374d5de8841SJeremy Fitzhardinge { 375d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_is_locked = xen_spin_is_locked; 376d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_is_contended = xen_spin_is_contended; 377d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_lock = xen_spin_lock; 3781e696f63SJeremy Fitzhardinge pv_lock_ops.spin_lock_flags = xen_spin_lock_flags; 379d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_trylock = xen_spin_trylock; 380d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_unlock = xen_spin_unlock; 381d5de8841SJeremy Fitzhardinge } 382994025caSJeremy Fitzhardinge 383994025caSJeremy Fitzhardinge #ifdef CONFIG_XEN_DEBUG_FS 384994025caSJeremy Fitzhardinge 385994025caSJeremy Fitzhardinge static struct dentry *d_spin_debug; 386994025caSJeremy Fitzhardinge 387994025caSJeremy Fitzhardinge static int __init xen_spinlock_debugfs(void) 388994025caSJeremy Fitzhardinge { 389994025caSJeremy Fitzhardinge struct dentry *d_xen = xen_init_debugfs(); 390994025caSJeremy Fitzhardinge 391994025caSJeremy Fitzhardinge if (d_xen == NULL) 392994025caSJeremy Fitzhardinge return -ENOMEM; 393994025caSJeremy Fitzhardinge 394994025caSJeremy Fitzhardinge d_spin_debug = debugfs_create_dir("spinlocks", d_xen); 395994025caSJeremy Fitzhardinge 396994025caSJeremy Fitzhardinge debugfs_create_u8("zero_stats", 0644, d_spin_debug, &zero_stats); 397994025caSJeremy Fitzhardinge 398994025caSJeremy Fitzhardinge debugfs_create_u32("timeout", 0644, d_spin_debug, &lock_timeout); 399994025caSJeremy Fitzhardinge 400994025caSJeremy Fitzhardinge debugfs_create_u64("taken", 0444, d_spin_debug, &spinlock_stats.taken); 401994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow", 0444, d_spin_debug, 402994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow); 403994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_nested", 0444, d_spin_debug, 404994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_nested); 405994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_pickup", 0444, d_spin_debug, 406994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_pickup); 407994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_spurious", 0444, d_spin_debug, 408994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_spurious); 4091e696f63SJeremy Fitzhardinge debugfs_create_u32("taken_slow_irqenable", 0444, d_spin_debug, 4101e696f63SJeremy Fitzhardinge &spinlock_stats.taken_slow_irqenable); 411994025caSJeremy Fitzhardinge 412994025caSJeremy Fitzhardinge debugfs_create_u64("released", 0444, d_spin_debug, &spinlock_stats.released); 413994025caSJeremy Fitzhardinge debugfs_create_u32("released_slow", 0444, d_spin_debug, 414994025caSJeremy Fitzhardinge &spinlock_stats.released_slow); 415994025caSJeremy Fitzhardinge debugfs_create_u32("released_slow_kicked", 0444, d_spin_debug, 416994025caSJeremy Fitzhardinge &spinlock_stats.released_slow_kicked); 417994025caSJeremy Fitzhardinge 418994025caSJeremy Fitzhardinge debugfs_create_u64("time_spinning", 0444, d_spin_debug, 419f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_spinning); 420f8eca41fSJeremy Fitzhardinge debugfs_create_u64("time_blocked", 0444, d_spin_debug, 421f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_blocked); 422994025caSJeremy Fitzhardinge debugfs_create_u64("time_total", 0444, d_spin_debug, 423f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_total); 424994025caSJeremy Fitzhardinge 425994025caSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_total", 0444, d_spin_debug, 426f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_total, HISTO_BUCKETS + 1); 427994025caSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_spinning", 0444, d_spin_debug, 428f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_spinning, HISTO_BUCKETS + 1); 429f8eca41fSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_blocked", 0444, d_spin_debug, 430f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_blocked, HISTO_BUCKETS + 1); 431994025caSJeremy Fitzhardinge 432994025caSJeremy Fitzhardinge return 0; 433994025caSJeremy Fitzhardinge } 434994025caSJeremy Fitzhardinge fs_initcall(xen_spinlock_debugfs); 435994025caSJeremy Fitzhardinge 436994025caSJeremy Fitzhardinge #endif /* CONFIG_XEN_DEBUG_FS */ 437