libperf cpumap: Replace usage of perf_cpu_map__new(NULL) with perf_cpu_map__new_onlin...
authorIan Rogers <irogers@google.com>
Wed, 29 Nov 2023 06:02:01 +0000 (22:02 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Dec 2023 17:55:13 +0000 (14:55 -0300)
Passing NULL to perf_cpu_map__new() performs
perf_cpu_map__new_online_cpus(), just directly call
perf_cpu_map__new_online_cpus() to be more intention revealing.

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-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
28 files changed:
tools/lib/perf/Documentation/examples/sampling.c
tools/lib/perf/Documentation/libperf-sampling.txt
tools/lib/perf/evlist.c
tools/lib/perf/tests/test-evlist.c
tools/lib/perf/tests/test-evsel.c
tools/perf/arch/arm/util/cs-etm.c
tools/perf/arch/arm64/util/header.c
tools/perf/bench/epoll-ctl.c
tools/perf/bench/epoll-wait.c
tools/perf/bench/futex-hash.c
tools/perf/bench/futex-lock-pi.c
tools/perf/bench/futex-requeue.c
tools/perf/bench/futex-wake-parallel.c
tools/perf/bench/futex-wake.c
tools/perf/builtin-ftrace.c
tools/perf/tests/code-reading.c
tools/perf/tests/keep-tracking.c
tools/perf/tests/mmap-basic.c
tools/perf/tests/openat-syscall-all-cpus.c
tools/perf/tests/perf-time-to-tsc.c
tools/perf/tests/switch-tracking.c
tools/perf/tests/topology.c
tools/perf/util/bpf_counter.c
tools/perf/util/cpumap.c
tools/perf/util/cputopo.c
tools/perf/util/evlist.c
tools/perf/util/perf_api_probe.c
tools/perf/util/record.c

index 8e1a926a9cfe6ec3631f9b82d758e870d4dab6ef..bc142f0664b5a6a127152bbb48068290dc949dcb 100644 (file)
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
 
        libperf_init(libperf_print);
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus) {
                fprintf(stderr, "failed to create cpus\n");
                return -1;
index d6ca24f6ef78f421910614560fe3b6bb6ec45420..2378980fab8a6b263e44ed3c5bb0f7ae9ed35ce1 100644 (file)
@@ -97,7 +97,7 @@ In this case we will monitor all the available CPUs:
 
 [source,c]
 --
- 42         cpus = perf_cpu_map__new(NULL);
+ 42         cpus = perf_cpu_map__new_online_cpus();
  43         if (!cpus) {
  44                 fprintf(stderr, "failed to create cpus\n");
  45                 return -1;
index 75f36218fdd98ed53aa4e4f5bcfff579f64623ec..058e3ff10f9b2849fd25b35164472ec9f949adca 100644 (file)
@@ -39,7 +39,7 @@ static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
        if (evsel->system_wide) {
                /* System wide: set the cpu map of the evsel to all online CPUs. */
                perf_cpu_map__put(evsel->cpus);
-               evsel->cpus = perf_cpu_map__new(NULL);
+               evsel->cpus = perf_cpu_map__new_online_cpus();
        } else if (evlist->has_user_cpus && evsel->is_pmu_core) {
                /*
                 * User requested CPUs on a core PMU, ensure the requested CPUs
index ab63878bacb99eca321881542312476b894606c9..10f70cb41ff1debbb870d3acc2cb71683bcee7f6 100644 (file)
@@ -46,7 +46,7 @@ static int test_stat_cpu(void)
        };
        int err, idx;
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        __T("failed to create cpus", cpus);
 
        evlist = perf_evlist__new();
@@ -350,7 +350,7 @@ static int test_mmap_cpus(void)
 
        attr.config = id;
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        __T("failed to create cpus", cpus);
 
        evlist = perf_evlist__new();
index a11fc51bfb688304e764f9166ebeddb11c902938..545ec31505466647b9ec182f79534fa713df4a57 100644 (file)
@@ -27,7 +27,7 @@ static int test_stat_cpu(void)
        };
        int err, idx;
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        __T("failed to create cpus", cpus);
 
        evsel = perf_evsel__new(&attr);
index c6b7b3066324ee2853b63de1f61585aefa8f21fe..77e6663c1703b8776c4cc33fbf0b81aac833583f 100644 (file)
@@ -199,7 +199,7 @@ static int cs_etm_validate_config(struct auxtrace_record *itr,
 {
        int i, err = -EINVAL;
        struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus;
-       struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
+       struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus();
 
        /* Set option of each CPU we have */
        for (i = 0; i < cpu__max_cpu().cpu; i++) {
@@ -536,7 +536,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
        int i;
        int etmv3 = 0, etmv4 = 0, ete = 0;
        struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus;
-       struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
+       struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus();
 
        /* cpu map is not empty, we have specific CPUs to work with */
        if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) {
@@ -802,7 +802,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
        u64 nr_cpu, type;
        struct perf_cpu_map *cpu_map;
        struct perf_cpu_map *event_cpus = session->evlist->core.user_requested_cpus;
-       struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
+       struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus();
        struct cs_etm_recording *ptr =
                        container_of(itr, struct cs_etm_recording, itr);
        struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
index a2eef9ec5491096d0f718f59e3e2ae6996e35ca3..97037499152ef785837b8815aac4da7907dfebf5 100644 (file)
@@ -57,7 +57,7 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
 
 int get_cpuid(char *buf, size_t sz)
 {
-       struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
+       struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus();
        int ret;
 
        if (!cpus)
index 6bfffe83dde99bd240de98cdde473d1bb8620d3b..d3db73dac66afe48ff80ff30849e125240c812e7 100644 (file)
@@ -330,7 +330,7 @@ int bench_epoll_ctl(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                goto errmem;
 
index cb5174b53940b265ae2be3adec3a9b916d524dab..06bb3187660abdd736821b5e96dddc73af261fed 100644 (file)
@@ -444,7 +444,7 @@ int bench_epoll_wait(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                goto errmem;
 
index 2005a3fa3026799d1cfcd246cc956ac4e528c97b..0c69d20efa329427c71141c09e6f1c1a9031738c 100644 (file)
@@ -138,7 +138,7 @@ int bench_futex_hash(int argc, const char **argv)
                exit(EXIT_FAILURE);
        }
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                goto errmem;
 
index 092cbd52db82b500360022d0d768999d1ca42cb9..7a4973346180fc91009573c503a021c9b217ee29 100644 (file)
@@ -172,7 +172,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
        if (argc)
                goto err;
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                err(EXIT_FAILURE, "calloc");
 
index c0035990a33cebafea34493b7978a9e1c2c9b2f7..d9ad736c1a3e0d13317aaf28a777a6327c17e5d3 100644 (file)
@@ -174,7 +174,7 @@ int bench_futex_requeue(int argc, const char **argv)
        if (argc)
                goto err;
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                err(EXIT_FAILURE, "cpu_map__new");
 
index 5ab0234d74e696d1afcc48451110653bc4da3649..b66df553e5614cb393066f2ec8b66ee75ba15ed8 100644 (file)
@@ -264,7 +264,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
                        err(EXIT_FAILURE, "mlockall");
        }
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                err(EXIT_FAILURE, "calloc");
 
index 18a5894af8bb51fb6aa5353db05ef9c75a270253..690fd6d3da130161ac6473df2ba5dabecbc8324a 100644 (file)
@@ -149,7 +149,7 @@ int bench_futex_wake(int argc, const char **argv)
                exit(EXIT_FAILURE);
        }
 
-       cpu = perf_cpu_map__new(NULL);
+       cpu = perf_cpu_map__new_online_cpus();
        if (!cpu)
                err(EXIT_FAILURE, "calloc");
 
index ac2e6c75f9120192ad5220eaf727896ef8b11aee..eb30c8eca48878482d9e9682165330a161a6f3f8 100644 (file)
@@ -333,7 +333,7 @@ static int set_tracing_func_irqinfo(struct perf_ftrace *ftrace)
 
 static int reset_tracing_cpu(void)
 {
-       struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL);
+       struct perf_cpu_map *cpumap = perf_cpu_map__new_online_cpus();
        int ret;
 
        ret = set_tracing_cpumask(cpumap);
index 8620146d0378389b73332217273cb31ae4310cc9..7a3a7bbbec7146b772cd6ab029b1d22c9d94a873 100644 (file)
@@ -610,7 +610,7 @@ static int do_test_code_reading(bool try_kcore)
                goto out_put;
        }
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus) {
                pr_debug("perf_cpu_map__new failed\n");
                goto out_put;
index 8f4f9b632e1e586a85911d61e4e180294041fff3..5a3b2bed07f327e1806766a5bdf0c61792673c75 100644 (file)
@@ -81,7 +81,7 @@ static int test__keep_tracking(struct test_suite *test __maybe_unused, int subte
        threads = thread_map__new(-1, getpid(), UINT_MAX);
        CHECK_NOT_NULL__(threads);
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        CHECK_NOT_NULL__(cpus);
 
        evlist = evlist__new();
index 886a13a77a1624022f9165837a7787f87ca709c4..012c8ae439fdcf56cd6b2492d7460de5110cc708 100644 (file)
@@ -52,7 +52,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest
                return -1;
        }
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (cpus == NULL) {
                pr_debug("perf_cpu_map__new\n");
                goto out_free_threads;
index f3275be83a3382ee1437ea671274f47fad60eca5..fb114118c87640b848bbd0243a7810cc2877b032 100644 (file)
@@ -37,7 +37,7 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb
                return -1;
        }
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (cpus == NULL) {
                pr_debug("perf_cpu_map__new\n");
                goto out_thread_map_delete;
index efcd71c2738afb9d93809e8bab18eb5dd3090195..bbe2ddeb9b745c0c8d51dc842afcfd603635fe4c 100644 (file)
@@ -93,7 +93,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
        threads = thread_map__new(-1, getpid(), UINT_MAX);
        CHECK_NOT_NULL__(threads);
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        CHECK_NOT_NULL__(cpus);
 
        evlist = evlist__new();
index e52b031bedc5a9b545fe9b6c8d3f93b6aaefd03d..5cab17a1942e67d7767161a21fdee07599912d61 100644 (file)
@@ -351,7 +351,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
                goto out_err;
        }
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus) {
                pr_debug("perf_cpu_map__new failed!\n");
                goto out_err;
index 9dee63734e66a0c1b08c62bb1bbfb393ad9866d2..2a842f53fbb575a2f715d66898ff1bb6553dfa7f 100644 (file)
@@ -215,7 +215,7 @@ static int test__session_topology(struct test_suite *test __maybe_unused, int su
        if (session_write_header(path))
                goto free_path;
 
-       map = perf_cpu_map__new(NULL);
+       map = perf_cpu_map__new_online_cpus();
        if (map == NULL) {
                pr_debug("failed to get system cpumap\n");
                goto free_path;
index 7f9b0e46e008c466604aec8c4e59ace15001a5e8..7a8af60e0f5158fe7936898a7c12fceadef7e8f0 100644 (file)
@@ -455,7 +455,7 @@ static int bperf__load(struct evsel *evsel, struct target *target)
                return -1;
 
        if (!all_cpu_map) {
-               all_cpu_map = perf_cpu_map__new(NULL);
+               all_cpu_map = perf_cpu_map__new_online_cpus();
                if (!all_cpu_map)
                        return -1;
        }
index 0e090e8bc33491eea0f2007f136aa236cc103482..0581ee0fa5f270b4eb6fa4ae5776afb056804099 100644 (file)
@@ -672,7 +672,7 @@ struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */
        static struct perf_cpu_map *online;
 
        if (!online)
-               online = perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */
+               online = perf_cpu_map__new_online_cpus(); /* from /sys/devices/system/cpu/online */
 
        return online;
 }
index 81cfc85f46682ce0c0a2cc5a88556dbb88beb23b..8bbeb2dc76fda994b7f83abd227aceaed6e78c55 100644 (file)
@@ -267,7 +267,7 @@ struct cpu_topology *cpu_topology__new(void)
        ncpus = cpu__max_present_cpu().cpu;
 
        /* build online CPU map */
-       map = perf_cpu_map__new(NULL);
+       map = perf_cpu_map__new_online_cpus();
        if (map == NULL) {
                pr_debug("failed to get system cpumap\n");
                return NULL;
index ff7f85ded89d73bbdb1c106380619a087d27bc38..0ed3ce2aa8ebf378e123337a04d332248373daec 100644 (file)
@@ -1352,7 +1352,7 @@ static int evlist__create_syswide_maps(struct evlist *evlist)
         * error, and we may not want to do that fallback to a
         * default cpu identity map :-\
         */
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus)
                goto out;
 
index e1e2d701599c4294f05e1c73ca5aef4cd1ef8544..1de3b69cdf4aafb7fdc73574b2b44a3cad38a75e 100644 (file)
@@ -64,7 +64,7 @@ static bool perf_probe_api(setup_probe_fn_t fn)
        struct perf_cpu cpu;
        int ret, i = 0;
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus)
                return false;
        cpu = perf_cpu_map__cpu(cpus, 0);
@@ -140,7 +140,7 @@ bool perf_can_record_cpu_wide(void)
        struct perf_cpu cpu;
        int fd;
 
-       cpus = perf_cpu_map__new(NULL);
+       cpus = perf_cpu_map__new_online_cpus();
        if (!cpus)
                return false;
 
index 40290382b2d7092e0e8525ebd03ee18c87154a9d..87e817b3cf7e9d9b94799cfcb47cbd98b4c1ff02 100644 (file)
@@ -238,7 +238,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str)
        evsel = evlist__last(temp_evlist);
 
        if (!evlist || perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) {
-               struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
+               struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus();
 
                if (cpus)
                        cpu =  perf_cpu_map__cpu(cpus, 0);