Skip to content

Commit 1211f4e

Browse files
committed
Merge branch 'libbpf/xsk cleanups'
Björn Töpel says: ==================== This series removes a header dependency from xsk.h, and moves libbpf_util.h into xsk.h. More details in each commit! Thank you, Björn ==================== Signed-off-by: Andrii Nakryiko <[email protected]>
2 parents a9c80b0 + 7e8bbe2 commit 1211f4e

File tree

3 files changed

+68
-78
lines changed

3 files changed

+68
-78
lines changed

tools/lib/bpf/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ install_headers: $(BPF_HELPER_DEFS)
228228
$(call do_install,bpf.h,$(prefix)/include/bpf,644); \
229229
$(call do_install,libbpf.h,$(prefix)/include/bpf,644); \
230230
$(call do_install,btf.h,$(prefix)/include/bpf,644); \
231-
$(call do_install,libbpf_util.h,$(prefix)/include/bpf,644); \
232231
$(call do_install,libbpf_common.h,$(prefix)/include/bpf,644); \
233232
$(call do_install,xsk.h,$(prefix)/include/bpf,644); \
234233
$(call do_install,bpf_helpers.h,$(prefix)/include/bpf,644); \

tools/lib/bpf/libbpf_util.h

Lines changed: 0 additions & 75 deletions
This file was deleted.

tools/lib/bpf/xsk.h

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/*
44
* AF_XDP user-space access library.
55
*
6-
* Copyright(c) 2018 - 2019 Intel Corporation.
6+
* Copyright (c) 2018 - 2019 Intel Corporation.
7+
* Copyright (c) 2019 Facebook
78
*
89
* Author(s): Magnus Karlsson <[email protected]>
910
*/
@@ -13,15 +14,80 @@
1314

1415
#include <stdio.h>
1516
#include <stdint.h>
17+
#include <stdbool.h>
1618
#include <linux/if_xdp.h>
1719

1820
#include "libbpf.h"
19-
#include "libbpf_util.h"
2021

2122
#ifdef __cplusplus
2223
extern "C" {
2324
#endif
2425

26+
/* Load-Acquire Store-Release barriers used by the XDP socket
27+
* library. The following macros should *NOT* be considered part of
28+
* the xsk.h API, and is subject to change anytime.
29+
*
30+
* LIBRARY INTERNAL
31+
*/
32+
33+
#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
34+
#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
35+
36+
#if defined(__i386__) || defined(__x86_64__)
37+
# define libbpf_smp_store_release(p, v) \
38+
do { \
39+
asm volatile("" : : : "memory"); \
40+
__XSK_WRITE_ONCE(*p, v); \
41+
} while (0)
42+
# define libbpf_smp_load_acquire(p) \
43+
({ \
44+
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
45+
asm volatile("" : : : "memory"); \
46+
___p1; \
47+
})
48+
#elif defined(__aarch64__)
49+
# define libbpf_smp_store_release(p, v) \
50+
asm volatile ("stlr %w1, %0" : "=Q" (*p) : "r" (v) : "memory")
51+
# define libbpf_smp_load_acquire(p) \
52+
({ \
53+
typeof(*p) ___p1; \
54+
asm volatile ("ldar %w0, %1" \
55+
: "=r" (___p1) : "Q" (*p) : "memory"); \
56+
___p1; \
57+
})
58+
#elif defined(__riscv)
59+
# define libbpf_smp_store_release(p, v) \
60+
do { \
61+
asm volatile ("fence rw,w" : : : "memory"); \
62+
__XSK_WRITE_ONCE(*p, v); \
63+
} while (0)
64+
# define libbpf_smp_load_acquire(p) \
65+
({ \
66+
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
67+
asm volatile ("fence r,rw" : : : "memory"); \
68+
___p1; \
69+
})
70+
#endif
71+
72+
#ifndef libbpf_smp_store_release
73+
#define libbpf_smp_store_release(p, v) \
74+
do { \
75+
__sync_synchronize(); \
76+
__XSK_WRITE_ONCE(*p, v); \
77+
} while (0)
78+
#endif
79+
80+
#ifndef libbpf_smp_load_acquire
81+
#define libbpf_smp_load_acquire(p) \
82+
({ \
83+
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
84+
__sync_synchronize(); \
85+
___p1; \
86+
})
87+
#endif
88+
89+
/* LIBRARY INTERNAL -- END */
90+
2591
/* Do not access these members directly. Use the functions below. */
2692
#define DEFINE_XSK_RING(name) \
2793
struct name { \

0 commit comments

Comments
 (0)