Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf pmu: Add CPU map for "cpu" PMUs

A typical "cpu" PMU has no "cpus" or "cpumask" file meaning the CPU
map is set to NULL, which also encodes an empty CPU map. Update
pmu_cpumask so that if the "cpu" PMU fails to load a CPU map, use a
default of all online PMUs.

Remove const from cpu_map__online for the sake of reference counting.

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230527072210.2900565-8-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
a0c41cae 1578e63d

+5 -5
+2 -2
tools/perf/util/cpumap.c
··· 667 667 return ptr - buf; 668 668 } 669 669 670 - const struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ 670 + struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ 671 671 { 672 - static const struct perf_cpu_map *online = NULL; 672 + static struct perf_cpu_map *online; 673 673 674 674 if (!online) 675 675 online = perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */
+2 -2
tools/perf/util/cpumap.h
··· 55 55 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); 56 56 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); 57 57 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); 58 - const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ 58 + struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ 59 59 60 60 int cpu__setup_cpunode_map(void); 61 61 ··· 66 66 /** 67 67 * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1. 68 68 */ 69 - static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus) 69 + static inline bool cpu_map__is_dummy(const struct perf_cpu_map *cpus) 70 70 { 71 71 return perf_cpu_map__nr(cpus) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1; 72 72 }
+1 -1
tools/perf/util/pmu.c
··· 610 610 return cpus; 611 611 } 612 612 613 - return NULL; 613 + return !strcmp(name, "cpu") ? perf_cpu_map__get(cpu_map__online()) : NULL; 614 614 } 615 615 616 616 static bool pmu_is_uncore(int dirfd, const char *name)