[DTrace-devel] [PATCH 31/61] Remove the "default tuple" area
eugene.loh at oracle.com
eugene.loh at oracle.com
Fri Jul 8 14:45:15 UTC 2022
From: Eugene Loh <eugene.loh at oracle.com>
All we need is a bunch of zeroes, which are available from the newly
introduced block of zeroes. Using that block is better because:
1) The new block is global, while the older area was per-CPU.
We only need one copy of this read-only memory.
2) The new block will be overlapped with other uses of zeroes.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_bpf.c | 4 ++++
libdtrace/dt_cg.c | 6 ++++--
libdtrace/dt_dctx.h | 16 ++++------------
3 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index ee9aa846..f0d1a99e 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -351,6 +351,10 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
if (pr_mapfd == -1)
return -1; /* dt_errno is set for us */
+ /* figure out how big the region of zeroes should be */
+ if (dtp->dt_zerosize < dtp->dt_maxtuplesize)
+ dtp->dt_zerosize = dtp->dt_maxtuplesize;
+
/* global variables, including a region of zeroes */
dtp->dt_zerooffset = P2ROUNDUP(dt_idhash_datasize(dtp->dt_globals), 8);
sz = dtp->dt_zerooffset + dtp->dt_zerosize;
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index f48452ee..11a9c8c5 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -2631,6 +2631,7 @@ dt_cg_arglist(dt_ident_t *idp, dt_node_t *args, dt_irlist_t *dlp,
const dt_idsig_t *isp = idp->di_data;
dt_node_t *dnp;
dt_ident_t *maxtupsz = dt_dlib_get_var(dtp, "TUPSZ");
+ dt_ident_t *zero_off = dt_dlib_get_var(dtp, "ZERO_OFF");
int i;
int treg, areg;
uint_t tuplesize;
@@ -2676,8 +2677,9 @@ dt_cg_arglist(dt_ident_t *idp, dt_node_t *args, dt_irlist_t *dlp,
emit(dlp, BPF_MOV_REG(BPF_REG_1, treg));
emite(dlp, BPF_MOV_IMM(BPF_REG_2, -1), maxtupsz);
- emit(dlp, BPF_MOV_REG(BPF_REG_3, BPF_REG_1));
- emite(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -1), maxtupsz);
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_3, BPF_REG_FP, DT_STK_DCTX));
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_3, BPF_REG_3, DCTX_GVARS));
+ emite(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -1), zero_off);
dt_regset_xalloc(drp, BPF_REG_0);
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_probe_read));
dt_regset_free_args(drp);
diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
index ea4758b6..c93fff2b 100644
--- a/libdtrace/dt_dctx.h
+++ b/libdtrace/dt_dctx.h
@@ -79,12 +79,10 @@ typedef struct dt_dctx {
* 0 -> | Stack : tstring | \
* | trace (shared) storage | |
* | storage : | |
- * +----------------+----------------+ |
- * DMEM_STRTOK -> | strtok() internal state | > DMEM_SIZE
+ * +----------------+----------------+ > DMEM_SIZE
+ * DMEM_STRTOK -> | strtok() internal state | |
* +---------------------------------+ |
- * DMEM_TUPLE -> | tuple assembly area | |
- * +---------------------------------+ |
- * DMEM_TUPLE_DFLT -> | default empty tuple | /
+ * DMEM_TUPLE -> | tuple assembly area | /
* +---------------------------------+
*/
@@ -107,17 +105,11 @@ typedef struct dt_dctx {
/*
* Macros to determine the offset of the components of dctx->mem.
- *
- * CAUTION: DMEM_TUPLE(dtp) and DMEM_TUPLE_DFLT(dtp) depend on data collected
- * during code generation and therefore cannot be used until all code
- * generation has completed.
*/
#define DMEM_STRTOK(dtp) \
MAX(DMEM_STACK_SZ(dtp), DMEM_TSTR_SZ(dtp))
#define DMEM_TUPLE(dtp) \
(DMEM_STRTOK(dtp) + DMEM_STRTOK_SZ(dtp))
-#define DMEM_TUPLE_DFLT(dtp) \
- (DMEM_TUPLE(dtp) + DMEM_TUPLE_SZ(dtp))
/*
* Macro to determine the total size of the mem area.
@@ -126,7 +118,7 @@ typedef struct dt_dctx {
* and therefore cannot be used until all code generation has
* completed.
*/
-#define DMEM_SIZE(dtp) (DMEM_TUPLE_DFLT(dtp) + DMEM_TUPLE_SZ(dtp))
+#define DMEM_SIZE(dtp) (DMEM_TUPLE(dtp) + DMEM_TUPLE_SZ(dtp))
/*
* The stack layout for BPF programs that are generated as trampolines for
--
2.18.4
More information about the DTrace-devel
mailing list