Skip to content

Commit

Permalink
bpf: add 'agggen' BPF map
Browse files Browse the repository at this point in the history
The 'agggen' BPF map associates a generation counter with an aggregation
ID.  It will be used to determine whether the aggregation data in the
'aggs' map for aggregations associated with a given aggregation ID is
valid or stale.

The initial generation counter for each aggregation is 1 (because 0 is
used to indicate a no-data condition).

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 26, 2023
1 parent 863876a commit 293cb09
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
40 changes: 31 additions & 9 deletions libdtrace/dt_bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, 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 @@ -477,18 +477,23 @@ gmap_create_state(dtrace_hdl_t *dtp)
}

/*
* Create the 'aggs' BPF map.
* Create the 'aggs' BPF map (and its companion 'agggen' BPF map).
*
* Aggregation data buffer map, associated with each CPU. The map is
* implemented as a global array-of-maps indexed by CPU id. The associated
* value is a map with a singleton element (key 0).
* - aggs: Aggregation data buffer map, associated with each CPU. The map
* is implemented as a global array-of-maps indexed by CPU id.
* The associated value is a map with a singleton element (key 0).
* - agggen: Aggregation generation counters. The map associates a
* generation counter with each aggregation ID. The counter is
* used to determine whether the aggregation data is valid. The
* initial value is 1.
*/
static int
gmap_create_aggs(dtrace_hdl_t *dtp)
{
size_t ncpus = dtp->dt_conf.max_cpuid + 1;
size_t nelems = 0;
int i;
size_t ncpus = dtp->dt_conf.max_cpuid + 1;
size_t nelems = 0;
uint32_t aggc = dt_idhash_peekid(dtp->dt_aggs);
uint32_t i;

/* Only create the map if it is used. */
if (dtp->dt_maxaggdsize == 0)
Expand All @@ -508,6 +513,8 @@ gmap_create_aggs(dtrace_hdl_t *dtp)
BPF_MAP_TYPE_HASH,
dtp->dt_maxtuplesize,
dtp->dt_maxaggdsize, nelems);
if (dtp->dt_aggmap_fd == -1)
return -1;

for (i = 0; i < dtp->dt_conf.num_online_cpus; i++) {
int cpu = dtp->dt_conf.cpus[i].cpu_id;
Expand All @@ -524,8 +531,23 @@ gmap_create_aggs(dtrace_hdl_t *dtp)
dt_bpf_map_update(dtp->dt_aggmap_fd, &cpu, &fd);
}

/* Create the agg generation value array. */
dtp->dt_genmap_fd = create_gmap(dtp, "agggen", BPF_MAP_TYPE_ARRAY,
sizeof(uint32_t), sizeof(uint64_t),
aggc);
if (dtp->dt_genmap_fd == -1)
return -1;

for (i = 0; i < aggc; i++) {
uint64_t val = 1;

return dtp->dt_aggmap_fd;
if (dt_bpf_map_update(dtp->dt_genmap_fd, &i, &val) == -1)
return dt_bpf_error(dtp,
"cannot update BPF map 'agggen': %s\n",
strerror(errno));
}

return 0;
}

/*
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, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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 @@ -57,6 +57,7 @@ static const dt_ident_t dt_bpf_symbols[] = {

/* BPF maps */
DT_BPF_SYMBOL(aggs, DT_IDENT_PTR),
DT_BPF_SYMBOL(agggen, DT_IDENT_PTR),
DT_BPF_SYMBOL(buffers, DT_IDENT_PTR),
DT_BPF_SYMBOL(cpuinfo, DT_IDENT_PTR),
DT_BPF_SYMBOL(dvars, DT_IDENT_PTR),
Expand Down
3 changes: 2 additions & 1 deletion libdtrace/dt_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023, 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 @@ -380,6 +380,7 @@ struct dtrace_hdl {
int dt_proc_fd; /* file descriptor for proc eventfd */
int dt_stmap_fd; /* file descriptor for the 'state' BPF map */
int dt_aggmap_fd; /* file descriptor for the 'aggs' BPF map */
int dt_genmap_fd; /* file descriptor for the 'agggen' BPF map */
dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */
void *dt_errarg; /* error handler argument */
dtrace_handle_drop_f *dt_drophdlr; /* drop handler, if any */
Expand Down
2 changes: 1 addition & 1 deletion test/stress/buffering/err.resize2.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- @@stderr --
dtrace: script 'test/stress/buffering/err.resize2.d' matched 1 probe
dtrace: could not enable tracing: failed to create BPF map 'aggs_0': Too big
dtrace: could not enable tracing: failed to create BPF map 'aggs': Too big

0 comments on commit 293cb09

Please sign in to comment.