Skip to content

Commit

Permalink
Implement the trunc() action
Browse files Browse the repository at this point in the history
Some tests may not yield the desired results yet due to issues with
switchrate/aggrate/statusrate implementation details that those
tests depend on.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Aug 21, 2023
1 parent 819f1c2 commit 5307ab9
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
31 changes: 31 additions & 0 deletions libdtrace/dt_aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,35 @@ dt_aggregate_go(dtrace_hdl_t *dtp)
return dt_set_errno(dtp, EDT_NOMEM);
}

/*
* Remove the given aggregation entry on the producer side. We use the global
* key scratch space because this function cannot be called from a call chain
* that already uses that global key scratch.
*/
static int
dt_aggwalk_remove(dtrace_hdl_t *dtp, dt_ahashent_t *h)
{
dtrace_aggdata_t *agd = &h->dtahe_data;
int i, ncpus = dtp->dt_conf.num_online_cpus;
char *key = dtp->dt_aggregate.dtat_key;

memset(key, 0, dtp->dt_maxtuplesize);
memcpy(key, agd->dtada_key, agd->dtada_desc->dtagd_ksize);

for (i = 0; i < ncpus; i++) {
int cpu = dtp->dt_conf.cpus[i].cpu_id;
int fd = dt_bpf_map_lookup_fd(dtp->dt_aggmap_fd, &cpu);

if (fd < 0)
return DTRACE_WORKSTATUS_ERROR;

dt_bpf_map_delete(fd, key);
close(fd);
}

return DTRACE_WORKSTATUS_OKAY;
}

static int
dt_aggwalk_rval(dtrace_hdl_t *dtp, dt_ahashent_t *h, int rval)
{
Expand Down Expand Up @@ -1148,6 +1177,8 @@ dt_aggwalk_rval(dtrace_hdl_t *dtp, dt_ahashent_t *h, int rval)
dt_free(dtp, aggdata->dtada_percpu);
}

dt_aggwalk_remove(dtp, h);

dt_free(dtp, aggdata->dtada_key);
dt_free(dtp, aggdata->dtada_data);
dt_free(dtp, h);
Expand Down
27 changes: 4 additions & 23 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2273,11 +2273,6 @@ dt_cg_act_trunc(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
dt_node_t *anp, *trunc;
dt_ident_t *aid;
char n[DT_TYPE_NAMELEN];
int argc = 0;

for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
argc++;
assert(argc == 1 || argc == 2);

anp = dnp->dn_args;
assert(anp != NULL);
Expand All @@ -2288,32 +2283,18 @@ dt_cg_act_trunc(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
dnp->dn_ident->di_name,
dt_node_type_name(anp, n, sizeof(n)));

trunc = anp->dn_list;
if (argc == 2)
assert(trunc != NULL && dt_node_is_scalar(trunc));

aid = anp->dn_ident;
if (aid->di_gen == pcb->pcb_hdl->dt_gen &&
!(aid->di_flags & DT_IDFLG_MOD))
dnerror(dnp, D_TRUNC_AGGBAD,
"undefined aggregation: @%s\n", aid->di_name);

/*
* FIXME: Needs implementation
* TODO: Emit code to truncate the given aggregation.
* DEPENDS ON: How aggregations are implemented using eBPF (hashmap?).
* AGGID = aid->di_id
*/
trunc = anp->dn_list;
if (trunc == NULL)
trunc = dt_node_int(0);

dt_cg_store_val(pcb, anp, DTRACEACT_LIBACT, NULL, DT_ACT_TRUNC);
#ifdef FIXME
/*
* FIXME: There is an optional trunction value.
* if (argc == 1), the optional value is missing, but "0" may be
* specified.
*/
dt_cg_store_val(pcb, trunc, DTRACEACT_LIBACT, NULL, DT_ACT_TRUNC);
#endif
dnerror(dnp, D_UNKNOWN, "trunc() is not implemented (yet)\n");
}

static void
Expand Down
19 changes: 13 additions & 6 deletions libdtrace/dt_consume.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,6 @@ dt_clear(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
return 0;
}

#ifdef FIXME
typedef struct dt_trunc {
dtrace_aggid_t dttd_id;
uint64_t dttd_remaining;
Expand Down Expand Up @@ -1594,19 +1593,19 @@ dt_trunc(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
addr = base + rec->dtrd_offset;

switch (rec->dtrd_size) {
case sizeof(uint64_t):
case sizeof(int64_t):
/* LINTED - alignment */
remaining = *((int64_t *)addr);
break;
case sizeof(uint32_t):
case sizeof(int32_t):
/* LINTED - alignment */
remaining = *((int32_t *)addr);
break;
case sizeof(uint16_t):
case sizeof(int16_t):
/* LINTED - alignment */
remaining = *((int16_t *)addr);
break;
case sizeof(uint8_t):
case sizeof(int8_t):
remaining = *((int8_t *)addr);
break;
default:
Expand All @@ -1626,7 +1625,6 @@ dt_trunc(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)

return 0;
}
#endif

static int
dt_print_datum(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
Expand Down Expand Up @@ -2344,6 +2342,15 @@ dt_consume_one_probe(dtrace_hdl_t *dtp, FILE *fp, char *data, uint32_t size,
if (dt_clear(dtp, data, rec) != 0)
return DTRACE_WORKSTATUS_ERROR;

continue;
case DT_ACT_TRUNC:
if (i == epd->dtdd_nrecs - 1)
return dt_set_errno(dtp, EDT_BADTRUNC);

if (dt_trunc(dtp, data, rec) != 0)
return DTRACE_WORKSTATUS_ERROR;

i++;
continue;
case DT_ACT_FTRUNCATE:
if (fp == NULL)
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static const dt_ident_t _dtrace_globals[] = {
DT_ATTR_STABCMN, DT_VERS_1_0,
&dt_idops_func, "void(@, size_t, [size_t])" },
{ "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN,
DT_VERS_1_0, &dt_idops_func, "void(@, [uint64_t])" },
DT_VERS_1_0, &dt_idops_func, "void(@, [int64_t])" },
{ "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN,
DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
{ "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN,
Expand Down
1 change: 0 additions & 1 deletion test/unittest/aggs/tst.negtrunc.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 - requires trunc() */

#pragma D option quiet

Expand Down
1 change: 0 additions & 1 deletion test/unittest/aggs/tst.negtruncquant.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 - requires trunc() */

#pragma D option quiet

Expand Down
1 change: 0 additions & 1 deletion test/unittest/aggs/tst.trunc.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 - requires trunc() */

#pragma D option quiet

Expand Down
1 change: 0 additions & 1 deletion test/unittest/aggs/tst.trunc0.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 - requires trunc() */

#pragma D option quiet
#pragma D option aggrate=1ms
Expand Down
1 change: 0 additions & 1 deletion test/unittest/aggs/tst.truncquant.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 - requires trunc() */

#pragma D option quiet

Expand Down

0 comments on commit 5307ab9

Please sign in to comment.