-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
3 changed files
with
68 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
/* | ||
* AF_XDP user-space access library. | ||
* | ||
* Copyright(c) 2018 - 2019 Intel Corporation. | ||
* Copyright (c) 2018 - 2019 Intel Corporation. | ||
* Copyright (c) 2019 Facebook | ||
* | ||
* Author(s): Magnus Karlsson <[email protected]> | ||
*/ | ||
|
@@ -13,15 +14,80 @@ | |
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <linux/if_xdp.h> | ||
|
||
#include "libbpf.h" | ||
#include "libbpf_util.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Load-Acquire Store-Release barriers used by the XDP socket | ||
* library. The following macros should *NOT* be considered part of | ||
* the xsk.h API, and is subject to change anytime. | ||
* | ||
* LIBRARY INTERNAL | ||
*/ | ||
|
||
#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x) | ||
#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v) | ||
|
||
#if defined(__i386__) || defined(__x86_64__) | ||
# define libbpf_smp_store_release(p, v) \ | ||
do { \ | ||
asm volatile("" : : : "memory"); \ | ||
__XSK_WRITE_ONCE(*p, v); \ | ||
} while (0) | ||
# define libbpf_smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \ | ||
asm volatile("" : : : "memory"); \ | ||
___p1; \ | ||
}) | ||
#elif defined(__aarch64__) | ||
# define libbpf_smp_store_release(p, v) \ | ||
asm volatile ("stlr %w1, %0" : "=Q" (*p) : "r" (v) : "memory") | ||
# define libbpf_smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p1; \ | ||
asm volatile ("ldar %w0, %1" \ | ||
: "=r" (___p1) : "Q" (*p) : "memory"); \ | ||
___p1; \ | ||
}) | ||
#elif defined(__riscv) | ||
# define libbpf_smp_store_release(p, v) \ | ||
do { \ | ||
asm volatile ("fence rw,w" : : : "memory"); \ | ||
__XSK_WRITE_ONCE(*p, v); \ | ||
} while (0) | ||
# define libbpf_smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \ | ||
asm volatile ("fence r,rw" : : : "memory"); \ | ||
___p1; \ | ||
}) | ||
#endif | ||
|
||
#ifndef libbpf_smp_store_release | ||
#define libbpf_smp_store_release(p, v) \ | ||
do { \ | ||
__sync_synchronize(); \ | ||
__XSK_WRITE_ONCE(*p, v); \ | ||
} while (0) | ||
#endif | ||
|
||
#ifndef libbpf_smp_load_acquire | ||
#define libbpf_smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \ | ||
__sync_synchronize(); \ | ||
___p1; \ | ||
}) | ||
#endif | ||
|
||
/* LIBRARY INTERNAL -- END */ | ||
|
||
/* Do not access these members directly. Use the functions below. */ | ||
#define DEFINE_XSK_RING(name) \ | ||
struct name { \ | ||
|