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 likely(x) (__builtin_expect(!!(x), 1))
17 #define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
18 #define SIZE_MAX (~(size_t)0)
20 typedef pthread_spinlock_t spinlock_t;
23 #define __GFP_ZERO 0x1
25 static void *kmalloc(unsigned size, gfp_t gfp)
27 void *p = memalign(64, size);
36 static inline void *kzalloc(unsigned size, gfp_t flags)
38 return kmalloc(size, flags | __GFP_ZERO);
41 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
43 if (size != 0 && n > SIZE_MAX / size)
45 return kmalloc(n * size, flags);
48 static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
50 return kmalloc_array(n, size, flags | __GFP_ZERO);
53 static void kfree(void *p)
59 static void spin_lock_init(spinlock_t *lock)
61 int r = pthread_spin_init(lock, 0);
65 static void spin_lock(spinlock_t *lock)
67 int ret = pthread_spin_lock(lock);
71 static void spin_unlock(spinlock_t *lock)
73 int ret = pthread_spin_unlock(lock);
77 static void spin_lock_bh(spinlock_t *lock)
82 static void spin_unlock_bh(spinlock_t *lock)
87 static void spin_lock_irq(spinlock_t *lock)
92 static void spin_unlock_irq(spinlock_t *lock)
97 static void spin_lock_irqsave(spinlock_t *lock, unsigned long f)
102 static void spin_unlock_irqrestore(spinlock_t *lock, unsigned long f)
107 #include "../../../include/linux/ptr_ring.h"
109 static unsigned long long headcnt, tailcnt;
110 static struct ptr_ring array ____cacheline_aligned_in_smp;
112 /* implemented by ring */
113 void alloc_ring(void)
115 int ret = ptr_ring_init(&array, ring_size, 0);
120 int add_inbuf(unsigned len, void *buf, void *datap)
124 ret = __ptr_ring_produce(&array, buf);
134 * ptr_ring API provides no way for producer to find out whether a given
135 * buffer was consumed. Our tests merely require that a successful get_buf
136 * implies that add_inbuf succeed in the past, and that add_inbuf will succeed,
137 * fake it accordingly.
139 void *get_buf(unsigned *lenp, void **bufp)
143 if (tailcnt == headcnt || __ptr_ring_full(&array))
155 return (tailcnt == headcnt || __ptr_ring_full(&array));
168 void kick_available(void)
186 return !__ptr_ring_peek(&array);
189 bool use_buf(unsigned *lenp, void **bufp)
193 ptr = __ptr_ring_consume(&array);