[DTrace-devel] [PATCH 05/05] bpf: ensure cpuinfo can handle non-sequential CPU ids
Kris Van Hees
kris.van.hees at oracle.com
Fri May 5 15:34:11 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>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_bpf.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index a00b353d..f247d83d 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -604,15 +604,28 @@ gmap_create_buffers(dtrace_hdl_t *dtp)
static int
gmap_create_cpuinfo(dtrace_hdl_t *dtp)
{
- int fd;
+ int i, fd, rc;
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)
+ rc = dt_bpf_map_update(fd, &key, data);
+ dt_free(dtp, data);
+ if (rc == -1)
return dt_bpf_error(dtp,
"cannot update BPF map 'cpuinfo': %s\n",
strerror(errno));
--
2.40.1
More information about the DTrace-devel
mailing list