mirror of
https://github.com/torvalds/linux.git
synced 2024-11-28 15:11:31 +00:00
8f60f870a9
Rename perf_cpu_map__default_new() to perf_cpu_map__new_online_cpus() to better indicate what the implementation does. Read the online CPUs from /sys/devices/system/cpu/online first before using sysconf() as it can't accurately configure holes in the CPU map. If sysconf() is used, warn when the configured and online processors disagree. When reading from a file, if the read doesn't yield a CPU map then return an empty map rather than the default online. This avoids recursion but also better yields being able to detect failures. Add more comments. Reviewed-by: James Clark <james.clark@arm.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: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: André Almeida <andrealmeid@igalia.com> Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Cc: Atish Patra <atishp@rivosinc.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Paran Lee <p4ranlee@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Steinar H. Gunderson <sesse@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will@kernel.org> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Yang Li <yang.lee@linux.alibaba.com> Cc: Yanteng Si <siyanteng@loongson.cn> Cc: bpf@vger.kernel.org Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20231129060211.1890454-3-irogers@google.com [ s/syfs/sysfs/g typo ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
44 lines
795 B
C
44 lines
795 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <perf/cpumap.h>
|
|
#include <internal/tests.h>
|
|
#include "tests.h"
|
|
|
|
static int libperf_print(enum libperf_print_level level,
|
|
const char *fmt, va_list ap)
|
|
{
|
|
return vfprintf(stderr, fmt, ap);
|
|
}
|
|
|
|
int test_cpumap(int argc, char **argv)
|
|
{
|
|
struct perf_cpu_map *cpus;
|
|
struct perf_cpu cpu;
|
|
int idx;
|
|
|
|
__T_START;
|
|
|
|
libperf_init(libperf_print);
|
|
|
|
cpus = perf_cpu_map__new_any_cpu();
|
|
if (!cpus)
|
|
return -1;
|
|
|
|
perf_cpu_map__get(cpus);
|
|
perf_cpu_map__put(cpus);
|
|
perf_cpu_map__put(cpus);
|
|
|
|
cpus = perf_cpu_map__new_online_cpus();
|
|
if (!cpus)
|
|
return -1;
|
|
|
|
perf_cpu_map__for_each_cpu(cpu, idx, cpus)
|
|
__T("wrong cpu number", cpu.cpu != -1);
|
|
|
|
perf_cpu_map__put(cpus);
|
|
|
|
__T_END;
|
|
return tests_failed == 0 ? 0 : -1;
|
|
}
|