[DTrace-devel] [PATCH REVIEWED] Add 'lock xadd' BPF instruction macro

Kris Van Hees kris.van.hees at oracle.com
Mon Sep 14 12:50:33 PDT 2020


BPF implements an exclusive-add instruction to provide an atomic form
for:

	*(dst + offset) += (src)

This instruction was missing from the bpf_asm.h include file.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 include/bpf_asm.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/bpf_asm.h b/include/bpf_asm.h
index 59484697..cac60c24 100644
--- a/include/bpf_asm.h
+++ b/include/bpf_asm.h
@@ -91,6 +91,15 @@
 		.imm = 0						\
 	})
 
+#define BPF_XADD_REG(sz, dst, ofs, src)					\
+	((struct bpf_insn) {						\
+		.code = BPF_STX | BPF_XADD | (sz),			\
+		.dst_reg = (dst),					\
+		.src_reg = (src),					\
+		.off = (ofs),						\
+		.imm = 0						\
+	})
+
 #define BPF_STORE_IMM(sz, dst, ofs, val)				\
 	((struct bpf_insn) {						\
 		.code = BPF_ST | BPF_MEM | (sz),			\
-- 
2.28.0




More information about the DTrace-devel mailing list