mirror of
https://github.com/torvalds/linux.git
synced 2024-12-03 01:21:28 +00:00
4402869939
Switch from directly accessing the perf_cpu_map to using the appropriate libperf API when possible. Using the API simplifies the job of refactoring use of perf_cpu_map. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: André Almeida <andrealmeid@collabora.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Eric Dumazet <edumazet@google.com> Cc: German Gomez <german.gomez@arm.com> Cc: James Clark <james.clark@arm.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: John Garry <john.garry@huawei.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Miaoqian Lin <linmq006@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com> Cc: Song Liu <song@kernel.org> Cc: Stephane Eranian <eranian@google.com> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Yury Norov <yury.norov@gmail.com> Link: http://lore.kernel.org/lkml/20220122045811.3402706-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <linux/bitmap.h>
|
|
#include <perf/cpumap.h>
|
|
#include <internal/cpumap.h>
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
|
|
#define NBITS 100
|
|
|
|
static unsigned long *get_bitmap(const char *str, int nbits)
|
|
{
|
|
struct perf_cpu_map *map = perf_cpu_map__new(str);
|
|
unsigned long *bm = NULL;
|
|
int i;
|
|
|
|
bm = bitmap_zalloc(nbits);
|
|
|
|
if (map && bm) {
|
|
for (i = 0; i < perf_cpu_map__nr(map); i++)
|
|
set_bit(perf_cpu_map__cpu(map, i).cpu, bm);
|
|
}
|
|
|
|
if (map)
|
|
perf_cpu_map__put(map);
|
|
return bm;
|
|
}
|
|
|
|
static int test_bitmap(const char *str)
|
|
{
|
|
unsigned long *bm = get_bitmap(str, NBITS);
|
|
char buf[100];
|
|
int ret;
|
|
|
|
bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
|
|
pr_debug("bitmap: %s\n", buf);
|
|
|
|
ret = !strcmp(buf, str);
|
|
free(bm);
|
|
return ret;
|
|
}
|
|
|
|
static int test__bitmap_print(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
|
|
return 0;
|
|
}
|
|
|
|
DEFINE_SUITE("Print bitmap", bitmap_print);
|