[DTrace-devel] [PATCH 5/5] bpf: ensure cpuinfo can handle non-sequential CPU ids
Kris Van Hees
kris.van.hees at oracle.com
Mon May 1 19:53:31 UTC 2023
The 'cpuinfo' BPF map (a per-cpu map) was populated assuming that CPU
ids are always strictly sequential, i.e. that no gaps in the numbering
can occur. That is not a valid assumption. We need to populate the
cpuinfo entries referenced by the cpu_id of each online CPU.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
libdtrace/dt_bpf.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index e19833bd..d0487759 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -607,15 +607,26 @@ gmap_create_buffers(dtrace_hdl_t *dtp)
static int
gmap_create_cpuinfo(dtrace_hdl_t *dtp)
{
- int fd;
+ int i, fd;
uint32_t key = 0;
+ dtrace_conf_t *conf = &dtp->dt_conf;
+ size_t ncpus = conf->max_cpuid + 1;
+ cpuinfo_t *data;
+ cpuinfo_t *ci;
+
+ data = dt_zalloc(dtp, ncpus * sizeof(cpuinfo_t));
+ if (data == NULL)
+ return dt_set_errno(dtp, EDT_NOMEM);
+
+ for (i = 0, ci = &conf->cpus[0]; i < ncpus; i++, ci++)
+ memcpy(&data[ci->cpu_id], ci, sizeof(cpuinfo_t));
fd = create_gmap(dtp, "cpuinfo", BPF_MAP_TYPE_PERCPU_ARRAY,
sizeof(uint32_t), sizeof(cpuinfo_t), 1);
if (fd == -1)
return -1;
- if (dt_bpf_map_update(fd, &key, dtp->dt_conf.cpus) == -1)
+ if (dt_bpf_map_update(fd, &key, data) == -1)
return dt_bpf_error(dtp,
"cannot update BPF map 'cpuinfo': %s\n",
strerror(errno));
--
2.39.1
More information about the DTrace-devel
mailing list