Skip to content

Commit 4227c2c

Browse files
captain5050mehmetb0
authored andcommitted
libperf cpumap: Add any, empty and min helpers
BugLink: https://bugs.launchpad.net/bugs/2107336 commit b6b4a62 upstream. Additional helpers to better replace perf_cpu_map__has_any_cpu_or_is_empty(). Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> 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 Rajeev <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: James Clark <james.clark@arm.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: 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> Link: https://lore.kernel.org/r/20240202234057.2085863-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> (cherry picked from commit b6b4a62) Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com> Acked-by: Manuel Diewald <manuel.diewald@canonical.com> Acked-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent 96b97b5 commit 4227c2c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

tools/lib/perf/cpumap.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map)
316316
return map ? __perf_cpu_map__cpu(map, 0).cpu == -1 : true;
317317
}
318318

319+
bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map)
320+
{
321+
if (!map)
322+
return true;
323+
324+
return __perf_cpu_map__nr(map) == 1 && __perf_cpu_map__cpu(map, 0).cpu == -1;
325+
}
326+
327+
bool perf_cpu_map__is_empty(const struct perf_cpu_map *map)
328+
{
329+
return map == NULL;
330+
}
331+
319332
int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu)
320333
{
321334
int low, high;
@@ -372,6 +385,20 @@ bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map)
372385
return map && __perf_cpu_map__cpu(map, 0).cpu == -1;
373386
}
374387

388+
struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map)
389+
{
390+
struct perf_cpu cpu, result = {
391+
.cpu = -1
392+
};
393+
int idx;
394+
395+
perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) {
396+
result = cpu;
397+
break;
398+
}
399+
return result;
400+
}
401+
375402
struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map)
376403
{
377404
struct perf_cpu result = {

tools/lib/perf/include/perf/cpumap.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
6161
* perf_cpu_map__has_any_cpu_or_is_empty - is map either empty or has the "any CPU"/dummy value.
6262
*/
6363
LIBPERF_API bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map);
64+
/**
65+
* perf_cpu_map__is_any_cpu_or_is_empty - is map either empty or the "any CPU"/dummy value.
66+
*/
67+
LIBPERF_API bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map);
68+
/**
69+
* perf_cpu_map__is_empty - does the map contain no values and it doesn't
70+
* contain the special "any CPU"/dummy value.
71+
*/
72+
LIBPERF_API bool perf_cpu_map__is_empty(const struct perf_cpu_map *map);
73+
/**
74+
* perf_cpu_map__min - the minimum CPU value or -1 if empty or just the "any CPU"/dummy value.
75+
*/
76+
LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map);
77+
/**
78+
* perf_cpu_map__max - the maximum CPU value or -1 if empty or just the "any CPU"/dummy value.
79+
*/
6480
LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map);
6581
LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu);
6682
LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs,

tools/lib/perf/libperf.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ LIBPERF_0.0.1 {
1010
perf_cpu_map__nr;
1111
perf_cpu_map__cpu;
1212
perf_cpu_map__has_any_cpu_or_is_empty;
13+
perf_cpu_map__is_any_cpu_or_is_empty;
14+
perf_cpu_map__is_empty;
15+
perf_cpu_map__has_any_cpu;
16+
perf_cpu_map__min;
1317
perf_cpu_map__max;
1418
perf_cpu_map__has;
1519
perf_thread_map__new_array;

0 commit comments

Comments
 (0)