Skip to content

Commit

Permalink
libperf: Move 'idx' from tools/perf to perf_evsel::idx
Browse files Browse the repository at this point in the history
Move evsel::idx to perf_evsel::idx, so we can move the group interface
to libperf.

Committer notes:

Fixup evsel->idx usage in tools/perf/util/bpf_counter_cgroup.c, that
appeared in my tree in my local tree.

Also fixed up these:

$ find tools/perf/ -name "*.[ch]" | xargs grep 'evsel->idx'
tools/perf/ui/gtk/annotate.c:                      evsel->idx + i);
tools/perf/ui/gtk/annotate.c:                   evsel->idx);
$

That running 'make -C tools/perf build-test' caught.

Signed-off-by: Jiri Olsa <[email protected]>
Requested-by: Shunsuke Nakamura <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Jiri Olsa authored and acmel committed Jul 9, 2021
1 parent 3d97060 commit 38fe0e0
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 58 deletions.
1 change: 1 addition & 0 deletions tools/lib/perf/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
void perf_evlist__add(struct perf_evlist *evlist,
struct perf_evsel *evsel)
{
evsel->idx = evlist->nr_entries;
list_add_tail(&evsel->node, &evlist->entries);
evlist->nr_entries += 1;
__perf_evlist__propagate_maps(evlist, evsel);
Expand Down
6 changes: 4 additions & 2 deletions tools/lib/perf/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
#include <sys/ioctl.h>
#include <sys/mman.h>

void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
int idx)
{
INIT_LIST_HEAD(&evsel->node);
evsel->attr = *attr;
evsel->idx = idx;
}

struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
{
struct perf_evsel *evsel = zalloc(sizeof(*evsel));

if (evsel != NULL)
perf_evsel__init(evsel, attr);
perf_evsel__init(evsel, attr, 0);

return evsel;
}
Expand Down
4 changes: 3 additions & 1 deletion tools/lib/perf/include/internal/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ struct perf_evsel {
/* parse modifier helper */
int nr_members;
bool system_wide;
int idx;
};

void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr);
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
int idx);
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
void perf_evsel__close_fd(struct perf_evsel *evsel);
void perf_evsel__free_fd(struct perf_evsel *evsel);
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/arch/x86/util/iostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static int iostat_event_group(struct evlist *evl,
}

evlist__for_each_entry(evl, evsel) {
evsel->priv = list->rps[evsel->idx / metrics_count];
evsel->priv = list->rps[evsel->core.idx / metrics_count];
}
list->nr_entries = 0;
err:
Expand Down Expand Up @@ -428,7 +428,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
{
double iostat_value = 0;
u64 prev_count_val = 0;
const char *iostat_metric = iostat_metric_by_idx(evsel->idx);
const char *iostat_metric = iostat_metric_by_idx(evsel->core.idx);
u8 die = ((struct iio_root_port *)evsel->priv)->die;
struct perf_counts_values *count = perf_counts(evsel->counts, die, 0);

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,12 @@ static int process_base_stream(struct data__file *data_base,
continue;

es_base = evsel_streams__entry(data_base->evlist_streams,
evsel_base->idx);
evsel_base->core.idx);
if (!es_base)
return -1;

es_pair = evsel_streams__entry(data_pair->evlist_streams,
evsel_pair->idx);
evsel_pair->core.idx);
if (!es_pair)
return -1;

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static int process_read_event(struct perf_tool *tool,
const char *name = evsel__name(evsel);
int err = perf_read_values_add_value(&rep->show_threads_values,
event->read.pid, event->read.tid,
evsel->idx,
evsel->core.idx,
name,
event->read.value);

Expand Down Expand Up @@ -666,7 +666,7 @@ static int report__collapse_hists(struct report *rep)
evlist__for_each_entry(rep->session->evlist, pos) {
struct hists *hists = evsel__hists(pos);

if (pos->idx == 0)
if (pos->core.idx == 0)
hists->symbol_filter_str = rep->symbol_filter_str;

hists->socket_filter = rep->socket_filter;
Expand Down
8 changes: 4 additions & 4 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ static void perf_top__show_details(struct perf_top *top)

if (top->evlist->enabled) {
if (top->zero)
symbol__annotate_zero_histogram(symbol, top->sym_evsel->idx);
symbol__annotate_zero_histogram(symbol, top->sym_evsel->core.idx);
else
symbol__annotate_decay_histogram(symbol, top->sym_evsel->idx);
symbol__annotate_decay_histogram(symbol, top->sym_evsel->core.idx);
}
if (more != 0)
printf("%d lines not displayed, maybe increase display entries [e]\n", more);
Expand Down Expand Up @@ -530,7 +530,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
fprintf(stderr, "\nAvailable events:");

evlist__for_each_entry(top->evlist, top->sym_evsel)
fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, evsel__name(top->sym_evsel));
fprintf(stderr, "\n\t%d %s", top->sym_evsel->core.idx, evsel__name(top->sym_evsel));

prompt_integer(&counter, "Enter details event counter");

Expand All @@ -541,7 +541,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
break;
}
evlist__for_each_entry(top->evlist, top->sym_evsel)
if (top->sym_evsel->idx == counter)
if (top->sym_evsel->core.idx == counter)
break;
} else
top->sym_evsel = evlist__first(top->evlist);
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/tests/evsel-roundtrip-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)

for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
__evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
if (evsel->idx != idx)
if (evsel->core.idx != idx)
continue;

++idx;
Expand Down Expand Up @@ -84,9 +84,9 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names,

err = 0;
evlist__for_each_entry(evlist, evsel) {
if (strcmp(evsel__name(evsel), names[evsel->idx / distance])) {
if (strcmp(evsel__name(evsel), names[evsel->core.idx / distance])) {
--err;
pr_debug("%s != %s\n", evsel__name(evsel), names[evsel->idx / distance]);
pr_debug("%s != %s\n", evsel__name(evsel), names[evsel->core.idx / distance]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tools/perf/tests/mmap-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
" doesn't map to an evsel\n", sample.id);
goto out_delete_evlist;
}
nr_events[evsel->idx]++;
nr_events[evsel->core.idx]++;
perf_mmap__consume(&md->core);
}
perf_mmap__read_done(&md->core);

out_init:
err = 0;
evlist__for_each_entry(evlist, evsel) {
if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) {
if (nr_events[evsel->core.idx] != expected_nr_events[evsel->core.idx]) {
pr_debug("expected %d %s events, got %d\n",
expected_nr_events[evsel->idx],
evsel__name(evsel), nr_events[evsel->idx]);
expected_nr_events[evsel->core.idx],
evsel__name(evsel), nr_events[evsel->core.idx]);
err = -1;
goto out_delete_evlist;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
hbt->timer(hbt->arg);

if (delay_secs != 0) {
symbol__annotate_decay_histogram(sym, evsel->idx);
symbol__annotate_decay_histogram(sym, evsel->core.idx);
hists__scnprintf_title(hists, title, sizeof(title));
annotate_browser__show(&browser->b, title, help);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/ui/gtk/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct map_symbol *ms,
ret += perf_gtk__get_percent(s + ret,
sizeof(s) - ret,
sym, pos,
evsel->idx + i);
evsel->core.idx + i);
ret += scnprintf(s + ret, sizeof(s) - ret, " ");
}
} else {
ret = perf_gtk__get_percent(s, sizeof(s), sym, pos,
evsel->idx);
evsel->core.idx);
}

if (ret)
Expand Down
8 changes: 4 additions & 4 deletions tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ static int symbol__inc_addr_samples(struct map_symbol *ms,
if (sym == NULL)
return 0;
src = symbol__hists(sym, evsel->evlist->core.nr_entries);
return src ? __symbol__inc_addr_samples(ms, src, evsel->idx, addr, sample) : 0;
return src ? __symbol__inc_addr_samples(ms, src, evsel->core.idx, addr, sample) : 0;
}

static int symbol__account_cycles(u64 addr, u64 start,
Expand Down Expand Up @@ -2159,7 +2159,7 @@ static void annotation__calc_percent(struct annotation *notes,

BUG_ON(i >= al->data_nr);

sym_hist = annotation__histogram(notes, evsel->idx);
sym_hist = annotation__histogram(notes, evsel->core.idx);
data = &al->data[i++];

calc_percent(sym_hist, hists, data, al->offset, end);
Expand Down Expand Up @@ -2340,7 +2340,7 @@ static void print_summary(struct rb_root *root, const char *filename)
static void symbol__annotate_hits(struct symbol *sym, struct evsel *evsel)
{
struct annotation *notes = symbol__annotation(sym);
struct sym_hist *h = annotation__histogram(notes, evsel->idx);
struct sym_hist *h = annotation__histogram(notes, evsel->core.idx);
u64 len = symbol__size(sym), offset;

for (offset = 0; offset < len; ++offset)
Expand Down Expand Up @@ -2373,7 +2373,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
const char *d_filename;
const char *evsel_name = evsel__name(evsel);
struct annotation *notes = symbol__annotation(sym);
struct sym_hist *h = annotation__histogram(notes, evsel->idx);
struct sym_hist *h = annotation__histogram(notes, evsel->core.idx);
struct annotation_line *pos, *queue = NULL;
u64 start = map__rip_2objdump(map, sym->start);
int printed = 2, queue_len = 0, addr_fmt_width;
Expand Down
12 changes: 6 additions & 6 deletions tools/perf/util/bpf_counter_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int bperf_load_program(struct evlist *evlist)
map_fd = bpf_map__fd(skel->maps.events);
for (cpu = 0; cpu < nr_cpus; cpu++) {
int fd = FD(evsel, cpu);
__u32 idx = evsel->idx * total_cpus +
__u32 idx = evsel->core.idx * total_cpus +
evlist->core.all_cpus->map[cpu];

err = bpf_map_update_elem(map_fd, &idx, &fd,
Expand Down Expand Up @@ -221,7 +221,7 @@ static int bperf_cgrp__sync_counters(struct evlist *evlist)

static int bperf_cgrp__enable(struct evsel *evsel)
{
if (evsel->idx)
if (evsel->core.idx)
return 0;

bperf_cgrp__sync_counters(evsel->evlist);
Expand All @@ -232,7 +232,7 @@ static int bperf_cgrp__enable(struct evsel *evsel)

static int bperf_cgrp__disable(struct evsel *evsel)
{
if (evsel->idx)
if (evsel->core.idx)
return 0;

bperf_cgrp__sync_counters(evsel->evlist);
Expand All @@ -251,7 +251,7 @@ static int bperf_cgrp__read(struct evsel *evsel)
int reading_map_fd, err = 0;
__u32 idx;

if (evsel->idx)
if (evsel->core.idx)
return 0;

bperf_cgrp__sync_counters(evsel->evlist);
Expand All @@ -263,7 +263,7 @@ static int bperf_cgrp__read(struct evsel *evsel)
reading_map_fd = bpf_map__fd(skel->maps.cgrp_readings);

evlist__for_each_entry(evlist, evsel) {
idx = evsel->idx;
idx = evsel->core.idx;
err = bpf_map_lookup_elem(reading_map_fd, &idx, values);
if (err) {
pr_err("bpf map lookup falied: idx=%u, event=%s, cgrp=%s\n",
Expand All @@ -288,7 +288,7 @@ static int bperf_cgrp__read(struct evsel *evsel)

static int bperf_cgrp__destroy(struct evsel *evsel)
{
if (evsel->idx)
if (evsel->core.idx)
return 0;

bperf_cgroup_bpf__destroy(skel);
Expand Down
10 changes: 4 additions & 6 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,9 @@ void evlist__delete(struct evlist *evlist)

void evlist__add(struct evlist *evlist, struct evsel *entry)
{
entry->evlist = evlist;
entry->idx = evlist->core.nr_entries;
entry->tracking = !entry->idx;

perf_evlist__add(&evlist->core, &entry->core);
entry->evlist = evlist;
entry->tracking = !entry->core.idx;

if (evlist->core.nr_entries == 1)
evlist__set_id_pos(evlist);
Expand Down Expand Up @@ -232,7 +230,7 @@ void __evlist__set_leader(struct list_head *list)
leader = list_entry(list->next, struct evsel, core.node);
evsel = list_entry(list->prev, struct evsel, core.node);

leader->core.nr_members = evsel->idx - leader->idx + 1;
leader->core.nr_members = evsel->core.idx - leader->core.idx + 1;

__evlist__for_each_entry(list, evsel) {
evsel->leader = leader;
Expand Down Expand Up @@ -2137,7 +2135,7 @@ struct evsel *evlist__find_evsel(struct evlist *evlist, int idx)
struct evsel *evsel;

evlist__for_each_entry(evlist, evsel) {
if (evsel->idx == idx)
if (evsel->core.idx == idx)
return evsel;
}
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ bool evsel__is_function_event(struct evsel *evsel)
void evsel__init(struct evsel *evsel,
struct perf_event_attr *attr, int idx)
{
perf_evsel__init(&evsel->core, attr);
evsel->idx = idx;
perf_evsel__init(&evsel->core, attr, idx);
evsel->tracking = !idx;
evsel->leader = evsel;
evsel->unit = "";
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct evsel {
struct perf_evsel core;
struct evlist *evlist;
off_t id_offset;
int idx;
int id_pos;
int is_pos;
unsigned int sample_size;
Expand Down Expand Up @@ -406,7 +405,7 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,

static inline int evsel__group_idx(struct evsel *evsel)
{
return evsel->idx - evsel->leader->idx;
return evsel->core.idx - evsel->leader->core.idx;
}

/* Iterates group WITHOUT the leader. */
Expand Down
10 changes: 5 additions & 5 deletions tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ static int write_group_desc(struct feat_fd *ff,
evlist__for_each_entry(evlist, evsel) {
if (evsel__is_group_leader(evsel) && evsel->core.nr_members > 1) {
const char *name = evsel->group_name ?: "{anon_group}";
u32 leader_idx = evsel->idx;
u32 leader_idx = evsel->core.idx;
u32 nr_members = evsel->core.nr_members;

ret = do_write_string(ff, name);
Expand Down Expand Up @@ -1844,7 +1844,7 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
msz = sz;

for (i = 0, evsel = events; i < nre; evsel++, i++) {
evsel->idx = i;
evsel->core.idx = i;

/*
* must read entire on-file attr struct to
Expand Down Expand Up @@ -2379,7 +2379,7 @@ static struct evsel *evlist__find_by_index(struct evlist *evlist, int idx)
struct evsel *evsel;

evlist__for_each_entry(evlist, evsel) {
if (evsel->idx == idx)
if (evsel->core.idx == idx)
return evsel;
}

Expand All @@ -2393,7 +2393,7 @@ static void evlist__set_event_name(struct evlist *evlist, struct evsel *event)
if (!event->name)
return;

evsel = evlist__find_by_index(evlist, event->idx);
evsel = evlist__find_by_index(evlist, event->core.idx);
if (!evsel)
return;

Expand Down Expand Up @@ -2739,7 +2739,7 @@ static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused)

i = nr = 0;
evlist__for_each_entry(session->evlist, evsel) {
if (evsel->idx == (int) desc[i].leader_idx) {
if (evsel->core.idx == (int) desc[i].leader_idx) {
evsel->leader = evsel;
/* {anon_group} is a dummy name */
if (strcmp(desc[i].name, "{anon_group}")) {
Expand Down
Loading

0 comments on commit 38fe0e0

Please sign in to comment.