perf tools: Handle TOPOLOGY headers with no CPU

This change “perf tools: Handle TOPOLOGY headers with no CPU” in Linux kernel is authored by Stephane Eranian <eranian [at]> on Sat Jan 19 00:12:39 2019 -0800.

perf tools: Handle TOPOLOGY headers with no CPU

This patch fixes an issue in cpumap.c when used with the TOPOLOGY
header. In some configurations, some NUMA nodes may have no CPU (empty
cpulist). Yet a cpumap map must be created otherwise perf abort with an
error. This patch handles this case by creating a dummy map.


  $ perf record -o - -e cycles noploop 2 | perf script -i -
  0x6e8 [0x6c]: failed to process type: 80


  $ perf record -o - -e cycles noploop 2 | perf script -i -
  noploop for 2 seconds

Signed-off-by: Stephane Eranian <>
Acked-by: Jiri Olsa <>
Cc: Andi Kleen <>
Cc: Kan Liang <>
Cc: Peter Zijlstra <>
Signed-off-by: Arnaldo Carvalho de Melo <>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 1497e80.

There are 11 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/perf/util/cpumap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 1ccbd33..383674f 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -134,7 +134,12 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
 	if (!cpu_list)
 		return cpu_map__read_all_cpu_map();
-	if (!isdigit(*cpu_list))
+	/*
+	 * must handle the case of empty cpumap to cover
+	 * TOPOLOGY header for NUMA nodes with no CPU
+	 * ( e.g., because of CPU hotplug)
+	 */
+	if (!isdigit(*cpu_list) && *cpu_list != '')
 		goto out;
 	while (isdigit(*cpu_list)) {
@@ -181,8 +186,10 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
 	if (nr_cpus > 0)
 		cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
-	else
+	else if (*cpu_list != '')
 		cpus = cpu_map__default_new();
+	else
+		cpus = cpu_map__dummy_new();

The commit for this change in Linux stable tree is 1497e80 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *