[DTrace-devel] [PATCH] Rename struct dt_bpf_context to dt_dctx_t (and other cleanup)

Kris Van Hees kris.van.hees at oracle.com
Wed Jun 24 08:30:45 PDT 2020


Given that struct dt_bpf_context actually contains DTrace context data
rather than anything specific to BPF, dt_dctx_t seems to be a better
name.  It is also more consistent with the rest of the DTrace source
code that favours dt_*_t over struct dt_*.

The dt_bpf_ctx.h file has been renamed as dt_dctx.h.

This patch also changes:
  sizeof(((struct dt_bpf_context *)0)->argv) / 8
into
  ARRAY_SIZE(((dt_dctx_t *)0)->argv)
in order to get rid of the hardcoded argv element size (8 bytes).

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 bpf/get_bvar.c              |  4 ++--
 libdtrace/dt_bpf_ctx.h      | 33 ---------------------------------
 libdtrace/dt_cg.c           | 10 +++++-----
 libdtrace/dt_dctx.h         | 33 +++++++++++++++++++++++++++++++++
 libdtrace/dt_impl.h         |  2 +-
 libdtrace/dt_prov_dtrace.c  | 10 +++++-----
 libdtrace/dt_prov_fbt.c     | 10 +++++-----
 libdtrace/dt_prov_sdt.c     | 10 +++++-----
 libdtrace/dt_prov_syscall.c | 10 +++++-----
 9 files changed, 61 insertions(+), 61 deletions(-)
 delete mode 100644 libdtrace/dt_bpf_ctx.h
 create mode 100644 libdtrace/dt_dctx.h

diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
index 77e7fa12..f50ac55d 100644
--- a/bpf/get_bvar.c
+++ b/bpf/get_bvar.c
@@ -7,7 +7,7 @@
 #include <bpf-helpers.h>
 #include <dtrace/conf.h>
 #include <dtrace/dif_defines.h>
-#include <dt_bpf_ctx.h>
+#include <dt_dctx.h>
 
 #ifndef noinline
 # define noinline	__attribute__((noinline))
@@ -15,7 +15,7 @@
 
 extern struct bpf_map_def cpuinfo;
 
-noinline uint64_t dt_get_bvar(struct dt_bpf_context *dctx, uint32_t id)
+noinline uint64_t dt_get_bvar(dt_dctx_t *dctx, uint32_t id)
 {
 	switch (id) {
 	case DIF_VAR_CURTHREAD:
diff --git a/libdtrace/dt_bpf_ctx.h b/libdtrace/dt_bpf_ctx.h
deleted file mode 100644
index 906a8e95..00000000
--- a/libdtrace/dt_bpf_ctx.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- *
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
- */
-
-#ifndef _DT_BPF_CTX_H
-#define _DT_BPF_CTX_H
-
-#include <dt_pt_regs.h>
-
-/*
- * The DTrace BPF context.
- */
-struct dt_bpf_context {
-	uint32_t	epid;
-	uint32_t	pad;
-	uint64_t	fault;
-#if 0
-	dt_pt_regs	regs;
-#endif
-	uint64_t	argv[10];
-};
-
-#define DCTX_EPID	offsetof(struct dt_bpf_context, epid)
-#define DCTX_PAD	offsetof(struct dt_bpf_context, pad)
-#define DCTX_FAULT	offsetof(struct dt_bpf_context, fault)
-#define DCTX_REGS	offsetof(struct dt_bpf_context, regs)
-#define DCTX_ARG(n)	offsetof(struct dt_bpf_context, argv[n])
-#define DCTX_SIZE	sizeof(struct dt_bpf_context)
-
-#endif /* _DT_BPF_CTX_H */
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index d9f5733b..5844ea8a 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -59,7 +59,7 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
 	assert(mem != NULL);
 
 	/*
-	 * void dt_program(void *ctx, struct dt_bpf_context *dctx)
+	 * void dt_program(void *ctx, dt_dctx_t *dctx)
 	 * {
 	 *	int	rc;		// -- %r0
 	 *	int	key;		// -- [%fp + DT_STK_LVAR_BASE]
@@ -122,10 +122,10 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
 	dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
 
 	/*
-	 * We read the 32-bit epid from dctx (struct dt_bpf_context) and store
-	 * it at %r9 (base address of the trace data).  Next we store the
-	 * 32-bit tag (hardcoded as 0 for now), which leaves us at an 8-byte
-	 * boundary for actual probe data to be stored.
+	 * We read the 32-bit epid from dctx (dt_dctx_t) and store it at %r9
+	 * (base address of the trace data).  Next we store the 32-bit tag
+	 * (hardcoded as 0 for now), which leaves us at an 8-byte boundary for
+	 * actual probe data to be stored.
 	 *
 	 *	*((uint32_t *)&buf[0]) = this->dctx->epid;
 	 *				// lddw %r0, [%fp + DT_STK_DCTX]
diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
new file mode 100644
index 00000000..91b9cef3
--- /dev/null
+++ b/libdtrace/dt_dctx.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ *
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#ifndef _DT_DCTX_H
+#define _DT_DCTX_H
+
+#include <dt_pt_regs.h>
+
+/*
+ * The DTrace context.
+ */
+typedef struct dt_dctx {
+	uint32_t	epid;
+	uint32_t	pad;
+	uint64_t	fault;
+#if 0
+	dt_pt_regs	regs;
+#endif
+	uint64_t	argv[10];
+} dt_dctx_t;
+
+#define DCTX_EPID	offsetof(dt_dctx_t, epid)
+#define DCTX_PAD	offsetof(dt_dctx_t, pad)
+#define DCTX_FAULT	offsetof(dt_dctx_t, fault)
+#define DCTX_REGS	offsetof(dt_dctx_t, regs)
+#define DCTX_ARG(n)	offsetof(dt_dctx_t, argv[n])
+#define DCTX_SIZE	sizeof(dt_dctx_t)
+
+#endif /* _DT_DCTX_H */
diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
index e769dbbc..85f16915 100644
--- a/libdtrace/dt_impl.h
+++ b/libdtrace/dt_impl.h
@@ -49,7 +49,7 @@ extern "C" {
 #include <dt_pcb.h>
 #include <dt_pt_regs.h>
 #include <dt_printf.h>
-#include <dt_bpf_ctx.h>
+#include <dt_dctx.h>
 #include <dt_debug.h>
 #include <dt_version.h>
 
diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
index 4f3ad4eb..39a011ab 100644
--- a/libdtrace/dt_prov_dtrace.c
+++ b/libdtrace/dt_prov_dtrace.c
@@ -59,9 +59,9 @@ static int populate(dtrace_hdl_t *dtp)
  *
  *	int dt_dtrace(dt_pt_regs *regs)
  *
- * The trampoline will populate a dt_bpf_context struct and then call the
- * function that implements tha compiled D clause.  It returns the value that
- * it gets back from that function.
+ * The trampoline will populate a dt_dctx_t struct and then call the function
+ * that implements tha compiled D clause.  It returns the value that it gets
+ * back from that function.
  */
 static void trampoline(dt_pcb_t *pcb)
 {
@@ -76,7 +76,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 * int dt_dtrace(dt_pt_regs *regs)
 	 * {
-	 *     struct dt_bpf_context	dctx;
+	 *     dt_dctx_t	dctx;
 	 *
 	 *     memset(&dctx, 0, sizeof(dctx));
 	 *
@@ -142,7 +142,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 *     (we clear dctx.argv[6] and on because of the memset above)
 	 */
-	for (i = 6; i < sizeof(((struct dt_bpf_context *)0)->argv) / 8; i++) {
+	for (i = 6; i < ARRAY_SIZE(((dt_dctx_t *)0)->argv); i++) {
 		instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_ARG(i)),
 				      0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
diff --git a/libdtrace/dt_prov_fbt.c b/libdtrace/dt_prov_fbt.c
index 0efed358..3b5739e4 100644
--- a/libdtrace/dt_prov_fbt.c
+++ b/libdtrace/dt_prov_fbt.c
@@ -155,9 +155,9 @@ static int populate(dtrace_hdl_t *dtp)
  *
  *	int dt_fbt(dt_pt_regs *regs)
  *
- * The trampoline will populate a dt_bpf_context struct and then call the
- * function that implements tha compiled D clause.  It returns the value that
- * it gets back from that function.
+ * The trampoline will populate a dt_dctx_t struct and then call the function
+ * that implements tha compiled D clause.  It returns the value that it gets
+ * back from that function.
  */
 static void trampoline(dt_pcb_t *pcb)
 {
@@ -172,7 +172,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 * int dt_fbt(dt_pt_regs *regs)
 	 * {
-	 *     struct dt_bpf_context	dctx;
+	 *     dt_dctx_t	dctx;
 	 *
 	 *     memset(&dctx, 0, sizeof(dctx));
 	 *
@@ -238,7 +238,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 *     (we clear dctx.argv[6] and on because of the memset above)
 	 */
-	for (i = 6; i < sizeof(((struct dt_bpf_context *)0)->argv) / 8; i++) {
+	for (i = 6; i < ARRAY_SIZE(((dt_dctx_t *)0)->argv); i++) {
 		instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_ARG(i)),
 				      0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
diff --git a/libdtrace/dt_prov_sdt.c b/libdtrace/dt_prov_sdt.c
index 584291c8..1976c171 100644
--- a/libdtrace/dt_prov_sdt.c
+++ b/libdtrace/dt_prov_sdt.c
@@ -295,9 +295,9 @@ static int populate(dtrace_hdl_t *dtp)
  *
  *	int dt_sdt(struct syscall_data *scd)
  *
- * The trampoline will populate a dt_bpf_context struct and then call the
- * function that implements the compiled D clause.  It returns the value that
- * it gets back from that function.
+ * The trampoline will populate a dt_dctx_t struct and then call the function
+ * that implements the compiled D clause.  It returns the value that it gets
+ * back from that function.
  *
  * FIXME: Currently, access to arguments of the tracepoint is not supported.
  */
@@ -314,7 +314,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 * int dt_sdt(struct syscall_data *scd)
 	 * {
-	 *     struct dt_bpf_context	dctx;
+	 *     dt_dctx_t	dctx;
 	 *
 	 *     memset(&dctx, 0, sizeof(dctx));
 	 *
@@ -345,7 +345,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 *     (we clear dctx.argv[0] and on because of the memset above)
 	 */
-	for (i = 0; i < sizeof(((struct dt_bpf_context *)0)->argv) / 8; i++) {
+	for (i = 0; i < ARRAY_SIZE(((dt_dctx_t *)0)->argv); i++) {
 		instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_ARG(i)),
 				      0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
diff --git a/libdtrace/dt_prov_syscall.c b/libdtrace/dt_prov_syscall.c
index 16b18aa2..0f8856f4 100644
--- a/libdtrace/dt_prov_syscall.c
+++ b/libdtrace/dt_prov_syscall.c
@@ -139,9 +139,9 @@ static int populate(dtrace_hdl_t *dtp)
  *
  *	int dt_syscall(struct syscall_data *scd)
  *
- * The trampoline will populate a dt_bpf_context struct and then call the
- * function that implements the compiled D clause.  It returns the value that
- * it gets back from that function.
+ * The trampoline will populate a dt_dctx_t struct and then call the function
+ * that implements the compiled D clause.  It returns the value that it gets
+ * back from that function.
  */
 static void trampoline(dt_pcb_t *pcb)
 {
@@ -156,7 +156,7 @@ static void trampoline(dt_pcb_t *pcb)
 	/*
 	 * int dt_syscall(struct syscall_data *scd)
 	 * {
-	 *     struct dt_bpf_context	dctx;
+	 *     dt_dctx_t	dctx;
 	 *
 	 *     memset(&dctx, 0, sizeof(dctx));
 	 *
@@ -200,7 +200,7 @@ static void trampoline(dt_pcb_t *pcb)
 	 *     (we clear dctx.argv[6] and on because of the memset above)
 	 */
 	for (i = pcb->pcb_pinfo.dtp_argc;
-	     i < sizeof(((struct dt_bpf_context *)0)->argv) / 8; i++) {
+	     i < ARRAY_SIZE(((dt_dctx_t *)0)->argv); i++) {
 		instr = BPF_STORE_IMM(BPF_DW, BPF_REG_FP, DCTX_FP(DCTX_ARG(i)),
 				      0);
 		dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr));
-- 
2.26.0




More information about the DTrace-devel mailing list