Skip to content

Commit

Permalink
Load the global string table data into the strtab BPF map
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Jun 18, 2021
1 parent ceeb427 commit 9e1846b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
15 changes: 3 additions & 12 deletions libdtrace/dt_as.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,9 @@ dt_as(dt_pcb_t *pcb)
* We keep the string table around (dtp->dt_csstab) because further
* compilations may add more strings. We will load a consolidated
* compiled string table into a strtab BPF map so it can be used ny
* all BPF programs we will be loading. Since each DIFO will have a
* string table that comprises the strings of all DIFOs before it along
* with any new ones, we simply assign the latest (and most complete)
* string table to dtp->dt_strtab (and the size as dtp->dt_strlen), so
* that when we are ready to load and execute programs, we know we have
* the latest and greatest string table to work with.
*
* Note that this means that we should *not* free dtp->dt_strtab later
* because it will be free'd when the DIFO is destroyed.
* all BPF programs we will be loading. Therefore, each DIFO will have
* a string table that comprises the strings of all DIFOs before it
* along with any new ones.
*/
dp->dtdo_strlen = dt_strtab_size(dtp->dt_ccstab);
if (dp->dtdo_strlen > 0) {
Expand All @@ -586,9 +580,6 @@ dt_as(dt_pcb_t *pcb)
dt_strtab_write(dtp->dt_ccstab,
(dt_strtab_write_f *)dt_strtab_copystr,
dp->dtdo_strtab);

dtp->dt_strtab = dp->dtdo_strtab;
dtp->dt_strlen = dp->dtdo_strlen;
} else
dp->dtdo_strtab = NULL;

Expand Down
22 changes: 19 additions & 3 deletions libdtrace/dt_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int
dt_bpf_gmap_create(dtrace_hdl_t *dtp)
{
int gvarsz, lvarsz, tvarc, aggsz;
int ci_mapfd;
int ci_mapfd, st_mapfd;
uint32_t key = 0;

/* If we already created the global maps, return success. */
Expand Down Expand Up @@ -251,8 +251,21 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
roundup(dtp->dt_maxreclen, 8), 1) == -1)
return -1; /* dt_errno is set for us */

if (create_gmap(dtp, "strtab", BPF_MAP_TYPE_ARRAY,
sizeof(uint32_t), dtp->dt_strlen, 1) == -1)
/*
* We may need to create a final copy of the string table because it is
* possible entries were added after the last clause was compiled.
*/
dtp->dt_strlen = dt_strtab_size(dtp->dt_ccstab);
dtp->dt_strtab = dt_zalloc(dtp, dtp->dt_strlen);
if (dtp->dt_strtab == NULL)
return dt_set_errno(dtp, EDT_NOMEM);

dt_strtab_write(dtp->dt_ccstab, (dt_strtab_write_f *)dt_strtab_copystr,
dtp->dt_strtab);

st_mapfd = create_gmap(dtp, "strtab", BPF_MAP_TYPE_ARRAY,
sizeof(uint32_t), dtp->dt_strlen, 1);
if (st_mapfd == -1)
return -1; /* dt_errno is set for us */

if (gvarsz > 0 &&
Expand All @@ -273,6 +286,9 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
/* Populate the 'cpuinfo' map. */
dt_bpf_map_update(ci_mapfd, &key, dtp->dt_conf.cpus);

/* Populate the 'strtab' map. */
dt_bpf_map_update(st_mapfd, &key, dtp->dt_strtab);

/* Set some task_struct offsets in state. */
if (set_task_offsets(dtp))
return dt_set_errno(dtp, EDT_CTF);
Expand Down

0 comments on commit 9e1846b

Please sign in to comment.