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> 9*5a0e3ad6STejun Heo #include <linux/gfp.h> 10d5de8841SJeremy Fitzhardinge 11d5de8841SJeremy Fitzhardinge #include <asm/paravirt.h> 12d5de8841SJeremy Fitzhardinge 13d5de8841SJeremy Fitzhardinge #include <xen/interface/xen.h> 14d5de8841SJeremy Fitzhardinge #include <xen/events.h> 15d5de8841SJeremy Fitzhardinge 16d5de8841SJeremy Fitzhardinge #include "xen-ops.h" 17994025caSJeremy Fitzhardinge #include "debugfs.h" 18994025caSJeremy Fitzhardinge 19994025caSJeremy Fitzhardinge #ifdef CONFIG_XEN_DEBUG_FS 20994025caSJeremy Fitzhardinge static struct xen_spinlock_stats 21994025caSJeremy Fitzhardinge { 22994025caSJeremy Fitzhardinge u64 taken; 23994025caSJeremy Fitzhardinge u32 taken_slow; 24994025caSJeremy Fitzhardinge u32 taken_slow_nested; 25994025caSJeremy Fitzhardinge u32 taken_slow_pickup; 26994025caSJeremy Fitzhardinge u32 taken_slow_spurious; 271e696f63SJeremy Fitzhardinge u32 taken_slow_irqenable; 28994025caSJeremy Fitzhardinge 29994025caSJeremy Fitzhardinge u64 released; 30994025caSJeremy Fitzhardinge u32 released_slow; 31994025caSJeremy Fitzhardinge u32 released_slow_kicked; 32994025caSJeremy Fitzhardinge 33f8eca41fSJeremy Fitzhardinge #define HISTO_BUCKETS 30 34f8eca41fSJeremy Fitzhardinge u32 histo_spin_total[HISTO_BUCKETS+1]; 35f8eca41fSJeremy Fitzhardinge u32 histo_spin_spinning[HISTO_BUCKETS+1]; 36f8eca41fSJeremy Fitzhardinge u32 histo_spin_blocked[HISTO_BUCKETS+1]; 37994025caSJeremy Fitzhardinge 38f8eca41fSJeremy Fitzhardinge u64 time_total; 39f8eca41fSJeremy Fitzhardinge u64 time_spinning; 40f8eca41fSJeremy Fitzhardinge u64 time_blocked; 41994025caSJeremy Fitzhardinge } spinlock_stats; 42994025caSJeremy Fitzhardinge 43994025caSJeremy Fitzhardinge static u8 zero_stats; 44994025caSJeremy Fitzhardinge 45994025caSJeremy Fitzhardinge static unsigned lock_timeout = 1 << 10; 46994025caSJeremy Fitzhardinge #define TIMEOUT lock_timeout 47994025caSJeremy Fitzhardinge 48994025caSJeremy Fitzhardinge static inline void check_zero(void) 49994025caSJeremy Fitzhardinge { 50994025caSJeremy Fitzhardinge if (unlikely(zero_stats)) { 51994025caSJeremy Fitzhardinge memset(&spinlock_stats, 0, sizeof(spinlock_stats)); 52994025caSJeremy Fitzhardinge zero_stats = 0; 53994025caSJeremy Fitzhardinge } 54994025caSJeremy Fitzhardinge } 55994025caSJeremy Fitzhardinge 56994025caSJeremy Fitzhardinge #define ADD_STATS(elem, val) \ 57994025caSJeremy Fitzhardinge do { check_zero(); spinlock_stats.elem += (val); } while(0) 58994025caSJeremy Fitzhardinge 59994025caSJeremy Fitzhardinge static inline u64 spin_time_start(void) 60994025caSJeremy Fitzhardinge { 61994025caSJeremy Fitzhardinge return xen_clocksource_read(); 62994025caSJeremy Fitzhardinge } 63994025caSJeremy Fitzhardinge 64994025caSJeremy Fitzhardinge static void __spin_time_accum(u64 delta, u32 *array) 65994025caSJeremy Fitzhardinge { 66994025caSJeremy Fitzhardinge unsigned index = ilog2(delta); 67994025caSJeremy Fitzhardinge 68994025caSJeremy Fitzhardinge check_zero(); 69994025caSJeremy Fitzhardinge 70994025caSJeremy Fitzhardinge if (index < HISTO_BUCKETS) 71994025caSJeremy Fitzhardinge array[index]++; 72994025caSJeremy Fitzhardinge else 73994025caSJeremy Fitzhardinge array[HISTO_BUCKETS]++; 74994025caSJeremy Fitzhardinge } 75994025caSJeremy Fitzhardinge 76f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_spinning(u64 start) 77994025caSJeremy Fitzhardinge { 78994025caSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 79994025caSJeremy Fitzhardinge 80f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_spinning); 81f8eca41fSJeremy Fitzhardinge spinlock_stats.time_spinning += delta; 82994025caSJeremy Fitzhardinge } 83994025caSJeremy Fitzhardinge 84f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_total(u64 start) 85994025caSJeremy Fitzhardinge { 86994025caSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 87994025caSJeremy Fitzhardinge 88f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_total); 89f8eca41fSJeremy Fitzhardinge spinlock_stats.time_total += delta; 90f8eca41fSJeremy Fitzhardinge } 91f8eca41fSJeremy Fitzhardinge 92f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_blocked(u64 start) 93f8eca41fSJeremy Fitzhardinge { 94f8eca41fSJeremy Fitzhardinge u32 delta = xen_clocksource_read() - start; 95f8eca41fSJeremy Fitzhardinge 96f8eca41fSJeremy Fitzhardinge __spin_time_accum(delta, spinlock_stats.histo_spin_blocked); 97f8eca41fSJeremy Fitzhardinge spinlock_stats.time_blocked += delta; 98994025caSJeremy Fitzhardinge } 99994025caSJeremy Fitzhardinge #else /* !CONFIG_XEN_DEBUG_FS */ 100994025caSJeremy Fitzhardinge #define TIMEOUT (1 << 10) 101994025caSJeremy Fitzhardinge #define ADD_STATS(elem, val) do { (void)(val); } while(0) 102994025caSJeremy Fitzhardinge 103994025caSJeremy Fitzhardinge static inline u64 spin_time_start(void) 104994025caSJeremy Fitzhardinge { 105994025caSJeremy Fitzhardinge return 0; 106994025caSJeremy Fitzhardinge } 107994025caSJeremy Fitzhardinge 108f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_total(u64 start) 109994025caSJeremy Fitzhardinge { 110994025caSJeremy Fitzhardinge } 111f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_spinning(u64 start) 112f8eca41fSJeremy Fitzhardinge { 113f8eca41fSJeremy Fitzhardinge } 114f8eca41fSJeremy Fitzhardinge static inline void spin_time_accum_blocked(u64 start) 115994025caSJeremy Fitzhardinge { 116994025caSJeremy Fitzhardinge } 117994025caSJeremy Fitzhardinge #endif /* CONFIG_XEN_DEBUG_FS */ 118d5de8841SJeremy Fitzhardinge 119d5de8841SJeremy Fitzhardinge struct xen_spinlock { 120d5de8841SJeremy Fitzhardinge unsigned char lock; /* 0 -> free; 1 -> locked */ 121d5de8841SJeremy Fitzhardinge unsigned short spinners; /* count of waiting cpus */ 122d5de8841SJeremy Fitzhardinge }; 123d5de8841SJeremy Fitzhardinge 124445c8951SThomas Gleixner static int xen_spin_is_locked(struct arch_spinlock *lock) 125d5de8841SJeremy Fitzhardinge { 126d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 127d5de8841SJeremy Fitzhardinge 128d5de8841SJeremy Fitzhardinge return xl->lock != 0; 129d5de8841SJeremy Fitzhardinge } 130d5de8841SJeremy Fitzhardinge 131445c8951SThomas Gleixner static int xen_spin_is_contended(struct arch_spinlock *lock) 132d5de8841SJeremy Fitzhardinge { 133d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 134d5de8841SJeremy Fitzhardinge 135d5de8841SJeremy Fitzhardinge /* Not strictly true; this is only the count of contended 136d5de8841SJeremy Fitzhardinge lock-takers entering the slow path. */ 137d5de8841SJeremy Fitzhardinge return xl->spinners != 0; 138d5de8841SJeremy Fitzhardinge } 139d5de8841SJeremy Fitzhardinge 140445c8951SThomas Gleixner static int xen_spin_trylock(struct arch_spinlock *lock) 141d5de8841SJeremy Fitzhardinge { 142d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 143d5de8841SJeremy Fitzhardinge u8 old = 1; 144d5de8841SJeremy Fitzhardinge 145d5de8841SJeremy Fitzhardinge asm("xchgb %b0,%1" 146d5de8841SJeremy Fitzhardinge : "+q" (old), "+m" (xl->lock) : : "memory"); 147d5de8841SJeremy Fitzhardinge 148d5de8841SJeremy Fitzhardinge return old == 0; 149d5de8841SJeremy Fitzhardinge } 150d5de8841SJeremy Fitzhardinge 151d5de8841SJeremy Fitzhardinge static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; 152d5de8841SJeremy Fitzhardinge static DEFINE_PER_CPU(struct xen_spinlock *, lock_spinners); 153d5de8841SJeremy Fitzhardinge 154168d2f46SJeremy Fitzhardinge /* 155168d2f46SJeremy Fitzhardinge * Mark a cpu as interested in a lock. Returns the CPU's previous 156168d2f46SJeremy Fitzhardinge * lock of interest, in case we got preempted by an interrupt. 157168d2f46SJeremy Fitzhardinge */ 158168d2f46SJeremy Fitzhardinge static inline struct xen_spinlock *spinning_lock(struct xen_spinlock *xl) 159d5de8841SJeremy Fitzhardinge { 160168d2f46SJeremy Fitzhardinge struct xen_spinlock *prev; 161168d2f46SJeremy Fitzhardinge 162168d2f46SJeremy Fitzhardinge prev = __get_cpu_var(lock_spinners); 163d5de8841SJeremy Fitzhardinge __get_cpu_var(lock_spinners) = xl; 164168d2f46SJeremy Fitzhardinge 165d5de8841SJeremy Fitzhardinge wmb(); /* set lock of interest before count */ 166168d2f46SJeremy Fitzhardinge 167d5de8841SJeremy Fitzhardinge asm(LOCK_PREFIX " incw %0" 168d5de8841SJeremy Fitzhardinge : "+m" (xl->spinners) : : "memory"); 169168d2f46SJeremy Fitzhardinge 170168d2f46SJeremy Fitzhardinge return prev; 171d5de8841SJeremy Fitzhardinge } 172d5de8841SJeremy Fitzhardinge 173168d2f46SJeremy Fitzhardinge /* 174168d2f46SJeremy Fitzhardinge * Mark a cpu as no longer interested in a lock. Restores previous 175168d2f46SJeremy Fitzhardinge * lock of interest (NULL for none). 176168d2f46SJeremy Fitzhardinge */ 177168d2f46SJeremy Fitzhardinge static inline void unspinning_lock(struct xen_spinlock *xl, struct xen_spinlock *prev) 178d5de8841SJeremy Fitzhardinge { 179d5de8841SJeremy Fitzhardinge asm(LOCK_PREFIX " decw %0" 180d5de8841SJeremy Fitzhardinge : "+m" (xl->spinners) : : "memory"); 181168d2f46SJeremy Fitzhardinge wmb(); /* decrement count before restoring lock */ 182168d2f46SJeremy Fitzhardinge __get_cpu_var(lock_spinners) = prev; 183d5de8841SJeremy Fitzhardinge } 184d5de8841SJeremy Fitzhardinge 185445c8951SThomas Gleixner static noinline int xen_spin_lock_slow(struct arch_spinlock *lock, bool irq_enable) 186d5de8841SJeremy Fitzhardinge { 187d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 188168d2f46SJeremy Fitzhardinge struct xen_spinlock *prev; 189d5de8841SJeremy Fitzhardinge int irq = __get_cpu_var(lock_kicker_irq); 190d5de8841SJeremy Fitzhardinge int ret; 191f8eca41fSJeremy Fitzhardinge u64 start; 192d5de8841SJeremy Fitzhardinge 193d5de8841SJeremy Fitzhardinge /* If kicker interrupts not initialized yet, just spin */ 194d5de8841SJeremy Fitzhardinge if (irq == -1) 195d5de8841SJeremy Fitzhardinge return 0; 196d5de8841SJeremy Fitzhardinge 197f8eca41fSJeremy Fitzhardinge start = spin_time_start(); 198f8eca41fSJeremy Fitzhardinge 199d5de8841SJeremy Fitzhardinge /* announce we're spinning */ 200168d2f46SJeremy Fitzhardinge prev = spinning_lock(xl); 201d5de8841SJeremy Fitzhardinge 202994025caSJeremy Fitzhardinge ADD_STATS(taken_slow, 1); 203994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_nested, prev != NULL); 204994025caSJeremy Fitzhardinge 205168d2f46SJeremy Fitzhardinge do { 2064d576b57SJeremy Fitzhardinge unsigned long flags; 2074d576b57SJeremy Fitzhardinge 208d5de8841SJeremy Fitzhardinge /* clear pending */ 209d5de8841SJeremy Fitzhardinge xen_clear_irq_pending(irq); 210d5de8841SJeremy Fitzhardinge 211d5de8841SJeremy Fitzhardinge /* check again make sure it didn't become free while 212d5de8841SJeremy Fitzhardinge we weren't looking */ 213d5de8841SJeremy Fitzhardinge ret = xen_spin_trylock(lock); 214168d2f46SJeremy Fitzhardinge if (ret) { 215994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_pickup, 1); 216994025caSJeremy Fitzhardinge 217168d2f46SJeremy Fitzhardinge /* 218168d2f46SJeremy Fitzhardinge * If we interrupted another spinlock while it 219168d2f46SJeremy Fitzhardinge * was blocking, make sure it doesn't block 220168d2f46SJeremy Fitzhardinge * without rechecking the lock. 221168d2f46SJeremy Fitzhardinge */ 222168d2f46SJeremy Fitzhardinge if (prev != NULL) 223168d2f46SJeremy Fitzhardinge xen_set_irq_pending(irq); 224d5de8841SJeremy Fitzhardinge goto out; 225168d2f46SJeremy Fitzhardinge } 226d5de8841SJeremy Fitzhardinge 2274d576b57SJeremy Fitzhardinge flags = __raw_local_save_flags(); 2284d576b57SJeremy Fitzhardinge if (irq_enable) { 2294d576b57SJeremy Fitzhardinge ADD_STATS(taken_slow_irqenable, 1); 2304d576b57SJeremy Fitzhardinge raw_local_irq_enable(); 2314d576b57SJeremy Fitzhardinge } 2324d576b57SJeremy Fitzhardinge 233168d2f46SJeremy Fitzhardinge /* 234168d2f46SJeremy Fitzhardinge * Block until irq becomes pending. If we're 235168d2f46SJeremy Fitzhardinge * interrupted at this point (after the trylock but 236168d2f46SJeremy Fitzhardinge * before entering the block), then the nested lock 237168d2f46SJeremy Fitzhardinge * handler guarantees that the irq will be left 238168d2f46SJeremy Fitzhardinge * pending if there's any chance the lock became free; 239168d2f46SJeremy Fitzhardinge * xen_poll_irq() returns immediately if the irq is 240168d2f46SJeremy Fitzhardinge * pending. 241168d2f46SJeremy Fitzhardinge */ 242d5de8841SJeremy Fitzhardinge xen_poll_irq(irq); 2434d576b57SJeremy Fitzhardinge 2444d576b57SJeremy Fitzhardinge raw_local_irq_restore(flags); 2454d576b57SJeremy Fitzhardinge 246994025caSJeremy Fitzhardinge ADD_STATS(taken_slow_spurious, !xen_test_irq_pending(irq)); 247168d2f46SJeremy Fitzhardinge } while (!xen_test_irq_pending(irq)); /* check for spurious wakeups */ 248168d2f46SJeremy Fitzhardinge 249d6c88a50SThomas Gleixner kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq)); 250d5de8841SJeremy Fitzhardinge 251d5de8841SJeremy Fitzhardinge out: 252168d2f46SJeremy Fitzhardinge unspinning_lock(xl, prev); 253f8eca41fSJeremy Fitzhardinge spin_time_accum_blocked(start); 254f8eca41fSJeremy Fitzhardinge 255d5de8841SJeremy Fitzhardinge return ret; 256d5de8841SJeremy Fitzhardinge } 257d5de8841SJeremy Fitzhardinge 258445c8951SThomas Gleixner static inline void __xen_spin_lock(struct arch_spinlock *lock, bool irq_enable) 259d5de8841SJeremy Fitzhardinge { 260d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 261994025caSJeremy Fitzhardinge unsigned timeout; 262d5de8841SJeremy Fitzhardinge u8 oldval; 263994025caSJeremy Fitzhardinge u64 start_spin; 264994025caSJeremy Fitzhardinge 265994025caSJeremy Fitzhardinge ADD_STATS(taken, 1); 266994025caSJeremy Fitzhardinge 267994025caSJeremy Fitzhardinge start_spin = spin_time_start(); 268d5de8841SJeremy Fitzhardinge 269d5de8841SJeremy Fitzhardinge do { 270994025caSJeremy Fitzhardinge u64 start_spin_fast = spin_time_start(); 271994025caSJeremy Fitzhardinge 272994025caSJeremy Fitzhardinge timeout = TIMEOUT; 273d5de8841SJeremy Fitzhardinge 274d5de8841SJeremy Fitzhardinge asm("1: xchgb %1,%0\n" 275d5de8841SJeremy Fitzhardinge " testb %1,%1\n" 276d5de8841SJeremy Fitzhardinge " jz 3f\n" 277d5de8841SJeremy Fitzhardinge "2: rep;nop\n" 278d5de8841SJeremy Fitzhardinge " cmpb $0,%0\n" 279d5de8841SJeremy Fitzhardinge " je 1b\n" 280d5de8841SJeremy Fitzhardinge " dec %2\n" 281d5de8841SJeremy Fitzhardinge " jnz 2b\n" 282d5de8841SJeremy Fitzhardinge "3:\n" 283d5de8841SJeremy Fitzhardinge : "+m" (xl->lock), "=q" (oldval), "+r" (timeout) 284d5de8841SJeremy Fitzhardinge : "1" (1) 285d5de8841SJeremy Fitzhardinge : "memory"); 286d5de8841SJeremy Fitzhardinge 287f8eca41fSJeremy Fitzhardinge spin_time_accum_spinning(start_spin_fast); 2881e696f63SJeremy Fitzhardinge 2891e696f63SJeremy Fitzhardinge } while (unlikely(oldval != 0 && 2901e696f63SJeremy Fitzhardinge (TIMEOUT == ~0 || !xen_spin_lock_slow(lock, irq_enable)))); 291994025caSJeremy Fitzhardinge 292f8eca41fSJeremy Fitzhardinge spin_time_accum_total(start_spin); 293d5de8841SJeremy Fitzhardinge } 294d5de8841SJeremy Fitzhardinge 295445c8951SThomas Gleixner static void xen_spin_lock(struct arch_spinlock *lock) 2961e696f63SJeremy Fitzhardinge { 2971e696f63SJeremy Fitzhardinge __xen_spin_lock(lock, false); 2981e696f63SJeremy Fitzhardinge } 2991e696f63SJeremy Fitzhardinge 300445c8951SThomas Gleixner static void xen_spin_lock_flags(struct arch_spinlock *lock, unsigned long flags) 3011e696f63SJeremy Fitzhardinge { 3021e696f63SJeremy Fitzhardinge __xen_spin_lock(lock, !raw_irqs_disabled_flags(flags)); 3031e696f63SJeremy Fitzhardinge } 3041e696f63SJeremy Fitzhardinge 305d5de8841SJeremy Fitzhardinge static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) 306d5de8841SJeremy Fitzhardinge { 307d5de8841SJeremy Fitzhardinge int cpu; 308d5de8841SJeremy Fitzhardinge 309994025caSJeremy Fitzhardinge ADD_STATS(released_slow, 1); 310994025caSJeremy Fitzhardinge 311d5de8841SJeremy Fitzhardinge for_each_online_cpu(cpu) { 312d5de8841SJeremy Fitzhardinge /* XXX should mix up next cpu selection */ 313d5de8841SJeremy Fitzhardinge if (per_cpu(lock_spinners, cpu) == xl) { 314994025caSJeremy Fitzhardinge ADD_STATS(released_slow_kicked, 1); 315d5de8841SJeremy Fitzhardinge xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); 316d5de8841SJeremy Fitzhardinge break; 317d5de8841SJeremy Fitzhardinge } 318d5de8841SJeremy Fitzhardinge } 319d5de8841SJeremy Fitzhardinge } 320d5de8841SJeremy Fitzhardinge 321445c8951SThomas Gleixner static void xen_spin_unlock(struct arch_spinlock *lock) 322d5de8841SJeremy Fitzhardinge { 323d5de8841SJeremy Fitzhardinge struct xen_spinlock *xl = (struct xen_spinlock *)lock; 324d5de8841SJeremy Fitzhardinge 325994025caSJeremy Fitzhardinge ADD_STATS(released, 1); 326994025caSJeremy Fitzhardinge 327d5de8841SJeremy Fitzhardinge smp_wmb(); /* make sure no writes get moved after unlock */ 328d5de8841SJeremy Fitzhardinge xl->lock = 0; /* release lock */ 329d5de8841SJeremy Fitzhardinge 3302496afbfSYang Xiaowei /* 3312496afbfSYang Xiaowei * Make sure unlock happens before checking for waiting 3322496afbfSYang Xiaowei * spinners. We need a strong barrier to enforce the 3332496afbfSYang Xiaowei * write-read ordering to different memory locations, as the 3342496afbfSYang Xiaowei * CPU makes no implied guarantees about their ordering. 3352496afbfSYang Xiaowei */ 3362496afbfSYang Xiaowei mb(); 337d5de8841SJeremy Fitzhardinge 338d5de8841SJeremy Fitzhardinge if (unlikely(xl->spinners)) 339d5de8841SJeremy Fitzhardinge xen_spin_unlock_slow(xl); 340d5de8841SJeremy Fitzhardinge } 341d5de8841SJeremy Fitzhardinge 342d5de8841SJeremy Fitzhardinge static irqreturn_t dummy_handler(int irq, void *dev_id) 343d5de8841SJeremy Fitzhardinge { 344d5de8841SJeremy Fitzhardinge BUG(); 345d5de8841SJeremy Fitzhardinge return IRQ_HANDLED; 346d5de8841SJeremy Fitzhardinge } 347d5de8841SJeremy Fitzhardinge 348d5de8841SJeremy Fitzhardinge void __cpuinit xen_init_lock_cpu(int cpu) 349d5de8841SJeremy Fitzhardinge { 350d5de8841SJeremy Fitzhardinge int irq; 351d5de8841SJeremy Fitzhardinge const char *name; 352d5de8841SJeremy Fitzhardinge 353d5de8841SJeremy Fitzhardinge name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 354d5de8841SJeremy Fitzhardinge irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 355d5de8841SJeremy Fitzhardinge cpu, 356d5de8841SJeremy Fitzhardinge dummy_handler, 357d5de8841SJeremy Fitzhardinge IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING, 358d5de8841SJeremy Fitzhardinge name, 359d5de8841SJeremy Fitzhardinge NULL); 360d5de8841SJeremy Fitzhardinge 361d5de8841SJeremy Fitzhardinge if (irq >= 0) { 362d5de8841SJeremy Fitzhardinge disable_irq(irq); /* make sure it's never delivered */ 363d5de8841SJeremy Fitzhardinge per_cpu(lock_kicker_irq, cpu) = irq; 364d5de8841SJeremy Fitzhardinge } 365d5de8841SJeremy Fitzhardinge 366d5de8841SJeremy Fitzhardinge printk("cpu %d spinlock event irq %d\n", cpu, irq); 367d5de8841SJeremy Fitzhardinge } 368d5de8841SJeremy Fitzhardinge 369d68d82afSAlex Nixon void xen_uninit_lock_cpu(int cpu) 370d68d82afSAlex Nixon { 371d68d82afSAlex Nixon unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL); 372d68d82afSAlex Nixon } 373d68d82afSAlex Nixon 374d5de8841SJeremy Fitzhardinge void __init xen_init_spinlocks(void) 375d5de8841SJeremy Fitzhardinge { 376d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_is_locked = xen_spin_is_locked; 377d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_is_contended = xen_spin_is_contended; 378d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_lock = xen_spin_lock; 3791e696f63SJeremy Fitzhardinge pv_lock_ops.spin_lock_flags = xen_spin_lock_flags; 380d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_trylock = xen_spin_trylock; 381d5de8841SJeremy Fitzhardinge pv_lock_ops.spin_unlock = xen_spin_unlock; 382d5de8841SJeremy Fitzhardinge } 383994025caSJeremy Fitzhardinge 384994025caSJeremy Fitzhardinge #ifdef CONFIG_XEN_DEBUG_FS 385994025caSJeremy Fitzhardinge 386994025caSJeremy Fitzhardinge static struct dentry *d_spin_debug; 387994025caSJeremy Fitzhardinge 388994025caSJeremy Fitzhardinge static int __init xen_spinlock_debugfs(void) 389994025caSJeremy Fitzhardinge { 390994025caSJeremy Fitzhardinge struct dentry *d_xen = xen_init_debugfs(); 391994025caSJeremy Fitzhardinge 392994025caSJeremy Fitzhardinge if (d_xen == NULL) 393994025caSJeremy Fitzhardinge return -ENOMEM; 394994025caSJeremy Fitzhardinge 395994025caSJeremy Fitzhardinge d_spin_debug = debugfs_create_dir("spinlocks", d_xen); 396994025caSJeremy Fitzhardinge 397994025caSJeremy Fitzhardinge debugfs_create_u8("zero_stats", 0644, d_spin_debug, &zero_stats); 398994025caSJeremy Fitzhardinge 399994025caSJeremy Fitzhardinge debugfs_create_u32("timeout", 0644, d_spin_debug, &lock_timeout); 400994025caSJeremy Fitzhardinge 401994025caSJeremy Fitzhardinge debugfs_create_u64("taken", 0444, d_spin_debug, &spinlock_stats.taken); 402994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow", 0444, d_spin_debug, 403994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow); 404994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_nested", 0444, d_spin_debug, 405994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_nested); 406994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_pickup", 0444, d_spin_debug, 407994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_pickup); 408994025caSJeremy Fitzhardinge debugfs_create_u32("taken_slow_spurious", 0444, d_spin_debug, 409994025caSJeremy Fitzhardinge &spinlock_stats.taken_slow_spurious); 4101e696f63SJeremy Fitzhardinge debugfs_create_u32("taken_slow_irqenable", 0444, d_spin_debug, 4111e696f63SJeremy Fitzhardinge &spinlock_stats.taken_slow_irqenable); 412994025caSJeremy Fitzhardinge 413994025caSJeremy Fitzhardinge debugfs_create_u64("released", 0444, d_spin_debug, &spinlock_stats.released); 414994025caSJeremy Fitzhardinge debugfs_create_u32("released_slow", 0444, d_spin_debug, 415994025caSJeremy Fitzhardinge &spinlock_stats.released_slow); 416994025caSJeremy Fitzhardinge debugfs_create_u32("released_slow_kicked", 0444, d_spin_debug, 417994025caSJeremy Fitzhardinge &spinlock_stats.released_slow_kicked); 418994025caSJeremy Fitzhardinge 419994025caSJeremy Fitzhardinge debugfs_create_u64("time_spinning", 0444, d_spin_debug, 420f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_spinning); 421f8eca41fSJeremy Fitzhardinge debugfs_create_u64("time_blocked", 0444, d_spin_debug, 422f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_blocked); 423994025caSJeremy Fitzhardinge debugfs_create_u64("time_total", 0444, d_spin_debug, 424f8eca41fSJeremy Fitzhardinge &spinlock_stats.time_total); 425994025caSJeremy Fitzhardinge 426994025caSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_total", 0444, d_spin_debug, 427f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_total, HISTO_BUCKETS + 1); 428994025caSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_spinning", 0444, d_spin_debug, 429f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_spinning, HISTO_BUCKETS + 1); 430f8eca41fSJeremy Fitzhardinge xen_debugfs_create_u32_array("histo_blocked", 0444, d_spin_debug, 431f8eca41fSJeremy Fitzhardinge spinlock_stats.histo_spin_blocked, HISTO_BUCKETS + 1); 432994025caSJeremy Fitzhardinge 433994025caSJeremy Fitzhardinge return 0; 434994025caSJeremy Fitzhardinge } 435994025caSJeremy Fitzhardinge fs_initcall(xen_spinlock_debugfs); 436994025caSJeremy Fitzhardinge 437994025caSJeremy Fitzhardinge #endif /* CONFIG_XEN_DEBUG_FS */ 438