12 #define SMP_CACHE_BYTES 64
13 #define cache_line_size() SMP_CACHE_BYTES
14 #define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES)))
15 #define unlikely(x) (__builtin_expect(!!(x), 0))
16 #define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
17 typedef pthread_spinlock_t spinlock_t;
20 static void *kmalloc(unsigned size, gfp_t gfp)
22 return memalign(64, size);
25 static void *kzalloc(unsigned size, gfp_t gfp)
27 void *p = memalign(64, size);
35 static void kfree(void *p)
41 static void spin_lock_init(spinlock_t *lock)
43 int r = pthread_spin_init(lock, 0);
47 static void spin_lock(spinlock_t *lock)
49 int ret = pthread_spin_lock(lock);
53 static void spin_unlock(spinlock_t *lock)
55 int ret = pthread_spin_unlock(lock);
59 static void spin_lock_bh(spinlock_t *lock)
64 static void spin_unlock_bh(spinlock_t *lock)
69 static void spin_lock_irq(spinlock_t *lock)
74 static void spin_unlock_irq(spinlock_t *lock)
79 static void spin_lock_irqsave(spinlock_t *lock, unsigned long f)
84 static void spin_unlock_irqrestore(spinlock_t *lock, unsigned long f)
89 #include "../../../include/linux/ptr_ring.h"
91 static unsigned long long headcnt, tailcnt;
92 static struct ptr_ring array ____cacheline_aligned_in_smp;
94 /* implemented by ring */
97 int ret = ptr_ring_init(&array, ring_size, 0);
102 int add_inbuf(unsigned len, void *buf, void *datap)
106 ret = __ptr_ring_produce(&array, buf);
116 * ptr_ring API provides no way for producer to find out whether a given
117 * buffer was consumed. Our tests merely require that a successful get_buf
118 * implies that add_inbuf succeed in the past, and that add_inbuf will succeed,
119 * fake it accordingly.
121 void *get_buf(unsigned *lenp, void **bufp)
125 if (tailcnt == headcnt || __ptr_ring_full(&array))
140 if (tailcnt == headcnt || __ptr_ring_full(&array)) {
159 void kick_available(void)
175 void poll_avail(void)
181 b = __ptr_ring_peek(&array);
185 bool use_buf(unsigned *lenp, void **bufp)
189 ptr = __ptr_ring_consume(&array);