libperf: Add perf_cpu_map__dummy_new() function

Move cpu_map__dummy_new() to libperf as perf_cpu_map__dummy_new() function.

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-30-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:16 +02:00 committed by Arnaldo Carvalho de Melo
parent 959b83c769
commit 397721e06e
9 changed files with 24 additions and 19 deletions

View file

@ -3,3 +3,16 @@
#include <stdlib.h>
#include <linux/refcount.h>
#include <internal/cpumap.h>
struct perf_cpu_map *perf_cpu_map__dummy_new(void)
{
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int));
if (cpus != NULL) {
cpus->nr = 1;
cpus->map[0] = -1;
refcount_set(&cpus->refcnt, 1);
}
return cpus;
}

View file

@ -2,6 +2,10 @@
#ifndef __LIBPERF_CPUMAP_H
#define __LIBPERF_CPUMAP_H
#include <perf/core.h>
struct perf_cpu_map;
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
#endif /* __LIBPERF_CPUMAP_H */

View file

@ -1,6 +1,7 @@
LIBPERF_0.0.1 {
global:
libperf_set_print;
perf_cpu_map__dummy_new;
local:
*;
};

View file

@ -56,7 +56,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
}
evlist__add(evlist, evsel);
cpus = cpu_map__dummy_new();
cpus = perf_cpu_map__dummy_new();
threads = thread_map__new_by_tid(getpid());
if (!cpus || !threads) {
err = -ENOMEM;

View file

@ -63,7 +63,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
* perf_evlist__prepare_workload we'll fill in the only thread
* we're monitoring, the one forked there.
*/
cpus = cpu_map__dummy_new();
cpus = perf_cpu_map__dummy_new();
threads = thread_map__new_by_tid(-1);
if (!cpus || !threads) {
err = -ENOMEM;

View file

@ -189,7 +189,7 @@ struct perf_cpu_map *cpu_map__new(const char *cpu_list)
else if (*cpu_list != '\0')
cpus = cpu_map__default_new();
else
cpus = cpu_map__dummy_new();
cpus = perf_cpu_map__dummy_new();
invalid:
free(tmp_cpus);
out:
@ -256,19 +256,6 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
#undef BUFSIZE
}
struct perf_cpu_map *cpu_map__dummy_new(void)
{
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int));
if (cpus != NULL) {
cpus->nr = 1;
cpus->map[0] = -1;
refcount_set(&cpus->refcnt, 1);
}
return cpus;
}
struct perf_cpu_map *cpu_map__empty_new(int nr)
{
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);

View file

@ -6,13 +6,13 @@
#include <stdbool.h>
#include <linux/refcount.h>
#include <internal/cpumap.h>
#include <perf/cpumap.h>
#include "perf.h"
#include "util/debug.h"
struct perf_cpu_map *cpu_map__new(const char *cpu_list);
struct perf_cpu_map *cpu_map__empty_new(int nr);
struct perf_cpu_map *cpu_map__dummy_new(void);
struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data);
struct perf_cpu_map *cpu_map__read(FILE *file);
size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);

View file

@ -1086,7 +1086,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
return -1;
if (target__uses_dummy_map(target))
cpus = cpu_map__dummy_new();
cpus = perf_cpu_map__dummy_new();
else
cpus = cpu_map__new(target->cpu_list);

View file

@ -1840,7 +1840,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
static struct perf_cpu_map *empty_cpu_map;
if (empty_cpu_map == NULL) {
empty_cpu_map = cpu_map__dummy_new();
empty_cpu_map = perf_cpu_map__dummy_new();
if (empty_cpu_map == NULL)
return -ENOMEM;
}