Commit 397721e0 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

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: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 959b83c7
...@@ -3,3 +3,16 @@ ...@@ -3,3 +3,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include <internal/cpumap.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;
}
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
#ifndef __LIBPERF_CPUMAP_H #ifndef __LIBPERF_CPUMAP_H
#define __LIBPERF_CPUMAP_H #define __LIBPERF_CPUMAP_H
#include <perf/core.h>
struct perf_cpu_map; struct perf_cpu_map;
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
#endif /* __LIBPERF_CPUMAP_H */ #endif /* __LIBPERF_CPUMAP_H */
LIBPERF_0.0.1 { LIBPERF_0.0.1 {
global: global:
libperf_set_print; libperf_set_print;
perf_cpu_map__dummy_new;
local: local:
*; *;
}; };
...@@ -56,7 +56,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) ...@@ -56,7 +56,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
} }
evlist__add(evlist, evsel); evlist__add(evlist, evsel);
cpus = cpu_map__dummy_new(); cpus = perf_cpu_map__dummy_new();
threads = thread_map__new_by_tid(getpid()); threads = thread_map__new_by_tid(getpid());
if (!cpus || !threads) { if (!cpus || !threads) {
err = -ENOMEM; err = -ENOMEM;
......
...@@ -63,7 +63,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused ...@@ -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 * perf_evlist__prepare_workload we'll fill in the only thread
* we're monitoring, the one forked there. * 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); threads = thread_map__new_by_tid(-1);
if (!cpus || !threads) { if (!cpus || !threads) {
err = -ENOMEM; err = -ENOMEM;
......
...@@ -189,7 +189,7 @@ struct perf_cpu_map *cpu_map__new(const char *cpu_list) ...@@ -189,7 +189,7 @@ struct perf_cpu_map *cpu_map__new(const char *cpu_list)
else if (*cpu_list != '\0') else if (*cpu_list != '\0')
cpus = cpu_map__default_new(); cpus = cpu_map__default_new();
else else
cpus = cpu_map__dummy_new(); cpus = perf_cpu_map__dummy_new();
invalid: invalid:
free(tmp_cpus); free(tmp_cpus);
out: out:
...@@ -256,19 +256,6 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp) ...@@ -256,19 +256,6 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
#undef BUFSIZE #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 *cpu_map__empty_new(int nr)
{ {
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr); struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
#include <stdbool.h> #include <stdbool.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include <internal/cpumap.h> #include <internal/cpumap.h>
#include <perf/cpumap.h>
#include "perf.h" #include "perf.h"
#include "util/debug.h" #include "util/debug.h"
struct perf_cpu_map *cpu_map__new(const char *cpu_list); 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__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__new_data(struct cpu_map_data *data);
struct perf_cpu_map *cpu_map__read(FILE *file); struct perf_cpu_map *cpu_map__read(FILE *file);
size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
......
...@@ -1086,7 +1086,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target) ...@@ -1086,7 +1086,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
return -1; return -1;
if (target__uses_dummy_map(target)) if (target__uses_dummy_map(target))
cpus = cpu_map__dummy_new(); cpus = perf_cpu_map__dummy_new();
else else
cpus = cpu_map__new(target->cpu_list); cpus = cpu_map__new(target->cpu_list);
......
...@@ -1840,7 +1840,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, ...@@ -1840,7 +1840,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
static struct perf_cpu_map *empty_cpu_map; static struct perf_cpu_map *empty_cpu_map;
if (empty_cpu_map == NULL) { 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) if (empty_cpu_map == NULL)
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment