Skip to content

Commit

Permalink
Record clause id in mstate
Browse files Browse the repository at this point in the history
Support for the ERROR probe requires a per-probe unique id to identify
the clause the ERROR probe was triggered from.  Add a clid member to
the machine state, and initialize it in the prologue.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Feb 8, 2021
1 parent 1c789f4 commit 4351e01
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
7 changes: 4 additions & 3 deletions libdtrace/dt_bpf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand All @@ -19,8 +19,9 @@ extern "C" {
#endif

#define DT_CONST_EPID 1
#define DT_CONST_ARGC 2
#define DT_CONST_PRID 3
#define DT_CONST_PRID 2
#define DT_CONST_CLID 3
#define DT_CONST_ARGC 4

extern int perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu,
int group_fd, unsigned long flags);
Expand Down
16 changes: 11 additions & 5 deletions libdtrace/dt_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,8 @@ dt_link_layout(dtrace_hdl_t *dtp, const dtrace_difo_t *dp, uint_t *pcp,
static int
dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
const dtrace_difo_t *sdp, dt_strtab_t *stab,
uint_t *pcp, uint_t *rcp, uint_t *vcp, dtrace_epid_t epid)
uint_t *pcp, uint_t *rcp, uint_t *vcp, dtrace_epid_t epid,
uint_t clid)
{
uint_t pc = *pcp;
uint_t rc = *rcp;
Expand Down Expand Up @@ -2412,6 +2413,9 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
case DT_CONST_PRID:
nrp->dofr_data = prp->desc->id;
break;
case DT_CONST_CLID:
nrp->dofr_data = clid;
break;
case DT_CONST_ARGC:
nrp->dofr_data = 0; /* FIXME */
break;
Expand All @@ -2427,13 +2431,14 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
rdp = dt_dlib_get_func_difo(dtp, idp);
if (rdp == NULL)
return -1;
if (rdp->dtdo_ddesc != NULL)
if (rdp->dtdo_ddesc != NULL) {
nepid = dt_epid_add(dtp, rdp->dtdo_ddesc,
prp->desc->id);
else
clid++;
} else
nepid = 0;
ipc = dt_link_construct(dtp, prp, dp, rdp, stab,
pcp, rcp, vcp, nepid);
pcp, rcp, vcp, nepid, clid);
if (ipc == -1)
return -1;

Expand Down Expand Up @@ -2543,7 +2548,8 @@ dt_link(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp)
if (stab == NULL)
goto nomem;

rc = dt_link_construct(dtp, prp, fdp, dp, stab, &insc, &relc, &varc, 0);
rc = dt_link_construct(dtp, prp, fdp, dp, stab, &insc, &relc, &varc,
0, 0);
dt_dlib_reset(dtp, B_FALSE);
if (rc == -1)
goto fail;
Expand Down
4 changes: 4 additions & 0 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
dt_irlist_t *dlp = &pcb->pcb_ir;
dt_ident_t *epid = dt_dlib_get_var(pcb->pcb_hdl, "EPID");
dt_ident_t *prid = dt_dlib_get_var(pcb->pcb_hdl, "PRID");
dt_ident_t *clid = dt_dlib_get_var(pcb->pcb_hdl, "CLID");

assert(epid != NULL);
assert(prid != NULL);
assert(clid != NULL);

/*
* void dt_program(dt_dctx_t *dctx)
Expand All @@ -292,6 +294,7 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
* dctx->mst->tstamp = 0; // stdw [%r0 + DMST_TSTAMP], 0
* dctx->mst->epid = EPID; // stw [%r0 + DMST_EPID], EPID
* dctx->mst->prid = PRID; // stw [%r0 + DMST_PRID], PRID
* dctx->mst->clid = CLID; // stw [%r0 + DMST_CLID], CLID
* *((uint32_t *)&buf[0]) = EPID;
* // stw [%r9 + 0], EPID
*/
Expand All @@ -300,6 +303,7 @@ dt_cg_prologue(dt_pcb_t *pcb, dt_node_t *pred)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_0, DMST_TSTAMP, 0));
emite(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_0, DMST_EPID, -1), epid);
emite(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_0, DMST_PRID, -1), prid);
emite(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_0, DMST_CLID, -1), clid);
emite(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_9, 0, -1), epid);

/*
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_dctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
*/

#ifndef _DT_DCTX_H
Expand All @@ -20,6 +20,7 @@
typedef struct dt_mstate {
uint32_t epid; /* Enabled probe ID */
uint32_t prid; /* Probe ID */
uint32_t clid; /* Clause ID (unique per probe) */
uint32_t tag; /* Tag (for future use) */
uint64_t fault; /* DTrace fault flags */
uint64_t tstamp; /* cached timestamp value */
Expand Down Expand Up @@ -55,6 +56,7 @@ typedef struct dt_dctx {

#define DMST_EPID offsetof(dt_mstate_t, epid)
#define DMST_PRID offsetof(dt_mstate_t, prid)
#define DMST_CLID offsetof(dt_mstate_t, clid)
#define DMST_TAG offsetof(dt_mstate_t, tag)
#define DMST_FAULT offsetof(dt_mstate_t, fault)
#define DMST_TSTAMP offsetof(dt_mstate_t, tstamp)
Expand Down
3 changes: 2 additions & 1 deletion libdtrace/dt_dlibs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -74,6 +74,7 @@ static const dt_ident_t dt_bpf_symbols[] = {
/* BPF internal identifiers */
DT_BPF_SYMBOL_ID(EPID, DT_IDENT_SCALAR, DT_CONST_EPID),
DT_BPF_SYMBOL_ID(PRID, DT_IDENT_SCALAR, DT_CONST_PRID),
DT_BPF_SYMBOL_ID(CLID, DT_IDENT_SCALAR, DT_CONST_CLID),
DT_BPF_SYMBOL_ID(ARGC, DT_IDENT_SCALAR, DT_CONST_ARGC),
/* End-of-list marker */
{ NULL, }
Expand Down

0 comments on commit 4351e01

Please sign in to comment.