1 // SPDX-License-Identifier: GPL-2.0
13 #define SMP_CACHE_BYTES 64
14 #define cache_line_size() SMP_CACHE_BYTES
15 #define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES)))
16 #define unlikely(x) (__builtin_expect(!!(x), 0))
17 #define likely(x) (__builtin_expect(!!(x), 1))
18 #define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
19 typedef pthread_spinlock_t spinlock_t
;
22 static void *kmalloc(unsigned size
, gfp_t gfp
)
24 return memalign(64, size
);
27 static void *kzalloc(unsigned size
, gfp_t gfp
)
29 void *p
= memalign(64, size
);
37 static void kfree(void *p
)
43 static void spin_lock_init(spinlock_t
*lock
)
45 int r
= pthread_spin_init(lock
, 0);
49 static void spin_lock(spinlock_t
*lock
)
51 int ret
= pthread_spin_lock(lock
);
55 static void spin_unlock(spinlock_t
*lock
)
57 int ret
= pthread_spin_unlock(lock
);
61 static void spin_lock_bh(spinlock_t
*lock
)
66 static void spin_unlock_bh(spinlock_t
*lock
)
71 static void spin_lock_irq(spinlock_t
*lock
)
76 static void spin_unlock_irq(spinlock_t
*lock
)
81 static void spin_lock_irqsave(spinlock_t
*lock
, unsigned long f
)
86 static void spin_unlock_irqrestore(spinlock_t
*lock
, unsigned long f
)
91 #include "../../../include/linux/ptr_ring.h"
93 static unsigned long long headcnt
, tailcnt
;
94 static struct ptr_ring array ____cacheline_aligned_in_smp
;
96 /* implemented by ring */
99 int ret
= ptr_ring_init(&array
, ring_size
, 0);
101 /* Hacky way to poke at ring internals. Useful for testing though. */
107 int add_inbuf(unsigned len
, void *buf
, void *datap
)
111 ret
= __ptr_ring_produce(&array
, buf
);
121 * ptr_ring API provides no way for producer to find out whether a given
122 * buffer was consumed. Our tests merely require that a successful get_buf
123 * implies that add_inbuf succeed in the past, and that add_inbuf will succeed,
124 * fake it accordingly.
126 void *get_buf(unsigned *lenp
, void **bufp
)
130 if (tailcnt
== headcnt
|| __ptr_ring_full(&array
))
142 return (tailcnt
== headcnt
|| __ptr_ring_full(&array
));
155 void kick_available(void)
173 return !__ptr_ring_peek(&array
);
176 bool use_buf(unsigned *lenp
, void **bufp
)
180 ptr
= __ptr_ring_consume(&array
);