On Tue, Aug 04, 2026 at 06:35:20PM +1200, Tao Liu wrote:
Hi Huang,
On Mon, Jul 20, 2026 at 8:52 PM Huang Shijie <huangsj(a)hygon.cn> wrote:
>
> Add cpu_to_nid function which we can use to get the NUMA node id
> by the cpu id.
>
> Signed-off-by: Huang Shijie <huangsj(a)hygon.cn>
> ---
> defs.h | 2 ++
> kernel.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> main.c | 1 +
> 3 files changed, 49 insertions(+)
>
> diff --git a/defs.h b/defs.h
> index a4f70b7..98a149b 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -6040,6 +6040,8 @@ ulong do_maple_tree(ulong, int, struct list_pair *);
> void help_init(void);
> void cmd_usage(char *, int);
> void display_version(void);
> +int cpu_to_nid(int cpu);
> +void numa_init(void);
> void display_help_screen(char *);
> #ifdef ARM
> #define dump_machdep_table(X) arm_dump_machdep_table(X)
> diff --git a/kernel.c b/kernel.c
> index eb9754c..15254a4 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -12207,3 +12207,49 @@ out:
> pc->error_fp = error_fp_save;
> }
> #endif
> +
> +static int *cpu_to_nid_map;
> +
> +int
> +cpu_to_nid(int cpu)
> +{
> + if (!cpu_to_nid_map || cpu < 0 || cpu >= kt->cpus)
> + return -1;
> + if (vt->numnodes == 1)
> + return 0;
> + return cpu_to_nid_map[cpu];
> +}
> +
> +static void
> +cpu_to_nid_init(void)
> +{
> + int i, j;
> + int fd;
> + char buf[64];
> +
> + cpu_to_nid_map = malloc(kt->cpus * sizeof(int));
> + if (vt->numnodes == 1)
> + return;
> +
> + memset(cpu_to_nid_map, -1, kt->cpus * sizeof(int));
> +
> + for (i = 0; i < kt->cpus; i++) {
> + for (j = 0; j < vt->numnodes; j++) {
> + memset(buf, 0, sizeof(buf));
> + sprintf(buf,
"/sys/devices/system/cpu/cpu%d/node%d", i, j);
This will only work for live debug, rather than vmcore debug, won't
it? If so, I suggest supporting vmcore debug as well, so we can remove
the "/sys" dir reading.
okay.
I will wwitch to read the kernel symbol to get the cpu_to_node info.
(For x86_64, we can read the "x86_cpu_to_node_map".)
Thanks
Huang Shijie