Commit 515dbe48 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

libperf: Add perf_evlist__first()/last() functions

Add perf_evlist__first()/last() functions to libperf, as internal
functions and rename perf's origins to evlist__first/last.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lore.kernel.org/lkml/20190913132355.21634-29-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 70c20369
...@@ -416,7 +416,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, ...@@ -416,7 +416,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
if (err) if (err)
goto out; goto out;
tracking_evsel = perf_evlist__last(evlist); tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel); perf_evlist__set_tracking_event(evlist, tracking_evsel);
tracking_evsel->core.attr.freq = 0; tracking_evsel->core.attr.freq = 0;
......
...@@ -129,7 +129,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, ...@@ -129,7 +129,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
if (err) if (err)
return err; return err;
tracking_evsel = perf_evlist__last(evlist); tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel); perf_evlist__set_tracking_event(evlist, tracking_evsel);
tracking_evsel->core.attr.freq = 0; tracking_evsel->core.attr.freq = 0;
......
...@@ -62,9 +62,9 @@ int test__intel_cqm_count_nmi_context(struct test *test __maybe_unused, int subt ...@@ -62,9 +62,9 @@ int test__intel_cqm_count_nmi_context(struct test *test __maybe_unused, int subt
goto out; goto out;
} }
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
if (!evsel) { if (!evsel) {
pr_debug("perf_evlist__first failed\n"); pr_debug("evlist__first failed\n");
goto out; goto out;
} }
......
...@@ -83,7 +83,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe ...@@ -83,7 +83,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
perf_evlist__config(evlist, &opts, NULL); perf_evlist__config(evlist, &opts, NULL);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
evsel->core.attr.comm = 1; evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1; evsel->core.attr.disabled = 1;
......
...@@ -231,7 +231,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, ...@@ -231,7 +231,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
if (err) if (err)
return err; return err;
tracking_evsel = perf_evlist__last(evlist); tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel); perf_evlist__set_tracking_event(evlist, tracking_evsel);
......
...@@ -417,7 +417,7 @@ static int intel_pt_track_switches(struct evlist *evlist) ...@@ -417,7 +417,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
return err; return err;
} }
evsel = perf_evlist__last(evlist); evsel = evlist__last(evlist);
perf_evsel__set_sample_bit(evsel, CPU); perf_evsel__set_sample_bit(evsel, CPU);
perf_evsel__set_sample_bit(evsel, TIME); perf_evsel__set_sample_bit(evsel, TIME);
...@@ -717,7 +717,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, ...@@ -717,7 +717,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
if (err) if (err)
return err; return err;
switch_evsel = perf_evlist__last(evlist); switch_evsel = evlist__last(evlist);
switch_evsel->core.attr.freq = 0; switch_evsel->core.attr.freq = 0;
switch_evsel->core.attr.sample_period = 1; switch_evsel->core.attr.sample_period = 1;
...@@ -775,7 +775,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, ...@@ -775,7 +775,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
if (err) if (err)
return err; return err;
tracking_evsel = perf_evlist__last(evlist); tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel); perf_evlist__set_tracking_event(evlist, tracking_evsel);
......
...@@ -756,9 +756,9 @@ static int record__open(struct record *rec) ...@@ -756,9 +756,9 @@ static int record__open(struct record *rec)
if (perf_evlist__add_dummy(evlist)) if (perf_evlist__add_dummy(evlist))
return -ENOMEM; return -ENOMEM;
pos = perf_evlist__first(evlist); pos = evlist__first(evlist);
pos->tracking = 0; pos->tracking = 0;
pos = perf_evlist__last(evlist); pos = evlist__last(evlist);
pos->tracking = 1; pos->tracking = 1;
pos->core.attr.enable_on_exec = 1; pos->core.attr.enable_on_exec = 1;
} }
......
...@@ -2043,7 +2043,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, ...@@ -2043,7 +2043,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
return err; return err;
evlist = *pevlist; evlist = *pevlist;
evsel = perf_evlist__last(*pevlist); evsel = evlist__last(*pevlist);
if (!evsel->priv) { if (!evsel->priv) {
if (scr->per_event_dump) { if (scr->per_event_dump) {
......
...@@ -531,7 +531,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c) ...@@ -531,7 +531,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
prompt_integer(&counter, "Enter details event counter"); prompt_integer(&counter, "Enter details event counter");
if (counter >= top->evlist->core.nr_entries) { if (counter >= top->evlist->core.nr_entries) {
top->sym_evsel = perf_evlist__first(top->evlist); top->sym_evsel = evlist__first(top->evlist);
fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel)); fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel));
sleep(1); sleep(1);
break; break;
...@@ -540,7 +540,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c) ...@@ -540,7 +540,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
if (top->sym_evsel->idx == counter) if (top->sym_evsel->idx == counter)
break; break;
} else } else
top->sym_evsel = perf_evlist__first(top->evlist); top->sym_evsel = evlist__first(top->evlist);
break; break;
case 'f': case 'f':
prompt_integer(&top->count_filter, "Enter display event count filter"); prompt_integer(&top->count_filter, "Enter display event count filter");
...@@ -962,7 +962,7 @@ static int perf_top__overwrite_check(struct perf_top *top) ...@@ -962,7 +962,7 @@ static int perf_top__overwrite_check(struct perf_top *top)
/* has term for current event */ /* has term for current event */
if ((overwrite < 0) && (set >= 0)) { if ((overwrite < 0) && (set >= 0)) {
/* if it's first event, set overwrite */ /* if it's first event, set overwrite */
if (evsel == perf_evlist__first(evlist)) if (evsel == evlist__first(evlist))
overwrite = set; overwrite = set;
else else
return -1; return -1;
...@@ -986,7 +986,7 @@ static int perf_top_overwrite_fallback(struct perf_top *top, ...@@ -986,7 +986,7 @@ static int perf_top_overwrite_fallback(struct perf_top *top,
return 0; return 0;
/* only fall back when first event fails */ /* only fall back when first event fails */
if (evsel != perf_evlist__first(evlist)) if (evsel != evlist__first(evlist))
return 0; return 0;
evlist__for_each_entry(evlist, counter) evlist__for_each_entry(evlist, counter)
...@@ -1644,7 +1644,7 @@ int cmd_top(int argc, const char **argv) ...@@ -1644,7 +1644,7 @@ int cmd_top(int argc, const char **argv)
goto out_delete_evlist; goto out_delete_evlist;
} }
top.sym_evsel = perf_evlist__first(top.evlist); top.sym_evsel = evlist__first(top.evlist);
if (!callchain_param.enabled) { if (!callchain_param.enabled) {
symbol_conf.cumulate_callchain = false; symbol_conf.cumulate_callchain = false;
......
...@@ -3427,7 +3427,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) ...@@ -3427,7 +3427,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
trace->multiple_threads = perf_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 || evlist->core.threads->nr > 1 ||
perf_evlist__first(evlist)->core.attr.inherit; evlist__first(evlist)->core.attr.inherit;
/* /*
* Now that we already used evsel->core.attr to ask the kernel to setup the * Now that we already used evsel->core.attr to ask the kernel to setup the
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <api/fd/array.h> #include <api/fd/array.h>
#include <internal/evsel.h>
#define PERF_EVLIST__HLIST_BITS 8 #define PERF_EVLIST__HLIST_BITS 8
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
...@@ -55,4 +56,14 @@ struct perf_evlist { ...@@ -55,4 +56,14 @@ struct perf_evlist {
#define perf_evlist__for_each_entry_reverse(evlist, evsel) \ #define perf_evlist__for_each_entry_reverse(evlist, evsel) \
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
{
return list_entry(evlist->entries.next, struct perf_evsel, node);
}
static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
{
return list_entry(evlist->entries.prev, struct perf_evsel, node);
}
#endif /* __LIBPERF_INTERNAL_EVLIST_H */ #endif /* __LIBPERF_INTERNAL_EVLIST_H */
...@@ -652,7 +652,7 @@ static int do_test_code_reading(bool try_kcore) ...@@ -652,7 +652,7 @@ static int do_test_code_reading(bool try_kcore)
perf_evlist__config(evlist, &opts, NULL); perf_evlist__config(evlist, &opts, NULL);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
evsel->core.attr.comm = 1; evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1; evsel->core.attr.disabled = 1;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
static int attach__enable_on_exec(struct evlist *evlist) static int attach__enable_on_exec(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
struct target target = { struct target target = {
.uid = UINT_MAX, .uid = UINT_MAX,
}; };
...@@ -58,7 +58,7 @@ static int detach__enable_on_exec(struct evlist *evlist) ...@@ -58,7 +58,7 @@ static int detach__enable_on_exec(struct evlist *evlist)
static int attach__current_disabled(struct evlist *evlist) static int attach__current_disabled(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads; struct perf_thread_map *threads;
int err; int err;
...@@ -84,7 +84,7 @@ static int attach__current_disabled(struct evlist *evlist) ...@@ -84,7 +84,7 @@ static int attach__current_disabled(struct evlist *evlist)
static int attach__current_enabled(struct evlist *evlist) static int attach__current_enabled(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads; struct perf_thread_map *threads;
int err; int err;
...@@ -104,14 +104,14 @@ static int attach__current_enabled(struct evlist *evlist) ...@@ -104,14 +104,14 @@ static int attach__current_enabled(struct evlist *evlist)
static int detach__disable(struct evlist *evlist) static int detach__disable(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
return evsel__enable(evsel); return evsel__enable(evsel);
} }
static int attach__cpu_disabled(struct evlist *evlist) static int attach__cpu_disabled(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
int err; int err;
...@@ -140,7 +140,7 @@ static int attach__cpu_disabled(struct evlist *evlist) ...@@ -140,7 +140,7 @@ static int attach__cpu_disabled(struct evlist *evlist)
static int attach__cpu_enabled(struct evlist *evlist) static int attach__cpu_enabled(struct evlist *evlist)
{ {
struct evsel *evsel = perf_evlist__last(evlist); struct evsel *evsel = evlist__last(evlist);
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
int err; int err;
...@@ -180,7 +180,7 @@ static int test_times(int (attach)(struct evlist *), ...@@ -180,7 +180,7 @@ static int test_times(int (attach)(struct evlist *),
goto out_err; goto out_err;
} }
evsel = perf_evlist__last(evlist); evsel = evlist__last(evlist);
evsel->core.attr.read_format |= evsel->core.attr.read_format |=
PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_ENABLED |
PERF_FORMAT_TOTAL_TIME_RUNNING; PERF_FORMAT_TOTAL_TIME_RUNNING;
......
...@@ -92,7 +92,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu ...@@ -92,7 +92,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
evlist = perf_evlist__new_default(); evlist = perf_evlist__new_default();
TEST_ASSERT_VAL("failed to get evlist", evlist); TEST_ASSERT_VAL("failed to get evlist", evlist);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
TEST_ASSERT_VAL("failed to allocate ids", TEST_ASSERT_VAL("failed to allocate ids",
!perf_evsel__alloc_id(&evsel->core, 1, 1)); !perf_evsel__alloc_id(&evsel->core, 1, 1));
......
...@@ -34,7 +34,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) ...@@ -34,7 +34,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
} }
idx = 0; idx = 0;
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
......
...@@ -721,7 +721,7 @@ int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_u ...@@ -721,7 +721,7 @@ int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_u
if (verbose > 1) if (verbose > 1)
machine__fprintf(machine, stderr); machine__fprintf(machine, stderr);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
for (i = 0; i < ARRAY_SIZE(testcases); i++) { for (i = 0; i < ARRAY_SIZE(testcases); i++) {
err = testcases[i](evsel, machine); err = testcases[i](evsel, machine);
......
...@@ -311,8 +311,8 @@ int test__hists_link(struct test *test __maybe_unused, int subtest __maybe_unuse ...@@ -311,8 +311,8 @@ int test__hists_link(struct test *test __maybe_unused, int subtest __maybe_unuse
print_hists_in(hists); print_hists_in(hists);
} }
first = perf_evlist__first(evlist); first = evlist__first(evlist);
evsel = perf_evlist__last(evlist); evsel = evlist__last(evlist);
first_hists = evsel__hists(first); first_hists = evsel__hists(first);
hists = evsel__hists(evsel); hists = evsel__hists(evsel);
......
...@@ -608,7 +608,7 @@ int test__hists_output(struct test *test __maybe_unused, int subtest __maybe_unu ...@@ -608,7 +608,7 @@ int test__hists_output(struct test *test __maybe_unused, int subtest __maybe_unu
if (verbose > 1) if (verbose > 1)
machine__fprintf(machine, stderr); machine__fprintf(machine, stderr);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
for (i = 0; i < ARRAY_SIZE(testcases); i++) { for (i = 0; i < ARRAY_SIZE(testcases); i++) {
err = testcases[i](evsel, machine); err = testcases[i](evsel, machine);
......
...@@ -93,7 +93,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un ...@@ -93,7 +93,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
perf_evlist__config(evlist, &opts, NULL); perf_evlist__config(evlist, &opts, NULL);
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
evsel->core.attr.comm = 1; evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1; evsel->core.attr.disabled = 1;
...@@ -132,7 +132,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un ...@@ -132,7 +132,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
evlist__enable(evlist); evlist__enable(evlist);
evsel = perf_evlist__last(evlist); evsel = evlist__last(evlist);
CHECK__(evsel__disable(evsel)); CHECK__(evsel__disable(evsel));
......
This diff is collapsed.
...@@ -104,7 +104,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus ...@@ -104,7 +104,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
/* /*
* Config the evsels, setting attr->comm on the first one, etc. * Config the evsels, setting attr->comm on the first one, etc.
*/ */
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
perf_evsel__set_sample_bit(evsel, CPU); perf_evsel__set_sample_bit(evsel, CPU);
perf_evsel__set_sample_bit(evsel, TID); perf_evsel__set_sample_bit(evsel, TID);
perf_evsel__set_sample_bit(evsel, TIME); perf_evsel__set_sample_bit(evsel, TIME);
......
...@@ -367,7 +367,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -367,7 +367,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err; goto out_err;
} }
cpu_clocks_evsel = perf_evlist__last(evlist); cpu_clocks_evsel = evlist__last(evlist);
/* Second event */ /* Second event */
err = parse_events(evlist, "cycles:u", NULL); err = parse_events(evlist, "cycles:u", NULL);
...@@ -376,7 +376,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -376,7 +376,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err; goto out_err;
} }
cycles_evsel = perf_evlist__last(evlist); cycles_evsel = evlist__last(evlist);
/* Third event */ /* Third event */
if (!perf_evlist__can_select_event(evlist, sched_switch)) { if (!perf_evlist__can_select_event(evlist, sched_switch)) {
...@@ -391,7 +391,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -391,7 +391,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err; goto out_err;
} }
switch_evsel = perf_evlist__last(evlist); switch_evsel = evlist__last(evlist);
perf_evsel__set_sample_bit(switch_evsel, CPU); perf_evsel__set_sample_bit(switch_evsel, CPU);
perf_evsel__set_sample_bit(switch_evsel, TIME); perf_evsel__set_sample_bit(switch_evsel, TIME);
...@@ -401,12 +401,12 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -401,12 +401,12 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
switch_evsel->immediate = true; switch_evsel->immediate = true;
/* Test moving an event to the front */ /* Test moving an event to the front */
if (cycles_evsel == perf_evlist__first(evlist)) { if (cycles_evsel == evlist__first(evlist)) {
pr_debug("cycles event already at front"); pr_debug("cycles event already at front");
goto out_err; goto out_err;
} }
perf_evlist__to_front(evlist, cycles_evsel); perf_evlist__to_front(evlist, cycles_evsel);
if (cycles_evsel != perf_evlist__first(evlist)) { if (cycles_evsel != evlist__first(evlist)) {
pr_debug("Failed to move cycles event to front"); pr_debug("Failed to move cycles event to front");
goto out_err; goto out_err;
} }
...@@ -421,7 +421,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -421,7 +421,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err; goto out_err;
} }
tracking_evsel = perf_evlist__last(evlist); tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel); perf_evlist__set_tracking_event(evlist, tracking_evsel);
...@@ -434,7 +434,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ ...@@ -434,7 +434,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
perf_evlist__config(evlist, &opts, NULL); perf_evlist__config(evlist, &opts, NULL);
/* Check moved event is still at the front */ /* Check moved event is still at the front */
if (cycles_evsel != perf_evlist__first(evlist)) { if (cycles_evsel != evlist__first(evlist)) {
pr_debug("Front event no longer at front"); pr_debug("Front event no longer at front");
goto out_err; goto out_err;
} }
......
...@@ -88,7 +88,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused ...@@ -88,7 +88,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
goto out_delete_evlist; goto out_delete_evlist;
} }
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
evsel->core.attr.task = 1; evsel->core.attr.task = 1;
#ifdef __s390x__ #ifdef __s390x__
evsel->core.attr.sample_freq = 1000000; evsel->core.attr.sample_freq = 1000000;
......
...@@ -3319,13 +3319,13 @@ static int perf_evsel_menu__run(struct evsel_menu *menu, ...@@ -3319,13 +3319,13 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,
switch (key) { switch (key) {
case K_TAB: case K_TAB:
if (pos->core.node.next == &evlist->core.entries) if (pos->core.node.next == &evlist->core.entries)
pos = perf_evlist__first(evlist); pos = evlist__first(evlist);
else else
pos = perf_evsel__next(pos); pos = perf_evsel__next(pos);
goto browse_hists; goto browse_hists;
case K_UNTAB: case K_UNTAB:
if (pos->core.node.prev == &evlist->core.entries) if (pos->core.node.prev == &evlist->core.entries)
pos = perf_evlist__last(evlist); pos = evlist__last(evlist);
else else
pos = perf_evsel__prev(pos); pos = perf_evsel__prev(pos);
goto browse_hists; goto browse_hists;
...@@ -3417,7 +3417,7 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help, ...@@ -3417,7 +3417,7 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
single_entry: single_entry:
if (nr_entries == 1) { if (nr_entries == 1) {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
return perf_evsel__hists_browse(first, nr_entries, help, return perf_evsel__hists_browse(first, nr_entries, help,
false, hbt, min_pcnt, false, hbt, min_pcnt,
......
...@@ -1568,7 +1568,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name) ...@@ -1568,7 +1568,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
return ERR_PTR(-err); return ERR_PTR(-err);
} }
evsel = perf_evlist__last(evlist); evsel = evlist__last(evlist);
} }
bpf__for_each_map_named(map, obj, tmp, name) { bpf__for_each_map_named(map, obj, tmp, name) {
......
...@@ -105,7 +105,7 @@ struct evlist *perf_evlist__new_dummy(void) ...@@ -105,7 +105,7 @@ struct evlist *perf_evlist__new_dummy(void)
*/ */
void perf_evlist__set_id_pos(struct evlist *evlist) void perf_evlist__set_id_pos(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
evlist->id_pos = first->id_pos; evlist->id_pos = first->id_pos;
evlist->is_pos = first->is_pos; evlist->is_pos = first->is_pos;
...@@ -559,14 +559,14 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id) ...@@ -559,14 +559,14 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
struct perf_sample_id *sid; struct perf_sample_id *sid;
if (evlist->core.nr_entries == 1 || !id) if (evlist->core.nr_entries == 1 || !id)
return perf_evlist__first(evlist); return evlist__first(evlist);
sid = perf_evlist__id2sid(evlist, id); sid = perf_evlist__id2sid(evlist, id);
if (sid) if (sid)
return container_of(sid->evsel, struct evsel, core); return container_of(sid->evsel, struct evsel, core);
if (!perf_evlist__sample_id_all(evlist)) if (!perf_evlist__sample_id_all(evlist))
return perf_evlist__first(evlist); return evlist__first(evlist);
return NULL; return NULL;
} }
...@@ -610,7 +610,7 @@ static int perf_evlist__event2id(struct evlist *evlist, ...@@ -610,7 +610,7 @@ static int perf_evlist__event2id(struct evlist *evlist,
struct evsel *perf_evlist__event2evsel(struct evlist *evlist, struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
union perf_event *event) union perf_event *event)
{ {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
struct hlist_head *head; struct hlist_head *head;
struct perf_sample_id *sid; struct perf_sample_id *sid;
int hash; int hash;
...@@ -1222,7 +1222,7 @@ u64 perf_evlist__combined_branch_type(struct evlist *evlist) ...@@ -1222,7 +1222,7 @@ u64 perf_evlist__combined_branch_type(struct evlist *evlist)
bool perf_evlist__valid_read_format(struct evlist *evlist) bool perf_evlist__valid_read_format(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist), *pos = first; struct evsel *first = evlist__first(evlist), *pos = first;
u64 read_format = first->core.attr.read_format; u64 read_format = first->core.attr.read_format;
u64 sample_type = first->core.attr.sample_type; u64 sample_type = first->core.attr.sample_type;
...@@ -1242,13 +1242,13 @@ bool perf_evlist__valid_read_format(struct evlist *evlist) ...@@ -1242,13 +1242,13 @@ bool perf_evlist__valid_read_format(struct evlist *evlist)
u64 perf_evlist__read_format(struct evlist *evlist) u64 perf_evlist__read_format(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
return first->core.attr.read_format; return first->core.attr.read_format;
} }
u16 perf_evlist__id_hdr_size(struct evlist *evlist) u16 perf_evlist__id_hdr_size(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
struct perf_sample *data; struct perf_sample *data;
u64 sample_type; u64 sample_type;
u16 size = 0; u16 size = 0;
...@@ -1281,7 +1281,7 @@ u16 perf_evlist__id_hdr_size(struct evlist *evlist) ...@@ -1281,7 +1281,7 @@ u16 perf_evlist__id_hdr_size(struct evlist *evlist)
bool perf_evlist__valid_sample_id_all(struct evlist *evlist) bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist), *pos = first; struct evsel *first = evlist__first(evlist), *pos = first;
evlist__for_each_entry_continue(evlist, pos) { evlist__for_each_entry_continue(evlist, pos) {
if (first->core.attr.sample_id_all != pos->core.attr.sample_id_all) if (first->core.attr.sample_id_all != pos->core.attr.sample_id_all)
...@@ -1293,7 +1293,7 @@ bool perf_evlist__valid_sample_id_all(struct evlist *evlist) ...@@ -1293,7 +1293,7 @@ bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
bool perf_evlist__sample_id_all(struct evlist *evlist) bool perf_evlist__sample_id_all(struct evlist *evlist)
{ {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
return first->core.attr.sample_id_all; return first->core.attr.sample_id_all;
} }
...@@ -1568,7 +1568,7 @@ int perf_evlist__strerror_open(struct evlist *evlist, ...@@ -1568,7 +1568,7 @@ int perf_evlist__strerror_open(struct evlist *evlist,
"Hint:\tThe current value is %d.", value); "Hint:\tThe current value is %d.", value);
break; break;
case EINVAL: { case EINVAL: {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
int max_freq; int max_freq;
if (sysctl__read_int("kernel/perf_event_max_sample_rate", &max_freq) < 0) if (sysctl__read_int("kernel/perf_event_max_sample_rate", &max_freq) < 0)
...@@ -1630,7 +1630,7 @@ void perf_evlist__to_front(struct evlist *evlist, ...@@ -1630,7 +1630,7 @@ void perf_evlist__to_front(struct evlist *evlist,
struct evsel *evsel, *n; struct evsel *evsel, *n;
LIST_HEAD(move); LIST_HEAD(move);
if (move_evsel == perf_evlist__first(evlist)) if (move_evsel == evlist__first(evlist))
return; return;
evlist__for_each_entry_safe(evlist, n, evsel) { evlist__for_each_entry_safe(evlist, n, evsel) {
...@@ -1751,7 +1751,7 @@ bool perf_evlist__exclude_kernel(struct evlist *evlist) ...@@ -1751,7 +1751,7 @@ bool perf_evlist__exclude_kernel(struct evlist *evlist)
void perf_evlist__force_leader(struct evlist *evlist) void perf_evlist__force_leader(struct evlist *evlist)
{ {
if (!evlist->nr_groups) { if (!evlist->nr_groups) {
struct evsel *leader = perf_evlist__first(evlist); struct evsel *leader = evlist__first(evlist);
perf_evlist__set_leader(evlist); perf_evlist__set_leader(evlist);
leader->forced_leader = true; leader->forced_leader = true;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <api/fd/array.h> #include <api/fd/array.h>
#include <stdio.h> #include <stdio.h>
#include <internal/evlist.h> #include <internal/evlist.h>
#include <internal/evsel.h>
#include "events_stats.h" #include "events_stats.h"
#include "evsel.h" #include "evsel.h"
#include <pthread.h> #include <pthread.h>
...@@ -242,14 +243,18 @@ static inline bool perf_evlist__empty(struct evlist *evlist) ...@@ -242,14 +243,18 @@ static inline bool perf_evlist__empty(struct evlist *evlist)
return list_empty(&evlist->core.entries); return list_empty(&evlist->core.entries);
} }
static inline struct evsel *perf_evlist__first(struct evlist *evlist) static inline struct evsel *evlist__first(struct evlist *evlist)
{ {
return list_entry(evlist->core.entries.next, struct evsel, core.node); struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
return container_of(evsel, struct evsel, core);
} }
static inline struct evsel *perf_evlist__last(struct evlist *evlist) static inline struct evsel *evlist__last(struct evlist *evlist)
{ {
return list_entry(evlist->core.entries.prev, struct evsel, core.node); struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
return container_of(evsel, struct evsel, core);
} }
size_t perf_evlist__fprintf(struct evlist *evlist, FILE *fp); size_t perf_evlist__fprintf(struct evlist *evlist, FILE *fp);
......
...@@ -777,7 +777,7 @@ jit_process(struct perf_session *session, ...@@ -777,7 +777,7 @@ jit_process(struct perf_session *session,
* track sample_type to compute id_all layout * track sample_type to compute id_all layout
* perf sets the same sample type to all events as of now * perf sets the same sample type to all events as of now
*/ */
first = perf_evlist__first(session->evlist); first = evlist__first(session->evlist);
jd.sample_type = first->core.attr.sample_type; jd.sample_type = first->core.attr.sample_type;
*nbytes = 0; *nbytes = 0;
......
...@@ -1936,7 +1936,7 @@ int parse_events(struct evlist *evlist, const char *str, ...@@ -1936,7 +1936,7 @@ int parse_events(struct evlist *evlist, const char *str,
perf_evlist__splice_list_tail(evlist, &parse_state.list); perf_evlist__splice_list_tail(evlist, &parse_state.list);
evlist->nr_groups += parse_state.nr_groups; evlist->nr_groups += parse_state.nr_groups;
last = perf_evlist__last(evlist); last = evlist__last(evlist);
last->cmdline_group_boundary = true; last->cmdline_group_boundary = true;
return 0; return 0;
...@@ -2050,7 +2050,7 @@ foreach_evsel_in_last_glob(struct evlist *evlist, ...@@ -2050,7 +2050,7 @@ foreach_evsel_in_last_glob(struct evlist *evlist,
* So no need to WARN here, let *func do this. * So no need to WARN here, let *func do this.
*/ */
if (evlist->core.nr_entries > 0) if (evlist->core.nr_entries > 0)
last = perf_evlist__last(evlist); last = evlist__last(evlist);
do { do {
err = (*func)(last, arg); err = (*func)(last, arg);
......
...@@ -30,7 +30,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str) ...@@ -30,7 +30,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
if (parse_events(evlist, str, NULL)) if (parse_events(evlist, str, NULL))
goto out_delete; goto out_delete;
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
while (1) { while (1) {
fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags); fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags);
...@@ -171,7 +171,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts, ...@@ -171,7 +171,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
use_sample_identifier = perf_can_sample_identifier(); use_sample_identifier = perf_can_sample_identifier();
sample_id = true; sample_id = true;
} else if (evlist->core.nr_entries > 1) { } else if (evlist->core.nr_entries > 1) {
struct evsel *first = perf_evlist__first(evlist); struct evsel *first = evlist__first(evlist);
evlist__for_each_entry(evlist, evsel) { evlist__for_each_entry(evlist, evsel) {
if (evsel->core.attr.sample_type == first->core.attr.sample_type) if (evsel->core.attr.sample_type == first->core.attr.sample_type)
...@@ -276,7 +276,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) ...@@ -276,7 +276,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str)
if (err) if (err)
goto out_delete; goto out_delete;
evsel = perf_evlist__last(temp_evlist); evsel = evlist__last(temp_evlist);
if (!evlist || perf_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); struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
......
...@@ -2329,7 +2329,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name) ...@@ -2329,7 +2329,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name)
if (nr > evlist->core.nr_entries) if (nr > evlist->core.nr_entries)
return NULL; return NULL;
evsel = perf_evlist__first(evlist); evsel = evlist__first(evlist);
while (--nr > 0) while (--nr > 0)
evsel = perf_evsel__next(evsel); evsel = perf_evsel__next(evsel);
......
...@@ -71,7 +71,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) ...@@ -71,7 +71,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
} }
if (top->evlist->core.nr_entries == 1) { if (top->evlist->core.nr_entries == 1) {
struct evsel *first = perf_evlist__first(top->evlist); struct evsel *first = evlist__first(top->evlist);
ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ", ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
(uint64_t)first->core.attr.sample_period, (uint64_t)first->core.attr.sample_period,
opts->freq ? "Hz" : ""); opts->freq ? "Hz" : "");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment