[DTrace-devel] [PATCH] cg: wrap dctx and dctx->member accesses in a function

Nick Alcock nick.alcock at oracle.com
Thu Jan 11 17:35:04 UTC 2024


On 11 Jan 2024, Kris Van Hees via DTrace-devel spake thusly:

> Introduce dt_cg_access_dctx() to implement access to the DTrace context
> and members therein for both regular programs and trampolines.
>
> Replace
> 	BPF_LOAD(BPF_DW, <reg>, BPF_REG_FP, DT_STK_DCTX)
> 	BPF_LOAD(<size>, <reg>, <reg>, <member>)
> with
> 	dt_cg_access_dctx(<reg>, dlp, drp, <member>)
>
> Replace
> 	BPF_LOAD(BPF_DW, <reg>, BPF_REG_FP, DT_STK_DCTX)
> 	(not followed by access to a member of dctx)
> with
> 	dt_cg_access_dctx(<reg>, dlp, drp, -1)
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>

Yes!

Reviewed-by: Nick Alcock <nick.alcock at oracle.com>

with tiny nit below.

I wanted this for ages, but never wrote it because of...

> +	/*
> +	 * Regular programs get a pointer to the DTrace context from the stack.
> +	 * Trampolines have a pointer to the DTrace cotext in %r9.

"context"

> +	 */
> +	if (yypcb->pcb_root->dn_kind != DT_NODE_TRAMPOLINE) {
> +		emit(dlp,  BPF_LOAD(BPF_DW, ctxreg, BPF_REG_FP, DT_STK_DCTX));

... failing to realise how easy it was to detect trampolines, and being
unsatisfied about bloating them up with DCTX loads.

> -	emit(dlp,  BPF_LOAD(BPF_DW, reg, BPF_REG_FP, DT_STK_DCTX));
> -	emit(dlp,  BPF_LOAD(BPF_DW, reg, reg, DCTX_MST));
> +	dt_cg_access_dctx(reg, dlp, drp, DCTX_MST);

I mean it doesn't seem like too much code reduction, but it turns
emit(), which is always relatively opaque, into something that has an
actual *name*.



More information about the DTrace-devel mailing list