libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions

Moving the following functions from tools/perf:

  cpu_map__new()
  cpu_map__read()

to libperf with the following names:

  perf_cpu_map__new()
  perf_cpu_map__read()

Committer notes:

Fixed up this one:

  tools/perf/arch/arm/util/cs-etm.c

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190721112506.12306-44-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Jiri Olsa
2019-07-21 13:24:30 +02:00
committed by Arnaldo Carvalho de Melo
parent 1fc632cef4
commit 9c3516d1b8
37 changed files with 265 additions and 227 deletions

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <linux/bitmap.h>
#include <perf/cpumap.h>
#include "tests.h"
#include "cpumap.h"
#include "debug.h"
@@ -9,7 +10,7 @@
static unsigned long *get_bitmap(const char *str, int nbits)
{
struct perf_cpu_map *map = cpu_map__new(str);
struct perf_cpu_map *map = perf_cpu_map__new(str);
unsigned long *bm = NULL;
int i;

View File

@@ -8,6 +8,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <perf/cpumap.h>
#include "parse-events.h"
#include "evlist.h"
@@ -613,9 +614,9 @@ static int do_test_code_reading(bool try_kcore)
goto out_put;
}
cpus = cpu_map__new(NULL);
cpus = perf_cpu_map__new(NULL);
if (!cpus) {
pr_debug("cpu_map__new failed\n");
pr_debug("perf_cpu_map__new failed\n");
goto out_put;
}

View File

@@ -5,6 +5,7 @@
#include "event.h"
#include <string.h>
#include <linux/bitops.h>
#include <perf/cpumap.h>
#include "debug.h"
struct machine;
@@ -78,7 +79,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may
struct perf_cpu_map *cpus;
/* This one is better stores in mask. */
cpus = cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
cpus = perf_cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
TEST_ASSERT_VAL("failed to synthesize map",
!perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL));
@@ -86,7 +87,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may
perf_cpu_map__put(cpus);
/* This one is better stores in cpu values. */
cpus = cpu_map__new("1,256");
cpus = perf_cpu_map__new("1,256");
TEST_ASSERT_VAL("failed to synthesize map",
!perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL));
@@ -97,7 +98,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may
static int cpu_map_print(const char *str)
{
struct perf_cpu_map *map = cpu_map__new(str);
struct perf_cpu_map *map = perf_cpu_map__new(str);
char buf[100];
if (!map)

View File

@@ -4,6 +4,7 @@
#include <inttypes.h>
#include <string.h>
#include <sys/wait.h>
#include <perf/cpumap.h>
#include "tests.h"
#include "evlist.h"
#include "evsel.h"
@@ -115,9 +116,9 @@ static int attach__cpu_disabled(struct evlist *evlist)
pr_debug("attaching to CPU 0 as enabled\n");
cpus = cpu_map__new("0");
cpus = perf_cpu_map__new("0");
if (cpus == NULL) {
pr_debug("failed to call cpu_map__new\n");
pr_debug("failed to call perf_cpu_map__new\n");
return -1;
}
@@ -144,9 +145,9 @@ static int attach__cpu_enabled(struct evlist *evlist)
pr_debug("attaching to CPU 0 as enabled\n");
cpus = cpu_map__new("0");
cpus = perf_cpu_map__new("0");
if (cpus == NULL) {
pr_debug("failed to call cpu_map__new\n");
pr_debug("failed to call perf_cpu_map__new\n");
return -1;
}

View File

@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <perf/cpumap.h>
#include "evlist.h"
#include "evsel.h"
#include "machine.h"
@@ -108,7 +109,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
TEST_ASSERT_VAL("failed to synthesize attr update name",
!perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
evsel->own_cpus = cpu_map__new("1,2,3");
evsel->own_cpus = perf_cpu_map__new("1,2,3");
TEST_ASSERT_VAL("failed to synthesize attr update cpus",
!perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));

View File

@@ -2,6 +2,7 @@
#include <linux/types.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <perf/cpumap.h>
#include "parse-events.h"
#include "evlist.h"
@@ -75,7 +76,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
threads = thread_map__new(-1, getpid(), UINT_MAX);
CHECK_NOT_NULL__(threads);
cpus = cpu_map__new(NULL);
cpus = perf_cpu_map__new(NULL);
CHECK_NOT_NULL__(cpus);
evlist = evlist__new();

View File

@@ -2,6 +2,7 @@
#include <linux/compiler.h>
#include <linux/bitmap.h>
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include "cpumap.h"
#include "mem2node.h"
#include "tests.h"
@@ -19,7 +20,7 @@ static struct node {
static unsigned long *get_bitmap(const char *str, int nbits)
{
struct perf_cpu_map *map = cpu_map__new(str);
struct perf_cpu_map *map = perf_cpu_map__new(str);
unsigned long *bm = NULL;
int i;

View File

@@ -3,6 +3,7 @@
#include <inttypes.h>
/* For the CLR_() macros */
#include <pthread.h>
#include <perf/cpumap.h>
#include "evlist.h"
#include "evsel.h"
@@ -46,7 +47,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
return -1;
}
cpus = cpu_map__new(NULL);
cpus = perf_cpu_map__new(NULL);
if (cpus == NULL) {
pr_debug("cpu_map__new\n");
goto out_free_threads;

View File

@@ -33,7 +33,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int
return -1;
}
cpus = cpu_map__new(NULL);
cpus = perf_cpu_map__new(NULL);
if (cpus == NULL) {
pr_debug("cpu_map__new\n");
goto out_thread_map_delete;

View File

@@ -5,6 +5,7 @@
#include <time.h>
#include <stdlib.h>
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include "parse-events.h"
#include "evlist.h"
@@ -341,9 +342,9 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err;
}
cpus = cpu_map__new(NULL);
cpus = perf_cpu_map__new(NULL);
if (!cpus) {
pr_debug("cpu_map__new failed!\n");
pr_debug("perf_cpu_map__new failed!\n");
goto out_err;
}

View File

@@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <perf/cpumap.h>
#include "tests.h"
#include "util.h"
#include "session.h"
@@ -126,7 +127,7 @@ int test__session_topology(struct test *test __maybe_unused, int subtest __maybe
if (session_write_header(path))
goto free_path;
map = cpu_map__new(NULL);
map = perf_cpu_map__new(NULL);
if (map == NULL) {
pr_debug("failed to get system cpumap\n");
goto free_path;