hi,
sending fixes for tools and libperf.
thanks,
jirka
---
Jiri Olsa (5):
tools: Add missing perf_event.h include
libperf: Use perf_cpu_map__nr instead of cpu_map__nr
libperf: Move cpu_map__empty to perf_cpu_map__empty
libperf: Move cpu_map__idx to perf_cpu_map__idx
libperf: Add perf_thread_map__nr/perf_thread_map__pid functions
tools/include/linux/ring_buffer.h | 1 +
tools/perf/arch/arm/util/cs-etm.c | 12 ++++++------
tools/perf/arch/x86/util/intel-bts.c | 4 ++--
tools/perf/arch/x86/util/intel-pt.c | 10 +++++-----
tools/perf/builtin-c2c.c | 2 +-
tools/perf/builtin-ftrace.c | 2 +-
tools/perf/builtin-script.c | 4 ++--
tools/perf/builtin-stat.c | 8 ++++----
tools/perf/builtin-trace.c | 4 ++--
tools/perf/lib/cpumap.c | 17 +++++++++++++++++
tools/perf/lib/include/internal/cpumap.h | 2 ++
tools/perf/lib/include/perf/cpumap.h | 2 ++
tools/perf/lib/include/perf/threadmap.h | 2 ++
tools/perf/lib/libperf.map | 3 +++
tools/perf/lib/threadmap.c | 10 ++++++++++
tools/perf/tests/thread-map.c | 6 +++---
tools/perf/util/auxtrace.c | 4 ++--
tools/perf/util/cpumap.c | 20 ++++----------------
tools/perf/util/cpumap.h | 13 +------------
tools/perf/util/event.c | 10 +++++-----
tools/perf/util/evlist.c | 30 +++++++++++++++---------------
tools/perf/util/evsel.c | 4 ++--
tools/perf/util/mmap.c | 2 +-
tools/perf/util/record.c | 2 +-
tools/perf/util/scripting-engines/trace-event-python.c | 2 +-
tools/perf/util/stat-display.c | 6 +++---
tools/perf/util/stat.c | 6 +++---
tools/perf/util/thread_map.c | 4 ++--
tools/perf/util/thread_map.h | 10 ----------
29 files changed, 103 insertions(+), 99 deletions(-)
Switch the rest of the perf code to use perf_cpu_map__nr,
which is the same as current cpu_map__nr and remove
cpu_map__nr function.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 4 ++--
tools/perf/util/cpumap.h | 5 -----
tools/perf/util/evlist.c | 10 +++++-----
tools/perf/util/mmap.c | 2 +-
tools/perf/util/stat-display.c | 2 +-
5 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 5cb07e8cb296..c786ab095d15 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -653,7 +653,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
cpu_map = online_cpus;
} else {
/* Make sure all specified CPUs are online */
- for (i = 0; i < cpu_map__nr(event_cpus); i++) {
+ for (i = 0; i < perf_cpu_map__nr(event_cpus); i++) {
if (cpu_map__has(event_cpus, i) &&
!cpu_map__has(online_cpus, i))
return -EINVAL;
@@ -662,7 +662,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
cpu_map = event_cpus;
}
- nr_cpu = cpu_map__nr(cpu_map);
+ nr_cpu = perf_cpu_map__nr(cpu_map);
/* Get PMU type as dynamically assigned by the core */
type = cs_etm_pmu->type;
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index a3d27f4131be..77f85e9c88d4 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -49,11 +49,6 @@ static inline int cpu_map__id_to_cpu(int id)
return id & 0xffff;
}
-static inline int cpu_map__nr(const struct perf_cpu_map *map)
-{
- return map ? map->nr : 1;
-}
-
static inline bool cpu_map__empty(const struct perf_cpu_map *map)
{
return map ? map->map[0] == -1 : true;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c4489a1ad6bc..15d1046014d7 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -370,7 +370,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,
int thread)
{
int cpu;
- int nr_cpus = cpu_map__nr(evlist->core.cpus);
+ int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
if (!evsel->core.fd)
return -EINVAL;
@@ -396,7 +396,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
int perf_evlist__alloc_pollfd(struct evlist *evlist)
{
- int nr_cpus = cpu_map__nr(evlist->core.cpus);
+ int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
int nr_threads = thread_map__nr(evlist->core.threads);
int nfds = 0;
struct evsel *evsel;
@@ -692,7 +692,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
int i;
struct perf_mmap *map;
- evlist->nr_mmaps = cpu_map__nr(evlist->core.cpus);
+ evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
@@ -807,7 +807,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
struct mmap_params *mp)
{
int cpu, thread;
- int nr_cpus = cpu_map__nr(evlist->core.cpus);
+ int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
int nr_threads = thread_map__nr(evlist->core.threads);
pr_debug2("perf event ring buffer mmapped per cpu\n");
@@ -1014,7 +1014,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
evlist__for_each_entry(evlist, evsel) {
if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
evsel->sample_id == NULL &&
- perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
+ perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
return -ENOMEM;
}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 42a5971146ae..5f3532e51ec9 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -331,7 +331,7 @@ static void build_node_mask(int node, cpu_set_t *mask)
if (!cpu_map)
return;
- nr_cpus = cpu_map__nr(cpu_map);
+ nr_cpus = perf_cpu_map__nr(cpu_map);
for (c = 0; c < nr_cpus; c++) {
cpu = cpu_map->map[c]; /* map c index to online cpu index */
if (cpu__get_node(cpu) == node)
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index f7b39f4bc51e..3df0e39ccd52 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -745,7 +745,7 @@ static void print_aggr_thread(struct perf_stat_config *config,
{
FILE *output = config->output;
int nthreads = thread_map__nr(counter->core.threads);
- int ncpus = cpu_map__nr(counter->core.cpus);
+ int ncpus = perf_cpu_map__nr(counter->core.cpus);
int thread, sorted_threads, id;
struct perf_aggr_thread_value *buf;
--
2.21.0
As an internal function that will be used by both
perf and libperf, but is not exported at this point.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/cpumap.c | 12 ++++++++++++
tools/perf/lib/include/internal/cpumap.h | 2 ++
tools/perf/util/cpumap.c | 14 +-------------
tools/perf/util/cpumap.h | 1 -
tools/perf/util/evlist.c | 2 +-
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 63f7df7e47ff..2834753576b2 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -242,3 +242,15 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map)
{
return map ? map->map[0] == -1 : true;
}
+
+int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
+{
+ int i;
+
+ for (i = 0; i < cpus->nr; ++i) {
+ if (cpus->map[i] == cpu)
+ return i;
+ }
+
+ return -1;
+}
diff --git a/tools/perf/lib/include/internal/cpumap.h b/tools/perf/lib/include/internal/cpumap.h
index 3306319f7df8..840d4032587b 100644
--- a/tools/perf/lib/include/internal/cpumap.h
+++ b/tools/perf/lib/include/internal/cpumap.h
@@ -14,4 +14,6 @@ struct perf_cpu_map {
#define MAX_NR_CPUS 2048
#endif
+int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
+
#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 4402e67445a4..8e6c2cbffedc 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -458,19 +458,7 @@ int cpu__setup_cpunode_map(void)
bool cpu_map__has(struct perf_cpu_map *cpus, int cpu)
{
- return cpu_map__idx(cpus, cpu) != -1;
-}
-
-int cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
-{
- int i;
-
- for (i = 0; i < cpus->nr; ++i) {
- if (cpus->map[i] == cpu)
- return i;
- }
-
- return -1;
+ return perf_cpu_map__idx(cpus, cpu) != -1;
}
int cpu_map__cpu(struct perf_cpu_map *cpus, int idx)
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 3e068090612f..8dbedda7af45 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -62,5 +62,4 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
-int cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
#endif /* __PERF_CPUMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ba49b5ecffd0..8582560b59af 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -758,7 +758,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
if (evsel->system_wide && thread)
continue;
- cpu = cpu_map__idx(evsel->core.cpus, evlist_cpu);
+ cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
if (cpu == -1)
continue;
--
2.21.0
We need perf_event.h include for 'struct perf_event_mmap_page'.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/include/linux/ring_buffer.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/include/linux/ring_buffer.h b/tools/include/linux/ring_buffer.h
index 9a083ae60473..6c02617377c2 100644
--- a/tools/include/linux/ring_buffer.h
+++ b/tools/include/linux/ring_buffer.h
@@ -2,6 +2,7 @@
#define _TOOLS_LINUX_RING_BUFFER_H_
#include <asm/barrier.h>
+#include <linux/perf_event.h>
/*
* Contract with kernel for walking the perf ring buffer from
--
2.21.0
So it's part of libperf library as one of basic functions
over struct perf_cpu_map object.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 8 ++++----
tools/perf/arch/x86/util/intel-bts.c | 4 ++--
tools/perf/arch/x86/util/intel-pt.c | 10 +++++-----
tools/perf/builtin-c2c.c | 2 +-
tools/perf/builtin-stat.c | 4 ++--
tools/perf/lib/cpumap.c | 5 +++++
tools/perf/lib/include/perf/cpumap.h | 2 ++
tools/perf/lib/libperf.map | 1 +
tools/perf/util/cpumap.c | 6 +++---
tools/perf/util/cpumap.h | 7 +------
tools/perf/util/event.c | 2 +-
tools/perf/util/evlist.c | 6 +++---
tools/perf/util/record.c | 2 +-
tools/perf/util/stat.c | 2 +-
14 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index c786ab095d15..c73da3245b67 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -396,7 +396,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
* AUX event. We also need the contextID in order to be notified
* when a context switch happened.
*/
- if (!cpu_map__empty(cpus)) {
+ if (!perf_cpu_map__empty(cpus)) {
perf_evsel__set_sample_bit(cs_etm_evsel, CPU);
err = cs_etm_set_option(itr, cs_etm_evsel,
@@ -420,7 +420,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
tracking_evsel->core.attr.sample_period = 1;
/* In per-cpu case, always need the time of mmap events etc */
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(tracking_evsel, TIME);
}
@@ -493,7 +493,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
/* cpu map is not empty, we have specific CPUs to work with */
- if (!cpu_map__empty(event_cpus)) {
+ if (!perf_cpu_map__empty(event_cpus)) {
for (i = 0; i < cpu__max_cpu(); i++) {
if (!cpu_map__has(event_cpus, i) ||
!cpu_map__has(online_cpus, i))
@@ -649,7 +649,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
return -EINVAL;
/* If the cpu_map is empty all online CPUs are involved */
- if (cpu_map__empty(event_cpus)) {
+ if (perf_cpu_map__empty(event_cpus)) {
cpu_map = online_cpus;
} else {
/* Make sure all specified CPUs are online */
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 7b23318ebd7b..2d5d8a12dd1f 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -133,7 +133,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
if (!opts->full_auxtrace)
return 0;
- if (opts->full_auxtrace && !cpu_map__empty(cpus)) {
+ if (opts->full_auxtrace && !perf_cpu_map__empty(cpus)) {
pr_err(INTEL_BTS_PMU_NAME " does not support per-cpu recording\n");
return -EINVAL;
}
@@ -214,7 +214,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
* In the case of per-cpu mmaps, we need the CPU on the
* AUX event.
*/
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(intel_bts_evsel, CPU);
}
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a8e633aa278a..c72a77a82b39 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -365,7 +365,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
ui__warning("Intel Processor Trace: TSC not available\n");
}
- per_cpu_mmaps = !cpu_map__empty(session->evlist->core.cpus);
+ per_cpu_mmaps = !perf_cpu_map__empty(session->evlist->core.cpus);
auxtrace_info->type = PERF_AUXTRACE_INTEL_PT;
auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type;
@@ -702,7 +702,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* Per-cpu recording needs sched_switch events to distinguish different
* threads.
*/
- if (have_timing_info && !cpu_map__empty(cpus)) {
+ if (have_timing_info && !perf_cpu_map__empty(cpus)) {
if (perf_can_record_switch_events()) {
bool cpu_wide = !target__none(&opts->target) &&
!target__has_task(&opts->target);
@@ -760,7 +760,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* In the case of per-cpu mmaps, we need the CPU on the
* AUX event.
*/
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(intel_pt_evsel, CPU);
}
@@ -784,7 +784,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
tracking_evsel->immediate = true;
/* In per-cpu case, always need the time of mmap events etc */
- if (!cpu_map__empty(cpus)) {
+ if (!perf_cpu_map__empty(cpus)) {
perf_evsel__set_sample_bit(tracking_evsel, TIME);
/* And the CPU for switch events */
perf_evsel__set_sample_bit(tracking_evsel, CPU);
@@ -796,7 +796,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* Warn the user when we do not have enough information to decode i.e.
* per-cpu with no sched_switch (except workload-only).
*/
- if (!ptr->have_sched_switch && !cpu_map__empty(cpus) &&
+ if (!ptr->have_sched_switch && !perf_cpu_map__empty(cpus) &&
!target__none(&opts->target))
ui__warning("Intel Processor Trace decoding will not be possible except for kernel tracing!\n");
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index f0aae6e13a33..01629f5b6d1f 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2059,7 +2059,7 @@ static int setup_nodes(struct perf_session *session)
nodes[node] = set;
/* empty node, skip */
- if (cpu_map__empty(map))
+ if (perf_cpu_map__empty(map))
continue;
for (cpu = 0; cpu < map->nr; cpu++) {
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b19df671111e..90636a811b36 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -928,7 +928,7 @@ static int perf_stat_init_aggr_mode(void)
* the aggregation translate cpumap.
*/
nr = cpu_map__get_max(evsel_list->core.cpus);
- stat_config.cpus_aggr_map = cpu_map__empty_new(nr + 1);
+ stat_config.cpus_aggr_map = perf_cpu_map__empty_new(nr + 1);
return stat_config.cpus_aggr_map ? 0 : -ENOMEM;
}
@@ -1493,7 +1493,7 @@ int process_stat_config_event(struct perf_session *session,
perf_event__read_stat_config(&stat_config, &event->stat_config);
- if (cpu_map__empty(st->cpus)) {
+ if (perf_cpu_map__empty(st->cpus)) {
if (st->aggr_mode != AGGR_UNSET)
pr_warning("warning: processing task data, aggregation mode not set\n");
return 0;
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 1ddb69e796e5..63f7df7e47ff 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -237,3 +237,8 @@ int perf_cpu_map__nr(const struct perf_cpu_map *cpus)
{
return cpus ? cpus->nr : 1;
}
+
+bool perf_cpu_map__empty(const struct perf_cpu_map *map)
+{
+ return map ? map->map[0] == -1 : true;
+}
diff --git a/tools/perf/lib/include/perf/cpumap.h b/tools/perf/lib/include/perf/cpumap.h
index 1b6e7db3fa2b..8aa995c59498 100644
--- a/tools/perf/lib/include/perf/cpumap.h
+++ b/tools/perf/lib/include/perf/cpumap.h
@@ -4,6 +4,7 @@
#include <perf/core.h>
#include <stdio.h>
+#include <stdbool.h>
struct perf_cpu_map;
@@ -14,6 +15,7 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
+LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map);
#define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \
for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index e24d3cec01c1..3373dd51fcda 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -8,6 +8,7 @@ LIBPERF_0.0.1 {
perf_cpu_map__read;
perf_cpu_map__nr;
perf_cpu_map__cpu;
+ perf_cpu_map__empty;
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
perf_thread_map__comm;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index beb3525e9e45..4402e67445a4 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -21,7 +21,7 @@ static struct perf_cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus)
{
struct perf_cpu_map *map;
- map = cpu_map__empty_new(cpus->nr);
+ map = perf_cpu_map__empty_new(cpus->nr);
if (map) {
unsigned i;
@@ -48,7 +48,7 @@ static struct perf_cpu_map *cpu_map__from_mask(struct cpu_map_mask *mask)
nr = bitmap_weight(mask->mask, nbits);
- map = cpu_map__empty_new(nr);
+ map = perf_cpu_map__empty_new(nr);
if (map) {
int cpu, i = 0;
@@ -77,7 +77,7 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
#undef BUFSIZE
}
-struct perf_cpu_map *cpu_map__empty_new(int nr)
+struct perf_cpu_map *perf_cpu_map__empty_new(int nr)
{
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 77f85e9c88d4..3e068090612f 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -11,7 +11,7 @@
#include "perf.h"
#include "util/debug.h"
-struct perf_cpu_map *cpu_map__empty_new(int nr);
+struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data);
size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
@@ -49,11 +49,6 @@ static inline int cpu_map__id_to_cpu(int id)
return id & 0xffff;
}
-static inline bool cpu_map__empty(const struct perf_cpu_map *map)
-{
- return map ? map->map[0] == -1 : true;
-}
-
int cpu__setup_cpunode_map(void);
int cpu__max_node(void);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f440fdc3e953..f433da85c45e 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1055,7 +1055,7 @@ static size_t mask_size(struct perf_cpu_map *map, int *max)
void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max)
{
size_t size_cpus, size_mask;
- bool is_dummy = cpu_map__empty(map);
+ bool is_dummy = perf_cpu_map__empty(map);
/*
* Both array and mask data have variable size based
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 15d1046014d7..ba49b5ecffd0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -386,7 +386,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,
int perf_evlist__enable_event_idx(struct evlist *evlist,
struct evsel *evsel, int idx)
{
- bool per_cpu_mmaps = !cpu_map__empty(evlist->core.cpus);
+ bool per_cpu_mmaps = !perf_cpu_map__empty(evlist->core.cpus);
if (per_cpu_mmaps)
return perf_evlist__enable_event_cpu(evlist, evsel, idx);
@@ -693,7 +693,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
struct perf_mmap *map;
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
- if (cpu_map__empty(evlist->core.cpus))
+ if (perf_cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!map)
@@ -1018,7 +1018,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
return -ENOMEM;
}
- if (cpu_map__empty(cpus))
+ if (perf_cpu_map__empty(cpus))
return perf_evlist__mmap_per_thread(evlist, &mp);
return perf_evlist__mmap_per_cpu(evlist, &mp);
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index e59382d99196..51bbd0714e6d 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -275,7 +275,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str)
evsel = perf_evlist__last(temp_evlist);
- if (!evlist || cpu_map__empty(evlist->core.cpus)) {
+ if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) {
struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
cpu = cpus ? cpus->map[0] : 0;
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index e4e4e3bf8b2b..2715112290cf 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -223,7 +223,7 @@ static int check_per_pkg(struct evsel *counter,
if (!counter->per_pkg)
return 0;
- if (cpu_map__empty(cpus))
+ if (perf_cpu_map__empty(cpus))
return 0;
if (!mask) {
--
2.21.0
So it's part of libperf library as basic functions
over struct perf_thread_map object.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-ftrace.c | 2 +-
tools/perf/builtin-script.c | 4 ++--
tools/perf/builtin-stat.c | 4 ++--
tools/perf/builtin-trace.c | 4 ++--
tools/perf/lib/include/perf/threadmap.h | 2 ++
tools/perf/lib/libperf.map | 2 ++
tools/perf/lib/threadmap.c | 10 ++++++++++
tools/perf/tests/thread-map.c | 6 +++---
tools/perf/util/auxtrace.c | 4 ++--
tools/perf/util/event.c | 8 ++++----
tools/perf/util/evlist.c | 12 ++++++------
tools/perf/util/evsel.c | 4 ++--
.../perf/util/scripting-engines/trace-event-python.c | 2 +-
tools/perf/util/stat-display.c | 4 ++--
tools/perf/util/stat.c | 4 ++--
tools/perf/util/thread_map.c | 4 ++--
tools/perf/util/thread_map.h | 10 ----------
17 files changed, 45 insertions(+), 41 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 1367bb5046a7..565db782c1b9 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -158,7 +158,7 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
if (target__has_cpu(&ftrace->target))
return 0;
- for (i = 0; i < thread_map__nr(ftrace->evlist->core.threads); i++) {
+ for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) {
scnprintf(buf, sizeof(buf), "%d",
ftrace->evlist->core.threads->map[i]);
if (append_tracing_file("set_ftrace_pid", buf) < 0)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1764efd16cd4..5d45be1d3885 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1905,7 +1905,7 @@ static struct scripting_ops *scripting_ops;
static void __process_stat(struct evsel *counter, u64 tstamp)
{
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
static int header_printed;
@@ -1927,7 +1927,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp)
printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n",
counter->core.cpus->map[cpu],
- thread_map__pid(counter->core.threads, thread),
+ perf_thread_map__pid(counter->core.threads, thread),
counts->val,
counts->ena,
counts->run,
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 90636a811b36..8a4f1a7d0cba 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -264,7 +264,7 @@ static int read_single_counter(struct evsel *counter, int cpu,
*/
static int read_counter(struct evsel *counter, struct timespec *rs)
{
- int nthreads = thread_map__nr(evsel_list->core.threads);
+ int nthreads = perf_thread_map__nr(evsel_list->core.threads);
int ncpus, cpu, thread;
if (target__has_cpu(&target) && !target__has_per_thread(&target))
@@ -1893,7 +1893,7 @@ int cmd_stat(int argc, const char **argv)
thread_map__read_comms(evsel_list->core.threads);
if (target.system_wide) {
if (runtime_stat_new(&stat_config,
- thread_map__nr(evsel_list->core.threads))) {
+ perf_thread_map__nr(evsel_list->core.threads))) {
goto out;
}
}
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bc44ed29e05a..de126258ca10 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3188,7 +3188,7 @@ static int trace__set_filter_pids(struct trace *trace)
err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
trace->filter_pids.entries);
}
- } else if (thread_map__pid(trace->evlist->core.threads, 0) == -1) {
+ } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
err = trace__set_filter_loop_pids(trace);
}
@@ -3417,7 +3417,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
evlist__enable(evlist);
}
- trace->multiple_threads = thread_map__pid(evlist->core.threads, 0) == -1 ||
+ trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
evlist->core.threads->nr > 1 ||
perf_evlist__first(evlist)->core.attr.inherit;
diff --git a/tools/perf/lib/include/perf/threadmap.h b/tools/perf/lib/include/perf/threadmap.h
index 456295273daa..a7c50de8d010 100644
--- a/tools/perf/lib/include/perf/threadmap.h
+++ b/tools/perf/lib/include/perf/threadmap.h
@@ -11,6 +11,8 @@ LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
+LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads);
+LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 3373dd51fcda..dc4d66363bc4 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -12,6 +12,8 @@ LIBPERF_0.0.1 {
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
perf_thread_map__comm;
+ perf_thread_map__nr;
+ perf_thread_map__pid;
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__new;
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
index 4865b73e2586..e92c368b0a6c 100644
--- a/tools/perf/lib/threadmap.c
+++ b/tools/perf/lib/threadmap.c
@@ -79,3 +79,13 @@ void perf_thread_map__put(struct perf_thread_map *map)
if (map && refcount_dec_and_test(&map->refcnt))
perf_thread_map__delete(map);
}
+
+int perf_thread_map__nr(struct perf_thread_map *threads)
+{
+ return threads ? threads->nr : 1;
+}
+
+pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread)
+{
+ return map->map[thread].pid;
+}
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index d61773cacf0b..d803eafedc60 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -26,7 +26,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
TEST_ASSERT_VAL("wrong nr", map->nr == 1);
TEST_ASSERT_VAL("wrong pid",
- thread_map__pid(map, 0) == getpid());
+ perf_thread_map__pid(map, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(map, 0) &&
!strcmp(perf_thread_map__comm(map, 0), NAME));
@@ -41,7 +41,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
thread_map__read_comms(map);
TEST_ASSERT_VAL("wrong nr", map->nr == 1);
- TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
+ TEST_ASSERT_VAL("wrong pid", perf_thread_map__pid(map, 0) == -1);
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(map, 0) &&
!strcmp(perf_thread_map__comm(map, 0), "dummy"));
@@ -68,7 +68,7 @@ static int process_event(struct perf_tool *tool __maybe_unused,
TEST_ASSERT_VAL("wrong nr", threads->nr == 1);
TEST_ASSERT_VAL("wrong pid",
- thread_map__pid(threads, 0) == getpid());
+ perf_thread_map__pid(threads, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(threads, 0) &&
!strcmp(perf_thread_map__comm(threads, 0), NAME));
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 60428576426e..094e6ceb3cf2 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -132,12 +132,12 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
if (per_cpu) {
mp->cpu = evlist->core.cpus->map[idx];
if (evlist->core.threads)
- mp->tid = thread_map__pid(evlist->core.threads, 0);
+ mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
else
mp->tid = -1;
} else {
mp->cpu = -1;
- mp->tid = thread_map__pid(evlist->core.threads, idx);
+ mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
}
}
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f433da85c45e..332edef8d394 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -647,7 +647,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
for (thread = 0; thread < threads->nr; ++thread) {
if (__event__synthesize_thread(comm_event, mmap_event,
fork_event, namespaces_event,
- thread_map__pid(threads, thread), 0,
+ perf_thread_map__pid(threads, thread), 0,
process, tool, machine,
mmap_data)) {
err = -1;
@@ -658,12 +658,12 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
* comm.pid is set to thread group id by
* perf_event__synthesize_comm
*/
- if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) {
+ if ((int) comm_event->comm.pid != perf_thread_map__pid(threads, thread)) {
bool need_leader = true;
/* is thread group leader in thread_map? */
for (j = 0; j < threads->nr; ++j) {
- if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) {
+ if ((int) comm_event->comm.pid == perf_thread_map__pid(threads, j)) {
need_leader = false;
break;
}
@@ -997,7 +997,7 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
if (!comm)
comm = (char *) "";
- entry->pid = thread_map__pid(threads, i);
+ entry->pid = perf_thread_map__pid(threads, i);
strncpy((char *) &entry->comm, comm, sizeof(entry->comm));
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8582560b59af..23b56717d260 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -314,7 +314,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
if (evsel->system_wide)
return 1;
else
- return thread_map__nr(evlist->core.threads);
+ return perf_thread_map__nr(evlist->core.threads);
}
void evlist__disable(struct evlist *evlist)
@@ -397,7 +397,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
int perf_evlist__alloc_pollfd(struct evlist *evlist)
{
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
int nfds = 0;
struct evsel *evsel;
@@ -529,7 +529,7 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist,
else
sid->cpu = -1;
if (!evsel->system_wide && evlist->core.threads && thread >= 0)
- sid->tid = thread_map__pid(evlist->core.threads, thread);
+ sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
else
sid->tid = -1;
}
@@ -694,7 +694,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (perf_cpu_map__empty(evlist->core.cpus))
- evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
+ evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!map)
return NULL;
@@ -808,7 +808,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
{
int cpu, thread;
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
pr_debug2("perf event ring buffer mmapped per cpu\n");
for (cpu = 0; cpu < nr_cpus; cpu++) {
@@ -836,7 +836,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
struct mmap_params *mp)
{
int thread;
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
pr_debug2("perf event ring buffer mmapped per thread\n");
for (thread = 0; thread < nr_threads; thread++) {
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0a33f7322ecc..45328a788e9f 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1651,7 +1651,7 @@ static bool ignore_missing_thread(struct evsel *evsel,
struct perf_thread_map *threads,
int thread, int err)
{
- pid_t ignore_pid = thread_map__pid(threads, thread);
+ pid_t ignore_pid = perf_thread_map__pid(threads, thread);
if (!evsel->ignore_missing_thread)
return false;
@@ -1814,7 +1814,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
int fd, group_fd;
if (!evsel->cgrp && !evsel->system_wide)
- pid = thread_map__pid(threads, thread);
+ pid = perf_thread_map__pid(threads, thread);
group_fd = get_group_fd(evsel, cpu, thread);
retry_open:
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 32c17a727450..6801afaa84c4 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1405,7 +1405,7 @@ static void python_process_stat(struct perf_stat_config *config,
for (thread = 0; thread < threads->nr; thread++) {
for (cpu = 0; cpu < cpus->nr; cpu++) {
process_stat(counter, cpus->map[cpu],
- thread_map__pid(threads, thread), tstamp,
+ perf_thread_map__pid(threads, thread), tstamp,
perf_counts(counter->counts, cpu, thread));
}
}
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 3df0e39ccd52..74e0f5ad1456 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -118,7 +118,7 @@ static void aggr_printout(struct perf_stat_config *config,
config->csv_output ? 0 : 16,
perf_thread_map__comm(evsel->core.threads, id),
config->csv_output ? 0 : -8,
- thread_map__pid(evsel->core.threads, id),
+ perf_thread_map__pid(evsel->core.threads, id),
config->csv_sep);
break;
case AGGR_GLOBAL:
@@ -744,7 +744,7 @@ static void print_aggr_thread(struct perf_stat_config *config,
struct evsel *counter, char *prefix)
{
FILE *output = config->output;
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_cpu_map__nr(counter->core.cpus);
int thread, sorted_threads, id;
struct perf_aggr_thread_value *buf;
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 2715112290cf..7342389bc8e1 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -158,7 +158,7 @@ static void perf_evsel__free_prev_raw_counts(struct evsel *evsel)
static int perf_evsel__alloc_stats(struct evsel *evsel, bool alloc_raw)
{
int ncpus = perf_evsel__nr_cpus(evsel);
- int nthreads = thread_map__nr(evsel->core.threads);
+ int nthreads = perf_thread_map__nr(evsel->core.threads);
if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
@@ -308,7 +308,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
static int process_counter_maps(struct perf_stat_config *config,
struct evsel *counter)
{
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index c58385ea05be..3e64525bf604 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -310,7 +310,7 @@ size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp)
size_t printed = fprintf(fp, "%d thread%s: ",
threads->nr, threads->nr > 1 ? "s" : "");
for (i = 0; i < threads->nr; ++i)
- printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i));
+ printed += fprintf(fp, "%s%d", i ? ", " : "", perf_thread_map__pid(threads, i));
return printed + fprintf(fp, "\n");
}
@@ -341,7 +341,7 @@ static int get_comm(char **comm, pid_t pid)
static void comm_init(struct perf_thread_map *map, int i)
{
- pid_t pid = thread_map__pid(map, i);
+ pid_t pid = perf_thread_map__pid(map, i);
char *comm = NULL;
/* dummy pid comm initialization */
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index ba45c760be72..ca165fdf6cb0 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -25,16 +25,6 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str);
size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp);
-static inline int thread_map__nr(struct perf_thread_map *threads)
-{
- return threads ? threads->nr : 1;
-}
-
-static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)
-{
- return map->map[thread].pid;
-}
-
void thread_map__read_comms(struct perf_thread_map *threads);
bool thread_map__has(struct perf_thread_map *threads, pid_t pid);
int thread_map__remove(struct perf_thread_map *threads, int idx);
--
2.21.0
Em Thu, Aug 22, 2019 at 01:11:37PM +0200, Jiri Olsa escreveu:
> We need perf_event.h include for 'struct perf_event_mmap_page'.
>
> Link: http://lkml.kernel.org/n/[email protected]
Thanks, applied.
- Arnaldo
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/include/linux/ring_buffer.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/include/linux/ring_buffer.h b/tools/include/linux/ring_buffer.h
> index 9a083ae60473..6c02617377c2 100644
> --- a/tools/include/linux/ring_buffer.h
> +++ b/tools/include/linux/ring_buffer.h
> @@ -2,6 +2,7 @@
> #define _TOOLS_LINUX_RING_BUFFER_H_
>
> #include <asm/barrier.h>
> +#include <linux/perf_event.h>
>
> /*
> * Contract with kernel for walking the perf ring buffer from
> --
> 2.21.0
--
- Arnaldo
Em Thu, Aug 22, 2019 at 01:11:41PM +0200, Jiri Olsa escreveu:
> So it's part of libperf library as basic functions
> over struct perf_thread_map object.
Thanks, applied and the other ones as well. I thought this one wasn't
applying but it was just a thinko on my part,
- Arnaldo
> Link: http://lkml.kernel.org/n/[email protected]
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/perf/builtin-ftrace.c | 2 +-
> tools/perf/builtin-script.c | 4 ++--
> tools/perf/builtin-stat.c | 4 ++--
> tools/perf/builtin-trace.c | 4 ++--
> tools/perf/lib/include/perf/threadmap.h | 2 ++
> tools/perf/lib/libperf.map | 2 ++
> tools/perf/lib/threadmap.c | 10 ++++++++++
> tools/perf/tests/thread-map.c | 6 +++---
> tools/perf/util/auxtrace.c | 4 ++--
> tools/perf/util/event.c | 8 ++++----
> tools/perf/util/evlist.c | 12 ++++++------
> tools/perf/util/evsel.c | 4 ++--
> .../perf/util/scripting-engines/trace-event-python.c | 2 +-
> tools/perf/util/stat-display.c | 4 ++--
> tools/perf/util/stat.c | 4 ++--
> tools/perf/util/thread_map.c | 4 ++--
> tools/perf/util/thread_map.h | 10 ----------
> 17 files changed, 45 insertions(+), 41 deletions(-)
>
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index 1367bb5046a7..565db782c1b9 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
> @@ -158,7 +158,7 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
> if (target__has_cpu(&ftrace->target))
> return 0;
>
> - for (i = 0; i < thread_map__nr(ftrace->evlist->core.threads); i++) {
> + for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) {
> scnprintf(buf, sizeof(buf), "%d",
> ftrace->evlist->core.threads->map[i]);
> if (append_tracing_file("set_ftrace_pid", buf) < 0)
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 1764efd16cd4..5d45be1d3885 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1905,7 +1905,7 @@ static struct scripting_ops *scripting_ops;
>
> static void __process_stat(struct evsel *counter, u64 tstamp)
> {
> - int nthreads = thread_map__nr(counter->core.threads);
> + int nthreads = perf_thread_map__nr(counter->core.threads);
> int ncpus = perf_evsel__nr_cpus(counter);
> int cpu, thread;
> static int header_printed;
> @@ -1927,7 +1927,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp)
>
> printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n",
> counter->core.cpus->map[cpu],
> - thread_map__pid(counter->core.threads, thread),
> + perf_thread_map__pid(counter->core.threads, thread),
> counts->val,
> counts->ena,
> counts->run,
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 90636a811b36..8a4f1a7d0cba 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -264,7 +264,7 @@ static int read_single_counter(struct evsel *counter, int cpu,
> */
> static int read_counter(struct evsel *counter, struct timespec *rs)
> {
> - int nthreads = thread_map__nr(evsel_list->core.threads);
> + int nthreads = perf_thread_map__nr(evsel_list->core.threads);
> int ncpus, cpu, thread;
>
> if (target__has_cpu(&target) && !target__has_per_thread(&target))
> @@ -1893,7 +1893,7 @@ int cmd_stat(int argc, const char **argv)
> thread_map__read_comms(evsel_list->core.threads);
> if (target.system_wide) {
> if (runtime_stat_new(&stat_config,
> - thread_map__nr(evsel_list->core.threads))) {
> + perf_thread_map__nr(evsel_list->core.threads))) {
> goto out;
> }
> }
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index bc44ed29e05a..de126258ca10 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -3188,7 +3188,7 @@ static int trace__set_filter_pids(struct trace *trace)
> err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
> trace->filter_pids.entries);
> }
> - } else if (thread_map__pid(trace->evlist->core.threads, 0) == -1) {
> + } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
> err = trace__set_filter_loop_pids(trace);
> }
>
> @@ -3417,7 +3417,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> evlist__enable(evlist);
> }
>
> - trace->multiple_threads = thread_map__pid(evlist->core.threads, 0) == -1 ||
> + trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
> evlist->core.threads->nr > 1 ||
> perf_evlist__first(evlist)->core.attr.inherit;
>
> diff --git a/tools/perf/lib/include/perf/threadmap.h b/tools/perf/lib/include/perf/threadmap.h
> index 456295273daa..a7c50de8d010 100644
> --- a/tools/perf/lib/include/perf/threadmap.h
> +++ b/tools/perf/lib/include/perf/threadmap.h
> @@ -11,6 +11,8 @@ LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
>
> LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
> LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
> +LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads);
> +LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
>
> LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
> LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
> diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
> index 3373dd51fcda..dc4d66363bc4 100644
> --- a/tools/perf/lib/libperf.map
> +++ b/tools/perf/lib/libperf.map
> @@ -12,6 +12,8 @@ LIBPERF_0.0.1 {
> perf_thread_map__new_dummy;
> perf_thread_map__set_pid;
> perf_thread_map__comm;
> + perf_thread_map__nr;
> + perf_thread_map__pid;
> perf_thread_map__get;
> perf_thread_map__put;
> perf_evsel__new;
> diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
> index 4865b73e2586..e92c368b0a6c 100644
> --- a/tools/perf/lib/threadmap.c
> +++ b/tools/perf/lib/threadmap.c
> @@ -79,3 +79,13 @@ void perf_thread_map__put(struct perf_thread_map *map)
> if (map && refcount_dec_and_test(&map->refcnt))
> perf_thread_map__delete(map);
> }
> +
> +int perf_thread_map__nr(struct perf_thread_map *threads)
> +{
> + return threads ? threads->nr : 1;
> +}
> +
> +pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread)
> +{
> + return map->map[thread].pid;
> +}
> diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
> index d61773cacf0b..d803eafedc60 100644
> --- a/tools/perf/tests/thread-map.c
> +++ b/tools/perf/tests/thread-map.c
> @@ -26,7 +26,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
>
> TEST_ASSERT_VAL("wrong nr", map->nr == 1);
> TEST_ASSERT_VAL("wrong pid",
> - thread_map__pid(map, 0) == getpid());
> + perf_thread_map__pid(map, 0) == getpid());
> TEST_ASSERT_VAL("wrong comm",
> perf_thread_map__comm(map, 0) &&
> !strcmp(perf_thread_map__comm(map, 0), NAME));
> @@ -41,7 +41,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
> thread_map__read_comms(map);
>
> TEST_ASSERT_VAL("wrong nr", map->nr == 1);
> - TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
> + TEST_ASSERT_VAL("wrong pid", perf_thread_map__pid(map, 0) == -1);
> TEST_ASSERT_VAL("wrong comm",
> perf_thread_map__comm(map, 0) &&
> !strcmp(perf_thread_map__comm(map, 0), "dummy"));
> @@ -68,7 +68,7 @@ static int process_event(struct perf_tool *tool __maybe_unused,
>
> TEST_ASSERT_VAL("wrong nr", threads->nr == 1);
> TEST_ASSERT_VAL("wrong pid",
> - thread_map__pid(threads, 0) == getpid());
> + perf_thread_map__pid(threads, 0) == getpid());
> TEST_ASSERT_VAL("wrong comm",
> perf_thread_map__comm(threads, 0) &&
> !strcmp(perf_thread_map__comm(threads, 0), NAME));
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index 60428576426e..094e6ceb3cf2 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -132,12 +132,12 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
> if (per_cpu) {
> mp->cpu = evlist->core.cpus->map[idx];
> if (evlist->core.threads)
> - mp->tid = thread_map__pid(evlist->core.threads, 0);
> + mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
> else
> mp->tid = -1;
> } else {
> mp->cpu = -1;
> - mp->tid = thread_map__pid(evlist->core.threads, idx);
> + mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
> }
> }
>
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index f433da85c45e..332edef8d394 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -647,7 +647,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
> for (thread = 0; thread < threads->nr; ++thread) {
> if (__event__synthesize_thread(comm_event, mmap_event,
> fork_event, namespaces_event,
> - thread_map__pid(threads, thread), 0,
> + perf_thread_map__pid(threads, thread), 0,
> process, tool, machine,
> mmap_data)) {
> err = -1;
> @@ -658,12 +658,12 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
> * comm.pid is set to thread group id by
> * perf_event__synthesize_comm
> */
> - if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) {
> + if ((int) comm_event->comm.pid != perf_thread_map__pid(threads, thread)) {
> bool need_leader = true;
>
> /* is thread group leader in thread_map? */
> for (j = 0; j < threads->nr; ++j) {
> - if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) {
> + if ((int) comm_event->comm.pid == perf_thread_map__pid(threads, j)) {
> need_leader = false;
> break;
> }
> @@ -997,7 +997,7 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
> if (!comm)
> comm = (char *) "";
>
> - entry->pid = thread_map__pid(threads, i);
> + entry->pid = perf_thread_map__pid(threads, i);
> strncpy((char *) &entry->comm, comm, sizeof(entry->comm));
> }
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 8582560b59af..23b56717d260 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -314,7 +314,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
> if (evsel->system_wide)
> return 1;
> else
> - return thread_map__nr(evlist->core.threads);
> + return perf_thread_map__nr(evlist->core.threads);
> }
>
> void evlist__disable(struct evlist *evlist)
> @@ -397,7 +397,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
> int perf_evlist__alloc_pollfd(struct evlist *evlist)
> {
> int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
> - int nr_threads = thread_map__nr(evlist->core.threads);
> + int nr_threads = perf_thread_map__nr(evlist->core.threads);
> int nfds = 0;
> struct evsel *evsel;
>
> @@ -529,7 +529,7 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist,
> else
> sid->cpu = -1;
> if (!evsel->system_wide && evlist->core.threads && thread >= 0)
> - sid->tid = thread_map__pid(evlist->core.threads, thread);
> + sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
> else
> sid->tid = -1;
> }
> @@ -694,7 +694,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
>
> evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
> if (perf_cpu_map__empty(evlist->core.cpus))
> - evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
> + evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
> map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
> if (!map)
> return NULL;
> @@ -808,7 +808,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
> {
> int cpu, thread;
> int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
> - int nr_threads = thread_map__nr(evlist->core.threads);
> + int nr_threads = perf_thread_map__nr(evlist->core.threads);
>
> pr_debug2("perf event ring buffer mmapped per cpu\n");
> for (cpu = 0; cpu < nr_cpus; cpu++) {
> @@ -836,7 +836,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
> struct mmap_params *mp)
> {
> int thread;
> - int nr_threads = thread_map__nr(evlist->core.threads);
> + int nr_threads = perf_thread_map__nr(evlist->core.threads);
>
> pr_debug2("perf event ring buffer mmapped per thread\n");
> for (thread = 0; thread < nr_threads; thread++) {
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 0a33f7322ecc..45328a788e9f 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -1651,7 +1651,7 @@ static bool ignore_missing_thread(struct evsel *evsel,
> struct perf_thread_map *threads,
> int thread, int err)
> {
> - pid_t ignore_pid = thread_map__pid(threads, thread);
> + pid_t ignore_pid = perf_thread_map__pid(threads, thread);
>
> if (!evsel->ignore_missing_thread)
> return false;
> @@ -1814,7 +1814,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
> int fd, group_fd;
>
> if (!evsel->cgrp && !evsel->system_wide)
> - pid = thread_map__pid(threads, thread);
> + pid = perf_thread_map__pid(threads, thread);
>
> group_fd = get_group_fd(evsel, cpu, thread);
> retry_open:
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 32c17a727450..6801afaa84c4 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -1405,7 +1405,7 @@ static void python_process_stat(struct perf_stat_config *config,
> for (thread = 0; thread < threads->nr; thread++) {
> for (cpu = 0; cpu < cpus->nr; cpu++) {
> process_stat(counter, cpus->map[cpu],
> - thread_map__pid(threads, thread), tstamp,
> + perf_thread_map__pid(threads, thread), tstamp,
> perf_counts(counter->counts, cpu, thread));
> }
> }
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 3df0e39ccd52..74e0f5ad1456 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -118,7 +118,7 @@ static void aggr_printout(struct perf_stat_config *config,
> config->csv_output ? 0 : 16,
> perf_thread_map__comm(evsel->core.threads, id),
> config->csv_output ? 0 : -8,
> - thread_map__pid(evsel->core.threads, id),
> + perf_thread_map__pid(evsel->core.threads, id),
> config->csv_sep);
> break;
> case AGGR_GLOBAL:
> @@ -744,7 +744,7 @@ static void print_aggr_thread(struct perf_stat_config *config,
> struct evsel *counter, char *prefix)
> {
> FILE *output = config->output;
> - int nthreads = thread_map__nr(counter->core.threads);
> + int nthreads = perf_thread_map__nr(counter->core.threads);
> int ncpus = perf_cpu_map__nr(counter->core.cpus);
> int thread, sorted_threads, id;
> struct perf_aggr_thread_value *buf;
> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> index 2715112290cf..7342389bc8e1 100644
> --- a/tools/perf/util/stat.c
> +++ b/tools/perf/util/stat.c
> @@ -158,7 +158,7 @@ static void perf_evsel__free_prev_raw_counts(struct evsel *evsel)
> static int perf_evsel__alloc_stats(struct evsel *evsel, bool alloc_raw)
> {
> int ncpus = perf_evsel__nr_cpus(evsel);
> - int nthreads = thread_map__nr(evsel->core.threads);
> + int nthreads = perf_thread_map__nr(evsel->core.threads);
>
> if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
> perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
> @@ -308,7 +308,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
> static int process_counter_maps(struct perf_stat_config *config,
> struct evsel *counter)
> {
> - int nthreads = thread_map__nr(counter->core.threads);
> + int nthreads = perf_thread_map__nr(counter->core.threads);
> int ncpus = perf_evsel__nr_cpus(counter);
> int cpu, thread;
>
> diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
> index c58385ea05be..3e64525bf604 100644
> --- a/tools/perf/util/thread_map.c
> +++ b/tools/perf/util/thread_map.c
> @@ -310,7 +310,7 @@ size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp)
> size_t printed = fprintf(fp, "%d thread%s: ",
> threads->nr, threads->nr > 1 ? "s" : "");
> for (i = 0; i < threads->nr; ++i)
> - printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i));
> + printed += fprintf(fp, "%s%d", i ? ", " : "", perf_thread_map__pid(threads, i));
>
> return printed + fprintf(fp, "\n");
> }
> @@ -341,7 +341,7 @@ static int get_comm(char **comm, pid_t pid)
>
> static void comm_init(struct perf_thread_map *map, int i)
> {
> - pid_t pid = thread_map__pid(map, i);
> + pid_t pid = perf_thread_map__pid(map, i);
> char *comm = NULL;
>
> /* dummy pid comm initialization */
> diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
> index ba45c760be72..ca165fdf6cb0 100644
> --- a/tools/perf/util/thread_map.h
> +++ b/tools/perf/util/thread_map.h
> @@ -25,16 +25,6 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str);
>
> size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp);
>
> -static inline int thread_map__nr(struct perf_thread_map *threads)
> -{
> - return threads ? threads->nr : 1;
> -}
> -
> -static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)
> -{
> - return map->map[thread].pid;
> -}
> -
> void thread_map__read_comms(struct perf_thread_map *threads);
> bool thread_map__has(struct perf_thread_map *threads, pid_t pid);
> int thread_map__remove(struct perf_thread_map *threads, int idx);
> --
> 2.21.0
--
- Arnaldo
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 315c0a1f0ccdd44c65f80ccbc62202fed8a23050
Gitweb: https://git.kernel.org/tip/315c0a1f0ccdd44c65f80ccbc62202fed8a23050
Author: Jiri Olsa <[email protected]>
AuthorDate: Thu, 22 Aug 2019 13:11:39 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 22 Aug 2019 11:17:03 -03:00
libperf: Move perf's cpu_map__empty() to perf_cpu_map__empty()
So it's part of the libperf library as one of basic functions operating
on the perf_cpu_map class.
Signed-off-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 8 ++++----
tools/perf/arch/x86/util/intel-bts.c | 4 ++--
tools/perf/arch/x86/util/intel-pt.c | 10 +++++-----
tools/perf/builtin-c2c.c | 2 +-
tools/perf/builtin-stat.c | 4 ++--
tools/perf/lib/cpumap.c | 5 +++++
tools/perf/lib/include/perf/cpumap.h | 2 ++
tools/perf/lib/libperf.map | 1 +
tools/perf/util/cpumap.c | 6 +++---
tools/perf/util/cpumap.h | 7 +------
tools/perf/util/event.c | 2 +-
tools/perf/util/evlist.c | 6 +++---
tools/perf/util/record.c | 2 +-
tools/perf/util/stat.c | 2 +-
14 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index c786ab0..c73da32 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -396,7 +396,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
* AUX event. We also need the contextID in order to be notified
* when a context switch happened.
*/
- if (!cpu_map__empty(cpus)) {
+ if (!perf_cpu_map__empty(cpus)) {
perf_evsel__set_sample_bit(cs_etm_evsel, CPU);
err = cs_etm_set_option(itr, cs_etm_evsel,
@@ -420,7 +420,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
tracking_evsel->core.attr.sample_period = 1;
/* In per-cpu case, always need the time of mmap events etc */
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(tracking_evsel, TIME);
}
@@ -493,7 +493,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
/* cpu map is not empty, we have specific CPUs to work with */
- if (!cpu_map__empty(event_cpus)) {
+ if (!perf_cpu_map__empty(event_cpus)) {
for (i = 0; i < cpu__max_cpu(); i++) {
if (!cpu_map__has(event_cpus, i) ||
!cpu_map__has(online_cpus, i))
@@ -649,7 +649,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
return -EINVAL;
/* If the cpu_map is empty all online CPUs are involved */
- if (cpu_map__empty(event_cpus)) {
+ if (perf_cpu_map__empty(event_cpus)) {
cpu_map = online_cpus;
} else {
/* Make sure all specified CPUs are online */
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 7b23318..2d5d8a1 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -133,7 +133,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
if (!opts->full_auxtrace)
return 0;
- if (opts->full_auxtrace && !cpu_map__empty(cpus)) {
+ if (opts->full_auxtrace && !perf_cpu_map__empty(cpus)) {
pr_err(INTEL_BTS_PMU_NAME " does not support per-cpu recording\n");
return -EINVAL;
}
@@ -214,7 +214,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
* In the case of per-cpu mmaps, we need the CPU on the
* AUX event.
*/
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(intel_bts_evsel, CPU);
}
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a8e633a..c72a77a 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -365,7 +365,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
ui__warning("Intel Processor Trace: TSC not available\n");
}
- per_cpu_mmaps = !cpu_map__empty(session->evlist->core.cpus);
+ per_cpu_mmaps = !perf_cpu_map__empty(session->evlist->core.cpus);
auxtrace_info->type = PERF_AUXTRACE_INTEL_PT;
auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type;
@@ -702,7 +702,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* Per-cpu recording needs sched_switch events to distinguish different
* threads.
*/
- if (have_timing_info && !cpu_map__empty(cpus)) {
+ if (have_timing_info && !perf_cpu_map__empty(cpus)) {
if (perf_can_record_switch_events()) {
bool cpu_wide = !target__none(&opts->target) &&
!target__has_task(&opts->target);
@@ -760,7 +760,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* In the case of per-cpu mmaps, we need the CPU on the
* AUX event.
*/
- if (!cpu_map__empty(cpus))
+ if (!perf_cpu_map__empty(cpus))
perf_evsel__set_sample_bit(intel_pt_evsel, CPU);
}
@@ -784,7 +784,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
tracking_evsel->immediate = true;
/* In per-cpu case, always need the time of mmap events etc */
- if (!cpu_map__empty(cpus)) {
+ if (!perf_cpu_map__empty(cpus)) {
perf_evsel__set_sample_bit(tracking_evsel, TIME);
/* And the CPU for switch events */
perf_evsel__set_sample_bit(tracking_evsel, CPU);
@@ -796,7 +796,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
* Warn the user when we do not have enough information to decode i.e.
* per-cpu with no sched_switch (except workload-only).
*/
- if (!ptr->have_sched_switch && !cpu_map__empty(cpus) &&
+ if (!ptr->have_sched_switch && !perf_cpu_map__empty(cpus) &&
!target__none(&opts->target))
ui__warning("Intel Processor Trace decoding will not be possible except for kernel tracing!\n");
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index f0aae6e..01629f5 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2059,7 +2059,7 @@ static int setup_nodes(struct perf_session *session)
nodes[node] = set;
/* empty node, skip */
- if (cpu_map__empty(map))
+ if (perf_cpu_map__empty(map))
continue;
for (cpu = 0; cpu < map->nr; cpu++) {
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b19df67..90636a8 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -928,7 +928,7 @@ static int perf_stat_init_aggr_mode(void)
* the aggregation translate cpumap.
*/
nr = cpu_map__get_max(evsel_list->core.cpus);
- stat_config.cpus_aggr_map = cpu_map__empty_new(nr + 1);
+ stat_config.cpus_aggr_map = perf_cpu_map__empty_new(nr + 1);
return stat_config.cpus_aggr_map ? 0 : -ENOMEM;
}
@@ -1493,7 +1493,7 @@ int process_stat_config_event(struct perf_session *session,
perf_event__read_stat_config(&stat_config, &event->stat_config);
- if (cpu_map__empty(st->cpus)) {
+ if (perf_cpu_map__empty(st->cpus)) {
if (st->aggr_mode != AGGR_UNSET)
pr_warning("warning: processing task data, aggregation mode not set\n");
return 0;
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 1ddb69e..63f7df7 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -237,3 +237,8 @@ int perf_cpu_map__nr(const struct perf_cpu_map *cpus)
{
return cpus ? cpus->nr : 1;
}
+
+bool perf_cpu_map__empty(const struct perf_cpu_map *map)
+{
+ return map ? map->map[0] == -1 : true;
+}
diff --git a/tools/perf/lib/include/perf/cpumap.h b/tools/perf/lib/include/perf/cpumap.h
index 1b6e7db..8aa995c 100644
--- a/tools/perf/lib/include/perf/cpumap.h
+++ b/tools/perf/lib/include/perf/cpumap.h
@@ -4,6 +4,7 @@
#include <perf/core.h>
#include <stdio.h>
+#include <stdbool.h>
struct perf_cpu_map;
@@ -14,6 +15,7 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
+LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map);
#define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \
for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index e24d3ce..3373dd5 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -8,6 +8,7 @@ LIBPERF_0.0.1 {
perf_cpu_map__read;
perf_cpu_map__nr;
perf_cpu_map__cpu;
+ perf_cpu_map__empty;
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
perf_thread_map__comm;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index beb3525..4402e67 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -21,7 +21,7 @@ static struct perf_cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus)
{
struct perf_cpu_map *map;
- map = cpu_map__empty_new(cpus->nr);
+ map = perf_cpu_map__empty_new(cpus->nr);
if (map) {
unsigned i;
@@ -48,7 +48,7 @@ static struct perf_cpu_map *cpu_map__from_mask(struct cpu_map_mask *mask)
nr = bitmap_weight(mask->mask, nbits);
- map = cpu_map__empty_new(nr);
+ map = perf_cpu_map__empty_new(nr);
if (map) {
int cpu, i = 0;
@@ -77,7 +77,7 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
#undef BUFSIZE
}
-struct perf_cpu_map *cpu_map__empty_new(int nr)
+struct perf_cpu_map *perf_cpu_map__empty_new(int nr)
{
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 77f85e9..3e06809 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -11,7 +11,7 @@
#include "perf.h"
#include "util/debug.h"
-struct perf_cpu_map *cpu_map__empty_new(int nr);
+struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data);
size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
@@ -49,11 +49,6 @@ static inline int cpu_map__id_to_cpu(int id)
return id & 0xffff;
}
-static inline bool cpu_map__empty(const struct perf_cpu_map *map)
-{
- return map ? map->map[0] == -1 : true;
-}
-
int cpu__setup_cpunode_map(void);
int cpu__max_node(void);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f440fdc..f433da8 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1055,7 +1055,7 @@ static size_t mask_size(struct perf_cpu_map *map, int *max)
void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max)
{
size_t size_cpus, size_mask;
- bool is_dummy = cpu_map__empty(map);
+ bool is_dummy = perf_cpu_map__empty(map);
/*
* Both array and mask data have variable size based
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 15d1046..ba49b5e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -386,7 +386,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,
int perf_evlist__enable_event_idx(struct evlist *evlist,
struct evsel *evsel, int idx)
{
- bool per_cpu_mmaps = !cpu_map__empty(evlist->core.cpus);
+ bool per_cpu_mmaps = !perf_cpu_map__empty(evlist->core.cpus);
if (per_cpu_mmaps)
return perf_evlist__enable_event_cpu(evlist, evsel, idx);
@@ -693,7 +693,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
struct perf_mmap *map;
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
- if (cpu_map__empty(evlist->core.cpus))
+ if (perf_cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!map)
@@ -1018,7 +1018,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
return -ENOMEM;
}
- if (cpu_map__empty(cpus))
+ if (perf_cpu_map__empty(cpus))
return perf_evlist__mmap_per_thread(evlist, &mp);
return perf_evlist__mmap_per_cpu(evlist, &mp);
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index e59382d..51bbd07 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -275,7 +275,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str)
evsel = perf_evlist__last(temp_evlist);
- if (!evlist || cpu_map__empty(evlist->core.cpus)) {
+ if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) {
struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
cpu = cpus ? cpus->map[0] : 0;
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index e4e4e3b..2715112 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -223,7 +223,7 @@ static int check_per_pkg(struct evsel *counter,
if (!counter->per_pkg)
return 0;
- if (cpu_map__empty(cpus))
+ if (perf_cpu_map__empty(cpus))
return 0;
if (!mask) {
The following commit has been merged into the perf/core branch of tip:
Commit-ID: b4df75de3b3930703415aa053a269ae07c78d9b2
Gitweb: https://git.kernel.org/tip/b4df75de3b3930703415aa053a269ae07c78d9b2
Author: Jiri Olsa <[email protected]>
AuthorDate: Thu, 22 Aug 2019 13:11:40 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 22 Aug 2019 11:18:45 -03:00
libperf: Move perf's cpu_map__idx() to perf_cpu_map__idx()
As an internal function that will be used by both perf and libperf, but
is not exported at this point.
Signed-off-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/lib/cpumap.c | 12 ++++++++++++
tools/perf/lib/include/internal/cpumap.h | 2 ++
tools/perf/util/cpumap.c | 14 +-------------
tools/perf/util/cpumap.h | 1 -
tools/perf/util/evlist.c | 2 +-
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 63f7df7..2834753 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -242,3 +242,15 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map)
{
return map ? map->map[0] == -1 : true;
}
+
+int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
+{
+ int i;
+
+ for (i = 0; i < cpus->nr; ++i) {
+ if (cpus->map[i] == cpu)
+ return i;
+ }
+
+ return -1;
+}
diff --git a/tools/perf/lib/include/internal/cpumap.h b/tools/perf/lib/include/internal/cpumap.h
index 3306319..840d403 100644
--- a/tools/perf/lib/include/internal/cpumap.h
+++ b/tools/perf/lib/include/internal/cpumap.h
@@ -14,4 +14,6 @@ struct perf_cpu_map {
#define MAX_NR_CPUS 2048
#endif
+int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
+
#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 4402e67..8e6c2cb 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -458,19 +458,7 @@ int cpu__setup_cpunode_map(void)
bool cpu_map__has(struct perf_cpu_map *cpus, int cpu)
{
- return cpu_map__idx(cpus, cpu) != -1;
-}
-
-int cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
-{
- int i;
-
- for (i = 0; i < cpus->nr; ++i) {
- if (cpus->map[i] == cpu)
- return i;
- }
-
- return -1;
+ return perf_cpu_map__idx(cpus, cpu) != -1;
}
int cpu_map__cpu(struct perf_cpu_map *cpus, int idx)
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 3e06809..8dbedda 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -62,5 +62,4 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
-int cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
#endif /* __PERF_CPUMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ba49b5e..8582560 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -758,7 +758,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
if (evsel->system_wide && thread)
continue;
- cpu = cpu_map__idx(evsel->core.cpus, evlist_cpu);
+ cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
if (cpu == -1)
continue;
The following commit has been merged into the perf/core branch of tip:
Commit-ID: a2f354e3abb853f9a40048829e1f839e8f7fada5
Gitweb: https://git.kernel.org/tip/a2f354e3abb853f9a40048829e1f839e8f7fada5
Author: Jiri Olsa <[email protected]>
AuthorDate: Thu, 22 Aug 2019 13:11:41 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 22 Aug 2019 17:16:57 -03:00
libperf: Add perf_thread_map__nr/perf_thread_map__pid functions
So it's part of libperf library as basic functions operating on
perf_thread_map objects.
Signed-off-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-ftrace.c | 2 +-
tools/perf/builtin-script.c | 4 +--
tools/perf/builtin-stat.c | 4 +--
tools/perf/builtin-trace.c | 4 +--
tools/perf/lib/include/perf/threadmap.h | 2 ++-
tools/perf/lib/libperf.map | 2 ++-
tools/perf/lib/threadmap.c | 10 ++++++++-
tools/perf/tests/thread-map.c | 6 ++---
tools/perf/util/auxtrace.c | 4 +--
tools/perf/util/event.c | 8 +++---
tools/perf/util/evlist.c | 12 ++++-----
tools/perf/util/evsel.c | 4 +--
tools/perf/util/scripting-engines/trace-event-python.c | 2 +-
tools/perf/util/stat-display.c | 4 +--
tools/perf/util/stat.c | 4 +--
tools/perf/util/thread_map.c | 4 +--
tools/perf/util/thread_map.h | 10 +--------
17 files changed, 45 insertions(+), 41 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 1367bb5..565db78 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -158,7 +158,7 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
if (target__has_cpu(&ftrace->target))
return 0;
- for (i = 0; i < thread_map__nr(ftrace->evlist->core.threads); i++) {
+ for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) {
scnprintf(buf, sizeof(buf), "%d",
ftrace->evlist->core.threads->map[i]);
if (append_tracing_file("set_ftrace_pid", buf) < 0)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index e957b87..9b93dde 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1906,7 +1906,7 @@ static struct scripting_ops *scripting_ops;
static void __process_stat(struct evsel *counter, u64 tstamp)
{
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
static int header_printed;
@@ -1928,7 +1928,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp)
printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n",
counter->core.cpus->map[cpu],
- thread_map__pid(counter->core.threads, thread),
+ perf_thread_map__pid(counter->core.threads, thread),
counts->val,
counts->ena,
counts->run,
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 90636a8..8a4f1a7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -264,7 +264,7 @@ static int read_single_counter(struct evsel *counter, int cpu,
*/
static int read_counter(struct evsel *counter, struct timespec *rs)
{
- int nthreads = thread_map__nr(evsel_list->core.threads);
+ int nthreads = perf_thread_map__nr(evsel_list->core.threads);
int ncpus, cpu, thread;
if (target__has_cpu(&target) && !target__has_per_thread(&target))
@@ -1893,7 +1893,7 @@ int cmd_stat(int argc, const char **argv)
thread_map__read_comms(evsel_list->core.threads);
if (target.system_wide) {
if (runtime_stat_new(&stat_config,
- thread_map__nr(evsel_list->core.threads))) {
+ perf_thread_map__nr(evsel_list->core.threads))) {
goto out;
}
}
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bc44ed2..de12625 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3188,7 +3188,7 @@ static int trace__set_filter_pids(struct trace *trace)
err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
trace->filter_pids.entries);
}
- } else if (thread_map__pid(trace->evlist->core.threads, 0) == -1) {
+ } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
err = trace__set_filter_loop_pids(trace);
}
@@ -3417,7 +3417,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
evlist__enable(evlist);
}
- trace->multiple_threads = thread_map__pid(evlist->core.threads, 0) == -1 ||
+ trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
evlist->core.threads->nr > 1 ||
perf_evlist__first(evlist)->core.attr.inherit;
diff --git a/tools/perf/lib/include/perf/threadmap.h b/tools/perf/lib/include/perf/threadmap.h
index 4562952..a7c50de 100644
--- a/tools/perf/lib/include/perf/threadmap.h
+++ b/tools/perf/lib/include/perf/threadmap.h
@@ -11,6 +11,8 @@ LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
+LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads);
+LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 3373dd5..dc4d663 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -12,6 +12,8 @@ LIBPERF_0.0.1 {
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
perf_thread_map__comm;
+ perf_thread_map__nr;
+ perf_thread_map__pid;
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__new;
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
index 4865b73..e92c368 100644
--- a/tools/perf/lib/threadmap.c
+++ b/tools/perf/lib/threadmap.c
@@ -79,3 +79,13 @@ void perf_thread_map__put(struct perf_thread_map *map)
if (map && refcount_dec_and_test(&map->refcnt))
perf_thread_map__delete(map);
}
+
+int perf_thread_map__nr(struct perf_thread_map *threads)
+{
+ return threads ? threads->nr : 1;
+}
+
+pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread)
+{
+ return map->map[thread].pid;
+}
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index d61773c..d803eaf 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -26,7 +26,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
TEST_ASSERT_VAL("wrong nr", map->nr == 1);
TEST_ASSERT_VAL("wrong pid",
- thread_map__pid(map, 0) == getpid());
+ perf_thread_map__pid(map, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(map, 0) &&
!strcmp(perf_thread_map__comm(map, 0), NAME));
@@ -41,7 +41,7 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
thread_map__read_comms(map);
TEST_ASSERT_VAL("wrong nr", map->nr == 1);
- TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
+ TEST_ASSERT_VAL("wrong pid", perf_thread_map__pid(map, 0) == -1);
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(map, 0) &&
!strcmp(perf_thread_map__comm(map, 0), "dummy"));
@@ -68,7 +68,7 @@ static int process_event(struct perf_tool *tool __maybe_unused,
TEST_ASSERT_VAL("wrong nr", threads->nr == 1);
TEST_ASSERT_VAL("wrong pid",
- thread_map__pid(threads, 0) == getpid());
+ perf_thread_map__pid(threads, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
perf_thread_map__comm(threads, 0) &&
!strcmp(perf_thread_map__comm(threads, 0), NAME));
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 6042857..094e6ce 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -132,12 +132,12 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
if (per_cpu) {
mp->cpu = evlist->core.cpus->map[idx];
if (evlist->core.threads)
- mp->tid = thread_map__pid(evlist->core.threads, 0);
+ mp->tid = perf_thread_map__pid(evlist->core.threads, 0);
else
mp->tid = -1;
} else {
mp->cpu = -1;
- mp->tid = thread_map__pid(evlist->core.threads, idx);
+ mp->tid = perf_thread_map__pid(evlist->core.threads, idx);
}
}
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f433da8..332edef 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -647,7 +647,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
for (thread = 0; thread < threads->nr; ++thread) {
if (__event__synthesize_thread(comm_event, mmap_event,
fork_event, namespaces_event,
- thread_map__pid(threads, thread), 0,
+ perf_thread_map__pid(threads, thread), 0,
process, tool, machine,
mmap_data)) {
err = -1;
@@ -658,12 +658,12 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
* comm.pid is set to thread group id by
* perf_event__synthesize_comm
*/
- if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) {
+ if ((int) comm_event->comm.pid != perf_thread_map__pid(threads, thread)) {
bool need_leader = true;
/* is thread group leader in thread_map? */
for (j = 0; j < threads->nr; ++j) {
- if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) {
+ if ((int) comm_event->comm.pid == perf_thread_map__pid(threads, j)) {
need_leader = false;
break;
}
@@ -997,7 +997,7 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
if (!comm)
comm = (char *) "";
- entry->pid = thread_map__pid(threads, i);
+ entry->pid = perf_thread_map__pid(threads, i);
strncpy((char *) &entry->comm, comm, sizeof(entry->comm));
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 68b7c94..ff41568 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -316,7 +316,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
if (evsel->system_wide)
return 1;
else
- return thread_map__nr(evlist->core.threads);
+ return perf_thread_map__nr(evlist->core.threads);
}
void evlist__disable(struct evlist *evlist)
@@ -399,7 +399,7 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
int perf_evlist__alloc_pollfd(struct evlist *evlist)
{
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
int nfds = 0;
struct evsel *evsel;
@@ -531,7 +531,7 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist,
else
sid->cpu = -1;
if (!evsel->system_wide && evlist->core.threads && thread >= 0)
- sid->tid = thread_map__pid(evlist->core.threads, thread);
+ sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
else
sid->tid = -1;
}
@@ -696,7 +696,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (perf_cpu_map__empty(evlist->core.cpus))
- evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
+ evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!map)
return NULL;
@@ -810,7 +810,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
{
int cpu, thread;
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
pr_debug2("perf event ring buffer mmapped per cpu\n");
for (cpu = 0; cpu < nr_cpus; cpu++) {
@@ -838,7 +838,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
struct mmap_params *mp)
{
int thread;
- int nr_threads = thread_map__nr(evlist->core.threads);
+ int nr_threads = perf_thread_map__nr(evlist->core.threads);
pr_debug2("perf event ring buffer mmapped per thread\n");
for (thread = 0; thread < nr_threads; thread++) {
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 7b43506..e983e72 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1653,7 +1653,7 @@ static bool ignore_missing_thread(struct evsel *evsel,
struct perf_thread_map *threads,
int thread, int err)
{
- pid_t ignore_pid = thread_map__pid(threads, thread);
+ pid_t ignore_pid = perf_thread_map__pid(threads, thread);
if (!evsel->ignore_missing_thread)
return false;
@@ -1816,7 +1816,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
int fd, group_fd;
if (!evsel->cgrp && !evsel->system_wide)
- pid = thread_map__pid(threads, thread);
+ pid = perf_thread_map__pid(threads, thread);
group_fd = get_group_fd(evsel, cpu, thread);
retry_open:
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 51771fc..78c8bc9 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1406,7 +1406,7 @@ static void python_process_stat(struct perf_stat_config *config,
for (thread = 0; thread < threads->nr; thread++) {
for (cpu = 0; cpu < cpus->nr; cpu++) {
process_stat(counter, cpus->map[cpu],
- thread_map__pid(threads, thread), tstamp,
+ perf_thread_map__pid(threads, thread), tstamp,
perf_counts(counter->counts, cpu, thread));
}
}
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 605a1fd..51d6781 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -119,7 +119,7 @@ static void aggr_printout(struct perf_stat_config *config,
config->csv_output ? 0 : 16,
perf_thread_map__comm(evsel->core.threads, id),
config->csv_output ? 0 : -8,
- thread_map__pid(evsel->core.threads, id),
+ perf_thread_map__pid(evsel->core.threads, id),
config->csv_sep);
break;
case AGGR_GLOBAL:
@@ -745,7 +745,7 @@ static void print_aggr_thread(struct perf_stat_config *config,
struct evsel *counter, char *prefix)
{
FILE *output = config->output;
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_cpu_map__nr(counter->core.cpus);
int thread, sorted_threads, id;
struct perf_aggr_thread_value *buf;
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 1e6a25a..0cbfd1e 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -159,7 +159,7 @@ static void perf_evsel__free_prev_raw_counts(struct evsel *evsel)
static int perf_evsel__alloc_stats(struct evsel *evsel, bool alloc_raw)
{
int ncpus = perf_evsel__nr_cpus(evsel);
- int nthreads = thread_map__nr(evsel->core.threads);
+ int nthreads = perf_thread_map__nr(evsel->core.threads);
if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
@@ -309,7 +309,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
static int process_counter_maps(struct perf_stat_config *config,
struct evsel *counter)
{
- int nthreads = thread_map__nr(counter->core.threads);
+ int nthreads = perf_thread_map__nr(counter->core.threads);
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index c58385e..3e64525 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -310,7 +310,7 @@ size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp)
size_t printed = fprintf(fp, "%d thread%s: ",
threads->nr, threads->nr > 1 ? "s" : "");
for (i = 0; i < threads->nr; ++i)
- printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i));
+ printed += fprintf(fp, "%s%d", i ? ", " : "", perf_thread_map__pid(threads, i));
return printed + fprintf(fp, "\n");
}
@@ -341,7 +341,7 @@ static int get_comm(char **comm, pid_t pid)
static void comm_init(struct perf_thread_map *map, int i)
{
- pid_t pid = thread_map__pid(map, i);
+ pid_t pid = perf_thread_map__pid(map, i);
char *comm = NULL;
/* dummy pid comm initialization */
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index ba45c76..ca165fd 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -25,16 +25,6 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str);
size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp);
-static inline int thread_map__nr(struct perf_thread_map *threads)
-{
- return threads ? threads->nr : 1;
-}
-
-static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)
-{
- return map->map[thread].pid;
-}
-
void thread_map__read_comms(struct perf_thread_map *threads);
bool thread_map__has(struct perf_thread_map *threads, pid_t pid);
int thread_map__remove(struct perf_thread_map *threads, int idx);