mirror of
https://github.com/torvalds/linux.git
synced 2026-11-29 01:43:18 +00:00
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 <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Andrew Jones <[email protected]> Cc: André Almeida <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: Atish Patra <[email protected]> Cc: Changbin Du <[email protected]> Cc: Darren Hart <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: K Prateek Nayak <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Paran Lee <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Steinar H. Gunderson <[email protected]> Cc: Suzuki Poulouse <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Yang Li <[email protected]> Cc: Yanteng Si <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] [ s/syfs/sysfs/g typo ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
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;
|
|
}
|