[DTrace-devel] [PATCH 1/2] Add a cpuinfos BPF map

eugene.loh at oracle.com eugene.loh at oracle.com
Mon Mar 31 21:45:00 UTC 2025


From: Eugene Loh <eugene.loh at oracle.com>

The cpuinfo BPF map is a per-CPU map that has CPU information
on each CPU for that CPU.

Add a cpuinfos BPF map that allows any CPU to access information
for any other CPU.

For now, we retain the older per-CPU map.  If desired, a future
patch can migrate existing uses of the per-CPU map to the new
map, decommissioning the old one.  This would include map set up:

*)  libdtrace/dt_dlibs.c:   DT_BPF_SYMBOL(cpuinfo, DT_IDENT_PTR),

*)  libdtrace/dt_impl.h:    int dt_cpumap_fd;

*)  libdtrace/dt_bpf.c:     dtp->dt_cpumap_fd = ...
    libdtrace/dt_bpf.c:     CREATE_MAP(cpuinfo)

and map use:

*)  bpf/get_agg.c
*)  bpf/get_bvar.c
*)  libdtrace/dt_cg.c
*)  libdtrace/dt_prov_lockstat.c

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_bpf.c   | 13 +++++++++++++
 libdtrace/dt_dlibs.c |  1 +
 libdtrace/dt_impl.h  |  1 +
 3 files changed, 15 insertions(+)

diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index 6d42a96c7..8da51d6b9 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -786,7 +786,20 @@ gmap_create_cpuinfo(dtrace_hdl_t *dtp)
 	if (dtp->dt_cpumap_fd == -1)
 		return -1;
 
+	dtp->dt_cpusmap_fd = create_gmap(dtp, "cpuinfos",
+					BPF_MAP_TYPE_HASH,
+					sizeof(uint32_t),
+					sizeof(dt_bpf_cpuinfo_t), ncpus);
+	if (dtp->dt_cpusmap_fd == -1)
+		return -1;
+
 	rc = dt_bpf_map_update(dtp->dt_cpumap_fd, &key, data);
+
+	for (i = 0, ci = &conf->cpus[0]; i < ncpus && rc != -1; i++, ci++) {
+		key = ci->cpu_id;
+		rc = dt_bpf_map_update(dtp->dt_cpusmap_fd, &key, &data[ci->cpu_id]);
+	}
+
 	dt_free(dtp, data);
 	if (rc == -1)
 		return dt_bpf_error(dtp,
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index 21df22a8a..0f19f3566 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -61,6 +61,7 @@ static const dt_ident_t		dt_bpf_symbols[] = {
 	DT_BPF_SYMBOL(agggen, DT_IDENT_PTR),
 	DT_BPF_SYMBOL(buffers, DT_IDENT_PTR),
 	DT_BPF_SYMBOL(cpuinfo, DT_IDENT_PTR),
+	DT_BPF_SYMBOL(cpuinfos, DT_IDENT_PTR),
 	DT_BPF_SYMBOL(dvars, DT_IDENT_PTR),
 	DT_BPF_SYMBOL(gvars, DT_IDENT_PTR),
 	DT_BPF_SYMBOL(lvars, DT_IDENT_PTR),
diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
index 68fb8ec53..a5e42801c 100644
--- a/libdtrace/dt_impl.h
+++ b/libdtrace/dt_impl.h
@@ -390,6 +390,7 @@ struct dtrace_hdl {
 	int dt_aggmap_fd;	/* file descriptor for the 'aggs' BPF map */
 	int dt_genmap_fd;	/* file descriptor for the 'agggen' BPF map */
 	int dt_cpumap_fd;	/* file descriptor for the 'cpuinfo' BPF map */
+	int dt_cpusmap_fd;	/* file descriptor for the 'cpuinfos' BPF map */
 	int dt_usdt_pridsmap_fd; /* file descriptor for the 'usdt_prids' BPF map */
 	int dt_usdt_namesmap_fd; /* file descriptor for the 'usdt_names' BPF map */
 	dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */
-- 
2.43.5




More information about the DTrace-devel mailing list