perf/core improvements and fixes:

perf c2c:
 
   Ravi Bangoria:
 
   - Fix report with offline cpus.
 
 libperf:
 
   Gerald BAEZA:
 
   - Fix alignment trap with xyarray contents in 'perf stat', noticed on ARMv7.
 
   Jiri Olsa:
 
   - Move some more cpu_map and thread_map methods from tools/perf/util/ to libperf.
 
 headers:
 
   Arnaldo Carvalho de Melo:
 
   - Do some house cleaning on the headers, removing needless includes in some places,
     providing forward declarations when those are the only thing needed, and fixing
     up the fallout from that for cases where we were using stuff and not adding the
     necessary headers. Should speed up the build and avoid needless rebuilds when
     something unrelated gets touched.
 
 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYIAB0WIQR2GiIUctdOfX2qHhGyPKLppCJ+JwUCXV8BzAAKCRCyPKLppCJ+
 J7ZzAQC2DOqsnTU3CRtsc89oi7GNN54OkobrJoRn4EJzJD8dUgEAk1ZY1oj/r+jL
 Sn3XpV4AlRoFj5jWwlr9sZ44d9HhaAY=
 =twFh
 -----END PGP SIGNATURE-----

Merge tag 'perf-core-for-mingo-5.4-20190822' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

perf c2c:

  Ravi Bangoria:

  - Fix report with offline CPUs.

libperf:

  Gerald BAEZA:

  - Fix alignment trap with xyarray contents in 'perf stat', noticed on ARMv7.

  Jiri Olsa:

  - Move some more cpu_map and thread_map methods from tools/perf/util/ to libperf.

headers:

  Arnaldo Carvalho de Melo:

  - Do some house cleaning on the headers, removing needless includes in some places,
    providing forward declarations when those are the only thing needed, and fixing
    up the fallout from that for cases where we were using stuff and not adding the
    necessary headers. Should speed up the build and avoid needless rebuilds when
    something unrelated gets touched.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Ingo Molnar 2019-08-23 12:29:17 +02:00
commit 49c46457ca
47 changed files with 155 additions and 113 deletions

View File

@ -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

View File

@ -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,11 +649,11 @@ 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 */
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;

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <api/fs/fs.h>
#include "debug.h"
#include "header.h"
#define MIDR "/regs/identification/midr_el1"

View File

@ -7,6 +7,7 @@
*/
#include <errno.h>
#include <string.h>
#include "../../util/kvm-stat.h"
#include "../../util/evsel.h"
#include <asm/sie.h>

View File

@ -6,6 +6,7 @@
#include <string.h>
#include <regex.h>
#include "../../util/debug.h"
#include "../../util/header.h"
static inline void

View File

@ -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);
}

View File

@ -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");

View File

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <errno.h>
#include <string.h>
#include "../../../util/kvm-stat.h"
#include "../../../util/evsel.h"
#include <asm/svm.h>

View File

@ -2027,7 +2027,7 @@ static int setup_nodes(struct perf_session *session)
c2c.node_info = 2;
c2c.nodes_cnt = session->header.env.nr_numa_nodes;
c2c.cpus_cnt = session->header.env.nr_cpus_online;
c2c.cpus_cnt = session->header.env.nr_cpus_avail;
n = session->header.env.numa_nodes;
if (!n)
@ -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++) {

View File

@ -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)

View File

@ -3,6 +3,7 @@
#include "perf.h"
#include "util/cache.h"
#include "util/counts.h"
#include "util/debug.h"
#include <subcmd/exec-cmd.h>
#include "util/header.h"
@ -1905,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;
@ -1927,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,

View File

@ -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))
@ -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;
@ -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;
}
}

View File

@ -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;

View File

@ -237,3 +237,20 @@ 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;
}
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;
}

View File

@ -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 */

View File

@ -2,6 +2,7 @@
#ifndef __LIBPERF_INTERNAL_XYARRAY_H
#define __LIBPERF_INTERNAL_XYARRAY_H
#include <linux/compiler.h>
#include <sys/types.h>
struct xyarray {
@ -10,7 +11,7 @@ struct xyarray {
size_t entries;
size_t max_x;
size_t max_y;
char contents[];
char contents[] __aligned(8);
};
struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);

View File

@ -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); \

View File

@ -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);

View File

@ -8,9 +8,12 @@ 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;
perf_thread_map__nr;
perf_thread_map__pid;
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__new;

View File

@ -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;
}

View File

@ -4,6 +4,7 @@
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include "cpumap.h"
#include "debug.h"
#include "mem2node.h"
#include "tests.h"

View File

@ -16,6 +16,7 @@
#include "cpumap.h"
#include "debug.h"
#include "stat.h"
#include "util/counts.h"
int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int subtest __maybe_unused)
{

View File

@ -10,6 +10,7 @@
#include "evsel.h"
#include "debug.h"
#include "tests.h"
#include "util/counts.h"
int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __maybe_unused)
{

View File

@ -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));

View File

@ -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);
}
}

View File

@ -26,6 +26,8 @@
#include "llvm-utils.h"
#include "c++/clang-c.h"
#include <internal/xyarray.h>
static int libbpf_perf_print(enum libbpf_print_level level __attribute__((unused)),
const char *fmt, va_list args)
{

View File

@ -2,8 +2,12 @@
#ifndef __PERF_COUNTS_H
#define __PERF_COUNTS_H
#include <linux/types.h>
#include <internal/xyarray.h>
#include <perf/evsel.h>
#include <stdbool.h>
struct evsel;
struct perf_counts {
s8 scaled;

View File

@ -2,6 +2,8 @@
#include <api/fs/fs.h>
#include "../perf.h"
#include "cpumap.h"
#include "debug.h"
#include "event.h"
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
@ -21,7 +23,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 +50,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 +79,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);
@ -458,19 +460,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)

View File

@ -4,14 +4,14 @@
#include <stdio.h>
#include <stdbool.h>
#include <linux/refcount.h>
#include <internal/cpumap.h>
#include <perf/cpumap.h>
#include "perf.h"
#include "util/debug.h"
struct perf_cpu_map *cpu_map__empty_new(int nr);
struct cpu_map_data;
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,16 +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;
}
int cpu__setup_cpunode_map(void);
int cpu__max_node(void);
@ -72,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 */

View File

@ -3,12 +3,14 @@
#include <sys/utsname.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <api/fs/fs.h>
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include "cputopo.h"
#include "cpumap.h"
#include "debug.h"
#include "env.h"
#define CORE_SIB_FMT \

View File

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "cpumap.h"
#include "debug.h"
#include "env.h"
#include <linux/ctype.h>
#include <linux/zalloc.h>

View File

@ -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));
}
@ -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

View File

@ -37,6 +37,8 @@
#include <perf/evsel.h>
#include <perf/cpumap.h>
#include <internal/xyarray.h>
#ifdef LACKS_SIGQUEUE_PROTOTYPE
int sigqueue(pid_t pid, int sig, const union sigval value);
#endif
@ -314,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)
@ -370,7 +372,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;
@ -386,7 +388,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);
@ -396,8 +398,8 @@ 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_threads = thread_map__nr(evlist->core.threads);
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
int nr_threads = perf_thread_map__nr(evlist->core.threads);
int nfds = 0;
struct evsel *evsel;
@ -529,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;
}
@ -692,9 +694,9 @@ 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);
if (cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = thread_map__nr(evlist->core.threads);
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (perf_cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!map)
return NULL;
@ -758,7 +760,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;
@ -807,8 +809,8 @@ 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_threads = thread_map__nr(evlist->core.threads);
int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
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 +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++) {
@ -1014,11 +1016,11 @@ 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;
}
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);

View File

@ -26,6 +26,7 @@
#include "asm/bug.h"
#include "callchain.h"
#include "cgroup.h"
#include "counts.h"
#include "event.h"
#include "evsel.h"
#include "evlist.h"
@ -39,6 +40,7 @@
#include "string2.h"
#include "memswap.h"
#include "util/parse-branch-options.h"
#include <internal/xyarray.h>
#include <linux/ctype.h>
@ -1651,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;
@ -1814,7 +1816,7 @@ retry_sample_id:
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:

View File

@ -4,16 +4,18 @@
#include <linux/list.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <linux/perf_event.h>
#include <linux/types.h>
#include <internal/evsel.h>
#include <internal/xyarray.h>
#include <perf/evsel.h>
#include "symbol_conf.h"
#include "cpumap.h"
#include "counts.h"
#include <internal/cpumap.h>
struct addr_location;
struct evsel;
union perf_event;
/*
* Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
@ -93,6 +95,8 @@ enum perf_tool_event {
};
struct bpf_object;
struct perf_counts;
struct xyarray;
/** struct evsel - event selector
*

View File

@ -2,6 +2,7 @@
#include <inttypes.h>
#include <linux/bitmap.h>
#include <linux/zalloc.h>
#include "debug.h"
#include "mem2node.h"
struct phys_entry {

View File

@ -7,18 +7,19 @@
#include "metricgroup.h"
#include "evlist.h"
#include "evsel.h"
#include "strbuf.h"
#include "pmu.h"
#include "expr.h"
#include "rblist.h"
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include "pmu-events/pmu-events.h"
#include "strlist.h"
#include <assert.h>
#include <linux/ctype.h>
#include <linux/zalloc.h>
#include <subcmd/parse-options.h>
struct metric_event *metricgroup__lookup(struct rblist *metric_events,
struct evsel *evsel,

View File

@ -1,11 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-only
#ifndef METRICGROUP_H
#define METRICGROUP_H 1
#include "linux/list.h"
#include "rblist.h"
#include <subcmd/parse-options.h>
#include "evlist.h"
#include "strbuf.h"
#include <linux/list.h>
#include <linux/rbtree.h>
#include <stdbool.h>
struct evsel;
struct option;
struct rblist;
struct metric_event {
struct rb_node nd;

View File

@ -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)

View File

@ -16,6 +16,7 @@
#include <locale.h>
#include <regex.h>
#include <perf/cpumap.h>
#include "debug.h"
#include "pmu.h"
#include "parse-events.h"
#include "cpumap.h"

View File

@ -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;

View File

@ -32,6 +32,7 @@
#include <linux/time64.h>
#include "../../perf.h"
#include "../counts.h"
#include "../debug.h"
#include "../callchain.h"
#include "../evsel.h"
@ -1405,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));
}
}

View File

@ -4,6 +4,7 @@
#include <linux/time64.h>
#include <math.h>
#include "color.h"
#include "counts.h"
#include "evlist.h"
#include "evsel.h"
#include "stat.h"
@ -118,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:
@ -744,8 +745,8 @@ 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 ncpus = cpu_map__nr(counter->core.cpus);
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;

View File

@ -2,6 +2,7 @@
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include "counts.h"
#include "stat.h"
#include "evlist.h"
#include "evsel.h"
@ -158,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 ||
@ -223,7 +224,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) {
@ -308,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;

View File

@ -14,6 +14,7 @@
#include <unistd.h>
#include <string.h>
#include <linux/bitmap.h>
#include <linux/string.h>
#include <linux/time64.h>
#include <linux/zalloc.h>
#include <perf/cpumap.h>

View File

@ -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 */

View File

@ -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);