linux-stable/tools/perf/tests/mem2node.c
Ian Rogers 4402869939 perf cpumap: Migrate to libperf cpumap api
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>
2022-01-22 17:08:42 -03:00

82 lines
2 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <linux/bitmap.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include <internal/cpumap.h>
#include "debug.h"
#include "env.h"
#include "mem2node.h"
#include "tests.h"
static struct node {
int node;
const char *map;
} test_nodes[] = {
{ .node = 0, .map = "0" },
{ .node = 1, .map = "1-2" },
{ .node = 3, .map = "5-7,9" },
};
#define T TEST_ASSERT_VAL
static unsigned long *get_bitmap(const char *str, int nbits)
{
struct perf_cpu_map *map = perf_cpu_map__new(str);
unsigned long *bm = NULL;
bm = bitmap_zalloc(nbits);
if (map && bm) {
struct perf_cpu cpu;
int i;
perf_cpu_map__for_each_cpu(cpu, i, map)
set_bit(cpu.cpu, bm);
}
if (map)
perf_cpu_map__put(map);
else
free(bm);
return bm && map ? bm : NULL;
}
static int test__mem2node(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
{
struct mem2node map;
struct memory_node nodes[3];
struct perf_env env = {
.memory_nodes = (struct memory_node *) &nodes[0],
.nr_memory_nodes = ARRAY_SIZE(nodes),
.memory_bsize = 0x100,
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(nodes); i++) {
nodes[i].node = test_nodes[i].node;
nodes[i].size = 10;
T("failed: alloc bitmap",
(nodes[i].set = get_bitmap(test_nodes[i].map, 10)));
}
T("failed: mem2node__init", !mem2node__init(&map, &env));
T("failed: mem2node__node", 0 == mem2node__node(&map, 0x50));
T("failed: mem2node__node", 1 == mem2node__node(&map, 0x100));
T("failed: mem2node__node", 1 == mem2node__node(&map, 0x250));
T("failed: mem2node__node", 3 == mem2node__node(&map, 0x500));
T("failed: mem2node__node", 3 == mem2node__node(&map, 0x650));
T("failed: mem2node__node", -1 == mem2node__node(&map, 0x450));
T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050));
for (i = 0; i < ARRAY_SIZE(nodes); i++)
zfree(&nodes[i].set);
mem2node__exit(&map);
return 0;
}
DEFINE_SUITE("mem2node", mem2node);