aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2014-01-10 08:37:27 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-01-13 08:06:25 -0500
commit0050f7aa182e3e8ed34dd6cc4318e52b3df6347a (patch)
tree472540f557462f51a73b7cd44c27792edd48e4d8 /tools/perf
parentf6d8b0571c9ac8f273d18c112c2fc3c9533c9f0a (diff)
perf evlist: Introduce evlist__for_each() & friends
For the common evsel list traversal, so that it becomes more compact. Use the opportunity to start ditching the 'perf_' from 'perf_evlist__', as discussed, as the whole conversion touches a lot of places, lets do it piecemeal when we have the chance due to other work, like in this case. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-qnkx7dzm2h6m6uptkfk03ni6@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-diff.c7
-rw-r--r--tools/perf/builtin-evlist.c2
-rw-r--r--tools/perf/builtin-inject.c2
-rw-r--r--tools/perf/builtin-kvm.c2
-rw-r--r--tools/perf/builtin-record.c2
-rw-r--r--tools/perf/builtin-report.c8
-rw-r--r--tools/perf/builtin-script.c5
-rw-r--r--tools/perf/builtin-stat.c32
-rw-r--r--tools/perf/builtin-top.c8
-rw-r--r--tools/perf/tests/evsel-roundtrip-name.c2
-rw-r--r--tools/perf/tests/hists_link.c4
-rw-r--r--tools/perf/tests/mmap-basic.c2
-rw-r--r--tools/perf/tests/parse-events.c4
-rw-r--r--tools/perf/ui/browsers/hists.c5
-rw-r--r--tools/perf/ui/gtk/hists.c2
-rw-r--r--tools/perf/util/cgroup.c4
-rw-r--r--tools/perf/util/evlist.c40
-rw-r--r--tools/perf/util/evlist.h65
-rw-r--r--tools/perf/util/header.c19
-rw-r--r--tools/perf/util/parse-events.c5
-rw-r--r--tools/perf/util/python.c3
-rw-r--r--tools/perf/util/record.c6
-rw-r--r--tools/perf/util/session.c6
24 files changed, 151 insertions, 86 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index ab65057a0317..0da603b79b61 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -232,7 +232,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
232 perf_session__fprintf_dsos(session, stdout); 232 perf_session__fprintf_dsos(session, stdout);
233 233
234 total_nr_samples = 0; 234 total_nr_samples = 0;
235 list_for_each_entry(pos, &session->evlist->entries, node) { 235 evlist__for_each(session->evlist, pos) {
236 struct hists *hists = &pos->hists; 236 struct hists *hists = &pos->hists;
237 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; 237 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
238 238
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index e6a0844bc2f0..987cac3b4bba 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -356,9 +356,10 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
356{ 356{
357 struct perf_evsel *e; 357 struct perf_evsel *e;
358 358
359 list_for_each_entry(e, &evlist->entries, node) 359 evlist__for_each(evlist, e) {
360 if (perf_evsel__match2(evsel, e)) 360 if (perf_evsel__match2(evsel, e))
361 return e; 361 return e;
362 }
362 363
363 return NULL; 364 return NULL;
364} 365}
@@ -367,7 +368,7 @@ static void perf_evlist__collapse_resort(struct perf_evlist *evlist)
367{ 368{
368 struct perf_evsel *evsel; 369 struct perf_evsel *evsel;
369 370
370 list_for_each_entry(evsel, &evlist->entries, node) { 371 evlist__for_each(evlist, evsel) {
371 struct hists *hists = &evsel->hists; 372 struct hists *hists = &evsel->hists;
372 373
373 hists__collapse_resort(hists, NULL); 374 hists__collapse_resort(hists, NULL);
@@ -614,7 +615,7 @@ static void data_process(void)
614 struct perf_evsel *evsel_base; 615 struct perf_evsel *evsel_base;
615 bool first = true; 616 bool first = true;
616 617
617 list_for_each_entry(evsel_base, &evlist_base->entries, node) { 618 evlist__for_each(evlist_base, evsel_base) {
618 struct data__file *d; 619 struct data__file *d;
619 int i; 620 int i;
620 621
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 20b0f12763b0..c99e0de7e54a 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -29,7 +29,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
29 if (session == NULL) 29 if (session == NULL)
30 return -ENOMEM; 30 return -ENOMEM;
31 31
32 list_for_each_entry(pos, &session->evlist->entries, node) 32 evlist__for_each(session->evlist, pos)
33 perf_evsel__fprintf(pos, details, stdout); 33 perf_evsel__fprintf(pos, details, stdout);
34 34
35 perf_session__delete(session); 35 perf_session__delete(session);
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index c9f6d74e1fd7..b3466018bbd7 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -369,7 +369,7 @@ static int __cmd_inject(struct perf_inject *inject)
369 369
370 inject->tool.ordered_samples = true; 370 inject->tool.ordered_samples = true;
371 371
372 list_for_each_entry(evsel, &session->evlist->entries, node) { 372 evlist__for_each(session->evlist, evsel) {
373 const char *name = perf_evsel__name(evsel); 373 const char *name = perf_evsel__name(evsel);
374 374
375 if (!strcmp(name, "sched:sched_switch")) { 375 if (!strcmp(name, "sched:sched_switch")) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 858b11bf6711..a7350519c63f 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1174,7 +1174,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
1174 * Note: exclude_{guest,host} do not apply here. 1174 * Note: exclude_{guest,host} do not apply here.
1175 * This command processes KVM tracepoints from host only 1175 * This command processes KVM tracepoints from host only
1176 */ 1176 */
1177 list_for_each_entry(pos, &evlist->entries, node) { 1177 evlist__for_each(evlist, pos) {
1178 struct perf_event_attr *attr = &pos->attr; 1178 struct perf_event_attr *attr = &pos->attr;
1179 1179
1180 /* make sure these *are* set */ 1180 /* make sure these *are* set */
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cb00b53c200f..88600158400e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -183,7 +183,7 @@ static int record__open(struct record *rec)
183 183
184 perf_evlist__config(evlist, opts); 184 perf_evlist__config(evlist, opts);
185 185
186 list_for_each_entry(pos, &evlist->entries, node) { 186 evlist__for_each(evlist, pos) {
187try_again: 187try_again:
188 if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) { 188 if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
189 if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) { 189 if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) {
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index cff9465847f2..46864dd7eb83 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -384,7 +384,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
384{ 384{
385 struct perf_evsel *pos; 385 struct perf_evsel *pos;
386 386
387 list_for_each_entry(pos, &evlist->entries, node) { 387 evlist__for_each(evlist, pos) {
388 struct hists *hists = &pos->hists; 388 struct hists *hists = &pos->hists;
389 const char *evname = perf_evsel__name(pos); 389 const char *evname = perf_evsel__name(pos);
390 390
@@ -495,7 +495,7 @@ static u64 report__collapse_hists(struct report *rep)
495 * Count number of histogram entries to use when showing progress, 495 * Count number of histogram entries to use when showing progress,
496 * reusing nr_samples variable. 496 * reusing nr_samples variable.
497 */ 497 */
498 list_for_each_entry(pos, &rep->session->evlist->entries, node) 498 evlist__for_each(rep->session->evlist, pos)
499 nr_samples += pos->hists.nr_entries; 499 nr_samples += pos->hists.nr_entries;
500 500
501 ui_progress__init(&prog, nr_samples, "Merging related events..."); 501 ui_progress__init(&prog, nr_samples, "Merging related events...");
@@ -505,7 +505,7 @@ static u64 report__collapse_hists(struct report *rep)
505 */ 505 */
506 nr_samples = 0; 506 nr_samples = 0;
507 507
508 list_for_each_entry(pos, &rep->session->evlist->entries, node) { 508 evlist__for_each(rep->session->evlist, pos) {
509 struct hists *hists = &pos->hists; 509 struct hists *hists = &pos->hists;
510 510
511 if (pos->idx == 0) 511 if (pos->idx == 0)
@@ -582,7 +582,7 @@ static int __cmd_report(struct report *rep)
582 return 0; 582 return 0;
583 } 583 }
584 584
585 list_for_each_entry(pos, &session->evlist->entries, node) 585 evlist__for_each(session->evlist, pos)
586 hists__output_resort(&pos->hists); 586 hists__output_resort(&pos->hists);
587 587
588 return report__browse_hists(rep); 588 return report__browse_hists(rep);
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6040000bdfa6..9e9c91f5b7fa 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -603,7 +603,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
603 if (evsel->attr.type >= PERF_TYPE_MAX) 603 if (evsel->attr.type >= PERF_TYPE_MAX)
604 return 0; 604 return 0;
605 605
606 list_for_each_entry(pos, &evlist->entries, node) { 606 evlist__for_each(evlist, pos) {
607 if (pos->attr.type == evsel->attr.type && pos != evsel) 607 if (pos->attr.type == evsel->attr.type && pos != evsel)
608 return 0; 608 return 0;
609 } 609 }
@@ -1309,8 +1309,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
1309 snprintf(evname, len + 1, "%s", p); 1309 snprintf(evname, len + 1, "%s", p);
1310 1310
1311 match = 0; 1311 match = 0;
1312 list_for_each_entry(pos, 1312 evlist__for_each(session->evlist, pos) {
1313 &session->evlist->entries, node) {
1314 if (!strcmp(perf_evsel__name(pos), evname)) { 1313 if (!strcmp(perf_evsel__name(pos), evname)) {
1315 match = 1; 1314 match = 1;
1316 break; 1315 break;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b27b2645eb3c..8b0e1c9234d9 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -214,7 +214,7 @@ static void perf_evlist__free_stats(struct perf_evlist *evlist)
214{ 214{
215 struct perf_evsel *evsel; 215 struct perf_evsel *evsel;
216 216
217 list_for_each_entry(evsel, &evlist->entries, node) { 217 evlist__for_each(evlist, evsel) {
218 perf_evsel__free_stat_priv(evsel); 218 perf_evsel__free_stat_priv(evsel);
219 perf_evsel__free_counts(evsel); 219 perf_evsel__free_counts(evsel);
220 perf_evsel__free_prev_raw_counts(evsel); 220 perf_evsel__free_prev_raw_counts(evsel);
@@ -225,7 +225,7 @@ static int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw)
225{ 225{
226 struct perf_evsel *evsel; 226 struct perf_evsel *evsel;
227 227
228 list_for_each_entry(evsel, &evlist->entries, node) { 228 evlist__for_each(evlist, evsel) {
229 if (perf_evsel__alloc_stat_priv(evsel) < 0 || 229 if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
230 perf_evsel__alloc_counts(evsel, perf_evsel__nr_cpus(evsel)) < 0 || 230 perf_evsel__alloc_counts(evsel, perf_evsel__nr_cpus(evsel)) < 0 ||
231 (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel) < 0)) 231 (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel) < 0))
@@ -259,7 +259,7 @@ static void perf_stat__reset_stats(struct perf_evlist *evlist)
259{ 259{
260 struct perf_evsel *evsel; 260 struct perf_evsel *evsel;
261 261
262 list_for_each_entry(evsel, &evlist->entries, node) { 262 evlist__for_each(evlist, evsel) {
263 perf_evsel__reset_stat_priv(evsel); 263 perf_evsel__reset_stat_priv(evsel);
264 perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel)); 264 perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel));
265 } 265 }
@@ -326,13 +326,13 @@ static struct perf_evsel *nth_evsel(int n)
326 326
327 /* Assumes this only called when evsel_list does not change anymore. */ 327 /* Assumes this only called when evsel_list does not change anymore. */
328 if (!array) { 328 if (!array) {
329 list_for_each_entry(ev, &evsel_list->entries, node) 329 evlist__for_each(evsel_list, ev)
330 array_len++; 330 array_len++;
331 array = malloc(array_len * sizeof(void *)); 331 array = malloc(array_len * sizeof(void *));
332 if (!array) 332 if (!array)
333 exit(ENOMEM); 333 exit(ENOMEM);
334 j = 0; 334 j = 0;
335 list_for_each_entry(ev, &evsel_list->entries, node) 335 evlist__for_each(evsel_list, ev)
336 array[j++] = ev; 336 array[j++] = ev;
337 } 337 }
338 if (n < array_len) 338 if (n < array_len)
@@ -440,13 +440,13 @@ static void print_interval(void)
440 char prefix[64]; 440 char prefix[64];
441 441
442 if (aggr_mode == AGGR_GLOBAL) { 442 if (aggr_mode == AGGR_GLOBAL) {
443 list_for_each_entry(counter, &evsel_list->entries, node) { 443 evlist__for_each(evsel_list, counter) {
444 ps = counter->priv; 444 ps = counter->priv;
445 memset(ps->res_stats, 0, sizeof(ps->res_stats)); 445 memset(ps->res_stats, 0, sizeof(ps->res_stats));
446 read_counter_aggr(counter); 446 read_counter_aggr(counter);
447 } 447 }
448 } else { 448 } else {
449 list_for_each_entry(counter, &evsel_list->entries, node) { 449 evlist__for_each(evsel_list, counter) {
450 ps = counter->priv; 450 ps = counter->priv;
451 memset(ps->res_stats, 0, sizeof(ps->res_stats)); 451 memset(ps->res_stats, 0, sizeof(ps->res_stats));
452 read_counter(counter); 452 read_counter(counter);
@@ -483,12 +483,12 @@ static void print_interval(void)
483 print_aggr(prefix); 483 print_aggr(prefix);
484 break; 484 break;
485 case AGGR_NONE: 485 case AGGR_NONE:
486 list_for_each_entry(counter, &evsel_list->entries, node) 486 evlist__for_each(evsel_list, counter)
487 print_counter(counter, prefix); 487 print_counter(counter, prefix);
488 break; 488 break;
489 case AGGR_GLOBAL: 489 case AGGR_GLOBAL:
490 default: 490 default:
491 list_for_each_entry(counter, &evsel_list->entries, node) 491 evlist__for_each(evsel_list, counter)
492 print_counter_aggr(counter, prefix); 492 print_counter_aggr(counter, prefix);
493 } 493 }
494 494
@@ -504,7 +504,7 @@ static void handle_initial_delay(void)
504 nthreads = thread_map__nr(evsel_list->threads); 504 nthreads = thread_map__nr(evsel_list->threads);
505 505
506 usleep(initial_delay * 1000); 506 usleep(initial_delay * 1000);
507 list_for_each_entry(counter, &evsel_list->entries, node) 507 evlist__for_each(evsel_list, counter)
508 perf_evsel__enable(counter, ncpus, nthreads); 508 perf_evsel__enable(counter, ncpus, nthreads);
509 } 509 }
510} 510}
@@ -552,7 +552,7 @@ static int __run_perf_stat(int argc, const char **argv)
552 if (group) 552 if (group)
553 perf_evlist__set_leader(evsel_list); 553 perf_evlist__set_leader(evsel_list);
554 554
555 list_for_each_entry(counter, &evsel_list->entries, node) { 555 evlist__for_each(evsel_list, counter) {
556 if (create_perf_stat_counter(counter) < 0) { 556 if (create_perf_stat_counter(counter) < 0) {
557 /* 557 /*
558 * PPC returns ENXIO for HW counters until 2.6.37 558 * PPC returns ENXIO for HW counters until 2.6.37
@@ -630,13 +630,13 @@ static int __run_perf_stat(int argc, const char **argv)
630 update_stats(&walltime_nsecs_stats, t1 - t0); 630 update_stats(&walltime_nsecs_stats, t1 - t0);
631 631
632 if (aggr_mode == AGGR_GLOBAL) { 632 if (aggr_mode == AGGR_GLOBAL) {
633 list_for_each_entry(counter, &evsel_list->entries, node) { 633 evlist__for_each(evsel_list, counter) {
634 read_counter_aggr(counter); 634 read_counter_aggr(counter);
635 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), 635 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter),
636 thread_map__nr(evsel_list->threads)); 636 thread_map__nr(evsel_list->threads));
637 } 637 }
638 } else { 638 } else {
639 list_for_each_entry(counter, &evsel_list->entries, node) { 639 evlist__for_each(evsel_list, counter) {
640 read_counter(counter); 640 read_counter(counter);
641 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), 1); 641 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), 1);
642 } 642 }
@@ -1117,7 +1117,7 @@ static void print_aggr(char *prefix)
1117 1117
1118 for (s = 0; s < aggr_map->nr; s++) { 1118 for (s = 0; s < aggr_map->nr; s++) {
1119 id = aggr_map->map[s]; 1119 id = aggr_map->map[s];
1120 list_for_each_entry(counter, &evsel_list->entries, node) { 1120 evlist__for_each(evsel_list, counter) {
1121 val = ena = run = 0; 1121 val = ena = run = 0;
1122 nr = 0; 1122 nr = 0;
1123 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { 1123 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
@@ -1328,11 +1328,11 @@ static void print_stat(int argc, const char **argv)
1328 print_aggr(NULL); 1328 print_aggr(NULL);
1329 break; 1329 break;
1330 case AGGR_GLOBAL: 1330 case AGGR_GLOBAL:
1331 list_for_each_entry(counter, &evsel_list->entries, node) 1331 evlist__for_each(evsel_list, counter)
1332 print_counter_aggr(counter, NULL); 1332 print_counter_aggr(counter, NULL);
1333 break; 1333 break;
1334 case AGGR_NONE: 1334 case AGGR_NONE:
1335 list_for_each_entry(counter, &evsel_list->entries, node) 1335 evlist__for_each(evsel_list, counter)
1336 print_counter(counter, NULL); 1336 print_counter(counter, NULL);
1337 break; 1337 break;
1338 default: 1338 default:
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index e0fd0aa57f06..569dd87690ef 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -482,7 +482,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
482 482
483 fprintf(stderr, "\nAvailable events:"); 483 fprintf(stderr, "\nAvailable events:");
484 484
485 list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) 485 evlist__for_each(top->evlist, top->sym_evsel)
486 fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel)); 486 fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel));
487 487
488 prompt_integer(&counter, "Enter details event counter"); 488 prompt_integer(&counter, "Enter details event counter");
@@ -493,7 +493,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
493 sleep(1); 493 sleep(1);
494 break; 494 break;
495 } 495 }
496 list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) 496 evlist__for_each(top->evlist, top->sym_evsel)
497 if (top->sym_evsel->idx == counter) 497 if (top->sym_evsel->idx == counter)
498 break; 498 break;
499 } else 499 } else
@@ -575,7 +575,7 @@ static void *display_thread_tui(void *arg)
575 * Zooming in/out UIDs. For now juse use whatever the user passed 575 * Zooming in/out UIDs. For now juse use whatever the user passed
576 * via --uid. 576 * via --uid.
577 */ 577 */
578 list_for_each_entry(pos, &top->evlist->entries, node) 578 evlist__for_each(top->evlist, pos)
579 pos->hists.uid_filter_str = top->record_opts.target.uid_str; 579 pos->hists.uid_filter_str = top->record_opts.target.uid_str;
580 580
581 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent, 581 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent,
@@ -858,7 +858,7 @@ static int perf_top__start_counters(struct perf_top *top)
858 858
859 perf_evlist__config(evlist, opts); 859 perf_evlist__config(evlist, opts);
860 860
861 list_for_each_entry(counter, &evlist->entries, node) { 861 evlist__for_each(evlist, counter) {
862try_again: 862try_again:
863 if (perf_evsel__open(counter, top->evlist->cpus, 863 if (perf_evsel__open(counter, top->evlist->cpus,
864 top->evlist->threads) < 0) { 864 top->evlist->threads) < 0) {
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c
index 0197bda9c461..465cdbc345cf 100644
--- a/tools/perf/tests/evsel-roundtrip-name.c
+++ b/tools/perf/tests/evsel-roundtrip-name.c
@@ -79,7 +79,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)
79 } 79 }
80 80
81 err = 0; 81 err = 0;
82 list_for_each_entry(evsel, &evlist->entries, node) { 82 evlist__for_each(evlist, evsel) {
83 if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) { 83 if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
84 --err; 84 --err;
85 pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]); 85 pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 173bf42cc03e..2b6519e0e36f 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -208,7 +208,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
208 * However the second evsel also has a collapsed entry for 208 * However the second evsel also has a collapsed entry for
209 * "bash [libc] malloc" so total 9 entries will be in the tree. 209 * "bash [libc] malloc" so total 9 entries will be in the tree.
210 */ 210 */
211 list_for_each_entry(evsel, &evlist->entries, node) { 211 evlist__for_each(evlist, evsel) {
212 for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) { 212 for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) {
213 const union perf_event event = { 213 const union perf_event event = {
214 .header = { 214 .header = {
@@ -466,7 +466,7 @@ int test__hists_link(void)
466 if (err < 0) 466 if (err < 0)
467 goto out; 467 goto out;
468 468
469 list_for_each_entry(evsel, &evlist->entries, node) { 469 evlist__for_each(evlist, evsel) {
470 hists__collapse_resort(&evsel->hists, NULL); 470 hists__collapse_resort(&evsel->hists, NULL);
471 471
472 if (verbose > 2) 472 if (verbose > 2)
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index aef25f0ff9cc..142263492f6f 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -126,7 +126,7 @@ int test__basic_mmap(void)
126 } 126 }
127 127
128 err = 0; 128 err = 0;
129 list_for_each_entry(evsel, &evlist->entries, node) { 129 evlist__for_each(evlist, evsel) {
130 if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) { 130 if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) {
131 pr_debug("expected %d %s events, got %d\n", 131 pr_debug("expected %d %s events, got %d\n",
132 expected_nr_events[evsel->idx], 132 expected_nr_events[evsel->idx],
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 41dee5e67f63..4db0ae617d70 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -30,7 +30,7 @@ static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
30 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); 30 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
31 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); 31 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
32 32
33 list_for_each_entry(evsel, &evlist->entries, node) { 33 evlist__for_each(evlist, evsel) {
34 TEST_ASSERT_VAL("wrong type", 34 TEST_ASSERT_VAL("wrong type",
35 PERF_TYPE_TRACEPOINT == evsel->attr.type); 35 PERF_TYPE_TRACEPOINT == evsel->attr.type);
36 TEST_ASSERT_VAL("wrong sample_type", 36 TEST_ASSERT_VAL("wrong sample_type",
@@ -201,7 +201,7 @@ test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
201 201
202 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); 202 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
203 203
204 list_for_each_entry(evsel, &evlist->entries, node) { 204 evlist__for_each(evlist, evsel) {
205 TEST_ASSERT_VAL("wrong exclude_user", 205 TEST_ASSERT_VAL("wrong exclude_user",
206 !evsel->attr.exclude_user); 206 !evsel->attr.exclude_user);
207 TEST_ASSERT_VAL("wrong exclude_kernel", 207 TEST_ASSERT_VAL("wrong exclude_kernel",
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a7045ea6d1d5..b720b92eba6e 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1938,7 +1938,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
1938 1938
1939 ui_helpline__push("Press ESC to exit"); 1939 ui_helpline__push("Press ESC to exit");
1940 1940
1941 list_for_each_entry(pos, &evlist->entries, node) { 1941 evlist__for_each(evlist, pos) {
1942 const char *ev_name = perf_evsel__name(pos); 1942 const char *ev_name = perf_evsel__name(pos);
1943 size_t line_len = strlen(ev_name) + 7; 1943 size_t line_len = strlen(ev_name) + 7;
1944 1944
@@ -1970,9 +1970,10 @@ single_entry:
1970 struct perf_evsel *pos; 1970 struct perf_evsel *pos;
1971 1971
1972 nr_entries = 0; 1972 nr_entries = 0;
1973 list_for_each_entry(pos, &evlist->entries, node) 1973 evlist__for_each(evlist, pos) {
1974 if (perf_evsel__is_group_leader(pos)) 1974 if (perf_evsel__is_group_leader(pos))
1975 nr_entries++; 1975 nr_entries++;
1976 }
1976 1977
1977 if (nr_entries == 1) 1978 if (nr_entries == 1)
1978 goto single_entry; 1979 goto single_entry;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 2ca66cc1160f..5b95c44f3435 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -375,7 +375,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
375 375
376 gtk_container_add(GTK_CONTAINER(window), vbox); 376 gtk_container_add(GTK_CONTAINER(window), vbox);
377 377
378 list_for_each_entry(pos, &evlist->entries, node) { 378 evlist__for_each(evlist, pos) {
379 struct hists *hists = &pos->hists; 379 struct hists *hists = &pos->hists;
380 const char *evname = perf_evsel__name(pos); 380 const char *evname = perf_evsel__name(pos);
381 GtkWidget *scrolled_window; 381 GtkWidget *scrolled_window;
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 0922aa4218c2..88f7be399432 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -81,7 +81,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
81 /* 81 /*
82 * check if cgrp is already defined, if so we reuse it 82 * check if cgrp is already defined, if so we reuse it
83 */ 83 */
84 list_for_each_entry(counter, &evlist->entries, node) { 84 evlist__for_each(evlist, counter) {
85 cgrp = counter->cgrp; 85 cgrp = counter->cgrp;
86 if (!cgrp) 86 if (!cgrp)
87 continue; 87 continue;
@@ -110,7 +110,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
110 * if add cgroup N, then need to find event N 110 * if add cgroup N, then need to find event N
111 */ 111 */
112 n = 0; 112 n = 0;
113 list_for_each_entry(counter, &evlist->entries, node) { 113 evlist__for_each(evlist, counter) {
114 if (n == nr_cgroups) 114 if (n == nr_cgroups)
115 goto found; 115 goto found;
116 n++; 116 n++;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0810f5ca77d7..40bd2c04df8a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -81,7 +81,7 @@ static void perf_evlist__update_id_pos(struct perf_evlist *evlist)
81{ 81{
82 struct perf_evsel *evsel; 82 struct perf_evsel *evsel;
83 83
84 list_for_each_entry(evsel, &evlist->entries, node) 84 evlist__for_each(evlist, evsel)
85 perf_evsel__calc_id_pos(evsel); 85 perf_evsel__calc_id_pos(evsel);
86 86
87 perf_evlist__set_id_pos(evlist); 87 perf_evlist__set_id_pos(evlist);
@@ -91,7 +91,7 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
91{ 91{
92 struct perf_evsel *pos, *n; 92 struct perf_evsel *pos, *n;
93 93
94 list_for_each_entry_safe(pos, n, &evlist->entries, node) { 94 evlist__for_each_safe(evlist, n, pos) {
95 list_del_init(&pos->node); 95 list_del_init(&pos->node);
96 perf_evsel__delete(pos); 96 perf_evsel__delete(pos);
97 } 97 }
@@ -148,7 +148,7 @@ void __perf_evlist__set_leader(struct list_head *list)
148 148
149 leader->nr_members = evsel->idx - leader->idx + 1; 149 leader->nr_members = evsel->idx - leader->idx + 1;
150 150
151 list_for_each_entry(evsel, list, node) { 151 __evlist__for_each(list, evsel) {
152 evsel->leader = leader; 152 evsel->leader = leader;
153 } 153 }
154} 154}
@@ -207,7 +207,7 @@ static int perf_evlist__add_attrs(struct perf_evlist *evlist,
207 return 0; 207 return 0;
208 208
209out_delete_partial_list: 209out_delete_partial_list:
210 list_for_each_entry_safe(evsel, n, &head, node) 210 __evlist__for_each_safe(&head, n, evsel)
211 perf_evsel__delete(evsel); 211 perf_evsel__delete(evsel);
212 return -1; 212 return -1;
213} 213}
@@ -228,7 +228,7 @@ perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id)
228{ 228{
229 struct perf_evsel *evsel; 229 struct perf_evsel *evsel;
230 230
231 list_for_each_entry(evsel, &evlist->entries, node) { 231 evlist__for_each(evlist, evsel) {
232 if (evsel->attr.type == PERF_TYPE_TRACEPOINT && 232 if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
233 (int)evsel->attr.config == id) 233 (int)evsel->attr.config == id)
234 return evsel; 234 return evsel;
@@ -243,7 +243,7 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
243{ 243{
244 struct perf_evsel *evsel; 244 struct perf_evsel *evsel;
245 245
246 list_for_each_entry(evsel, &evlist->entries, node) { 246 evlist__for_each(evlist, evsel) {
247 if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) && 247 if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
248 (strcmp(evsel->name, name) == 0)) 248 (strcmp(evsel->name, name) == 0))
249 return evsel; 249 return evsel;
@@ -273,7 +273,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
273 int nr_threads = thread_map__nr(evlist->threads); 273 int nr_threads = thread_map__nr(evlist->threads);
274 274
275 for (cpu = 0; cpu < nr_cpus; cpu++) { 275 for (cpu = 0; cpu < nr_cpus; cpu++) {
276 list_for_each_entry(pos, &evlist->entries, node) { 276 evlist__for_each(evlist, pos) {
277 if (!perf_evsel__is_group_leader(pos) || !pos->fd) 277 if (!perf_evsel__is_group_leader(pos) || !pos->fd)
278 continue; 278 continue;
279 for (thread = 0; thread < nr_threads; thread++) 279 for (thread = 0; thread < nr_threads; thread++)
@@ -291,7 +291,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
291 int nr_threads = thread_map__nr(evlist->threads); 291 int nr_threads = thread_map__nr(evlist->threads);
292 292
293 for (cpu = 0; cpu < nr_cpus; cpu++) { 293 for (cpu = 0; cpu < nr_cpus; cpu++) {
294 list_for_each_entry(pos, &evlist->entries, node) { 294 evlist__for_each(evlist, pos) {
295 if (!perf_evsel__is_group_leader(pos) || !pos->fd) 295 if (!perf_evsel__is_group_leader(pos) || !pos->fd)
296 continue; 296 continue;
297 for (thread = 0; thread < nr_threads; thread++) 297 for (thread = 0; thread < nr_threads; thread++)
@@ -630,7 +630,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
630{ 630{
631 struct perf_evsel *evsel; 631 struct perf_evsel *evsel;
632 632
633 list_for_each_entry(evsel, &evlist->entries, node) { 633 evlist__for_each(evlist, evsel) {
634 int fd = FD(evsel, cpu, thread); 634 int fd = FD(evsel, cpu, thread);
635 635
636 if (*output == -1) { 636 if (*output == -1) {
@@ -806,7 +806,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
806 pr_debug("mmap size %zuB\n", evlist->mmap_len); 806 pr_debug("mmap size %zuB\n", evlist->mmap_len);
807 mask = evlist->mmap_len - page_size - 1; 807 mask = evlist->mmap_len - page_size - 1;
808 808
809 list_for_each_entry(evsel, &evlist->entries, node) { 809 evlist__for_each(evlist, evsel) {
810 if ((evsel->attr.read_format & PERF_FORMAT_ID) && 810 if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
811 evsel->sample_id == NULL && 811 evsel->sample_id == NULL &&
812 perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0) 812 perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
@@ -849,7 +849,7 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist)
849 const int ncpus = cpu_map__nr(evlist->cpus), 849 const int ncpus = cpu_map__nr(evlist->cpus),
850 nthreads = thread_map__nr(evlist->threads); 850 nthreads = thread_map__nr(evlist->threads);
851 851
852 list_for_each_entry(evsel, &evlist->entries, node) { 852 evlist__for_each(evlist, evsel) {
853 if (evsel->filter == NULL) 853 if (evsel->filter == NULL)
854 continue; 854 continue;
855 855
@@ -868,7 +868,7 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
868 const int ncpus = cpu_map__nr(evlist->cpus), 868 const int ncpus = cpu_map__nr(evlist->cpus),
869 nthreads = thread_map__nr(evlist->threads); 869 nthreads = thread_map__nr(evlist->threads);
870 870
871 list_for_each_entry(evsel, &evlist->entries, node) { 871 evlist__for_each(evlist, evsel) {
872 err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter); 872 err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter);
873 if (err) 873 if (err)
874 break; 874 break;
@@ -887,7 +887,7 @@ bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
887 if (evlist->id_pos < 0 || evlist->is_pos < 0) 887 if (evlist->id_pos < 0 || evlist->is_pos < 0)
888 return false; 888 return false;
889 889
890 list_for_each_entry(pos, &evlist->entries, node) { 890 evlist__for_each(evlist, pos) {
891 if (pos->id_pos != evlist->id_pos || 891 if (pos->id_pos != evlist->id_pos ||
892 pos->is_pos != evlist->is_pos) 892 pos->is_pos != evlist->is_pos)
893 return false; 893 return false;
@@ -903,7 +903,7 @@ u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist)
903 if (evlist->combined_sample_type) 903 if (evlist->combined_sample_type)
904 return evlist->combined_sample_type; 904 return evlist->combined_sample_type;
905 905
906 list_for_each_entry(evsel, &evlist->entries, node) 906 evlist__for_each(evlist, evsel)
907 evlist->combined_sample_type |= evsel->attr.sample_type; 907 evlist->combined_sample_type |= evsel->attr.sample_type;
908 908
909 return evlist->combined_sample_type; 909 return evlist->combined_sample_type;
@@ -921,7 +921,7 @@ bool perf_evlist__valid_read_format(struct perf_evlist *evlist)
921 u64 read_format = first->attr.read_format; 921 u64 read_format = first->attr.read_format;
922 u64 sample_type = first->attr.sample_type; 922 u64 sample_type = first->attr.sample_type;
923 923
924 list_for_each_entry_continue(pos, &evlist->entries, node) { 924 evlist__for_each(evlist, pos) {
925 if (read_format != pos->attr.read_format) 925 if (read_format != pos->attr.read_format)
926 return false; 926 return false;
927 } 927 }
@@ -978,7 +978,7 @@ bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist)
978{ 978{
979 struct perf_evsel *first = perf_evlist__first(evlist), *pos = first; 979 struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
980 980
981 list_for_each_entry_continue(pos, &evlist->entries, node) { 981 evlist__for_each_continue(evlist, pos) {
982 if (first->attr.sample_id_all != pos->attr.sample_id_all) 982 if (first->attr.sample_id_all != pos->attr.sample_id_all)
983 return false; 983 return false;
984 } 984 }
@@ -1004,7 +1004,7 @@ void perf_evlist__close(struct perf_evlist *evlist)
1004 int ncpus = cpu_map__nr(evlist->cpus); 1004 int ncpus = cpu_map__nr(evlist->cpus);
1005 int nthreads = thread_map__nr(evlist->threads); 1005 int nthreads = thread_map__nr(evlist->threads);
1006 1006
1007 list_for_each_entry_reverse(evsel, &evlist->entries, node) 1007 evlist__for_each_reverse(evlist, evsel)
1008 perf_evsel__close(evsel, ncpus, nthreads); 1008 perf_evsel__close(evsel, ncpus, nthreads);
1009} 1009}
1010 1010
@@ -1015,7 +1015,7 @@ int perf_evlist__open(struct perf_evlist *evlist)
1015 1015
1016 perf_evlist__update_id_pos(evlist); 1016 perf_evlist__update_id_pos(evlist);
1017 1017
1018 list_for_each_entry(evsel, &evlist->entries, node) { 1018 evlist__for_each(evlist, evsel) {
1019 err = perf_evsel__open(evsel, evlist->cpus, evlist->threads); 1019 err = perf_evsel__open(evsel, evlist->cpus, evlist->threads);
1020 if (err < 0) 1020 if (err < 0)
1021 goto out_err; 1021 goto out_err;
@@ -1154,7 +1154,7 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
1154 struct perf_evsel *evsel; 1154 struct perf_evsel *evsel;
1155 size_t printed = 0; 1155 size_t printed = 0;
1156 1156
1157 list_for_each_entry(evsel, &evlist->entries, node) { 1157 evlist__for_each(evlist, evsel) {
1158 printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "", 1158 printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "",
1159 perf_evsel__name(evsel)); 1159 perf_evsel__name(evsel));
1160 } 1160 }
@@ -1233,7 +1233,7 @@ void perf_evlist__to_front(struct perf_evlist *evlist,
1233 if (move_evsel == perf_evlist__first(evlist)) 1233 if (move_evsel == perf_evlist__first(evlist))
1234 return; 1234 return;
1235 1235
1236 list_for_each_entry_safe(evsel, n, &evlist->entries, node) { 1236 evlist__for_each_safe(evlist, n, evsel) {
1237 if (evsel->leader == move_evsel->leader) 1237 if (evsel->leader == move_evsel->leader)
1238 list_move_tail(&evsel->node, &move); 1238 list_move_tail(&evsel->node, &move);
1239 } 1239 }
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 518e521c801d..f5173cd63693 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -196,5 +196,70 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
196void perf_evlist__to_front(struct perf_evlist *evlist, 196void perf_evlist__to_front(struct perf_evlist *evlist,
197 struct perf_evsel *move_evsel); 197 struct perf_evsel *move_evsel);
198 198
199/**
200 * __evlist__for_each - iterate thru all the evsels
201 * @list: list_head instance to iterate
202 * @evsel: struct evsel iterator
203 */
204#define __evlist__for_each(list, evsel) \
205 list_for_each_entry(evsel, list, node)
206
207/**
208 * evlist__for_each - iterate thru all the evsels
209 * @evlist: evlist instance to iterate
210 * @evsel: struct evsel iterator
211 */
212#define evlist__for_each(evlist, evsel) \
213 __evlist__for_each(&(evlist)->entries, evsel)
214
215/**
216 * __evlist__for_each_continue - continue iteration thru all the evsels
217 * @list: list_head instance to iterate
218 * @evsel: struct evsel iterator
219 */
220#define __evlist__for_each_continue(list, evsel) \
221 list_for_each_entry_continue(evsel, list, node)
222
223/**
224 * evlist__for_each_continue - continue iteration thru all the evsels
225 * @evlist: evlist instance to iterate
226 * @evsel: struct evsel iterator
227 */
228#define evlist__for_each_continue(evlist, evsel) \
229 __evlist__for_each_continue(&(evlist)->entries, evsel)
230
231/**
232 * __evlist__for_each_reverse - iterate thru all the evsels in reverse order
233 * @list: list_head instance to iterate
234 * @evsel: struct evsel iterator
235 */
236#define __evlist__for_each_reverse(list, evsel) \
237 list_for_each_entry_reverse(evsel, list, node)
238
239/**
240 * evlist__for_each_reverse - iterate thru all the evsels in reverse order
241 * @evlist: evlist instance to iterate
242 * @evsel: struct evsel iterator
243 */
244#define evlist__for_each_reverse(evlist, evsel) \
245 __evlist__for_each_reverse(&(evlist)->entries, evsel)
246
247/**
248 * __evlist__for_each_safe - safely iterate thru all the evsels
249 * @list: list_head instance to iterate
250 * @tmp: struct evsel temp iterator
251 * @evsel: struct evsel iterator
252 */
253#define __evlist__for_each_safe(list, tmp, evsel) \
254 list_for_each_entry_safe(evsel, tmp, list, node)
255
256/**
257 * evlist__for_each_safe - safely iterate thru all the evsels
258 * @evlist: evlist instance to iterate
259 * @evsel: struct evsel iterator
260 * @tmp: struct evsel temp iterator
261 */
262#define evlist__for_each_safe(evlist, tmp, evsel) \
263 __evlist__for_each_safe(&(evlist)->entries, tmp, evsel)
199 264
200#endif /* __PERF_EVLIST_H */ 265#endif /* __PERF_EVLIST_H */
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index a4a60b7887ee..bb3e0ede6183 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -643,8 +643,7 @@ static int write_event_desc(int fd, struct perf_header *h __maybe_unused,
643 if (ret < 0) 643 if (ret < 0)
644 return ret; 644 return ret;
645 645
646 list_for_each_entry(evsel, &evlist->entries, node) { 646 evlist__for_each(evlist, evsel) {
647
648 ret = do_write(fd, &evsel->attr, sz); 647 ret = do_write(fd, &evsel->attr, sz);
649 if (ret < 0) 648 if (ret < 0)
650 return ret; 649 return ret;
@@ -1092,7 +1091,7 @@ static int write_group_desc(int fd, struct perf_header *h __maybe_unused,
1092 if (ret < 0) 1091 if (ret < 0)
1093 return ret; 1092 return ret;
1094 1093
1095 list_for_each_entry(evsel, &evlist->entries, node) { 1094 evlist__for_each(evlist, evsel) {
1096 if (perf_evsel__is_group_leader(evsel) && 1095 if (perf_evsel__is_group_leader(evsel) &&
1097 evsel->nr_members > 1) { 1096 evsel->nr_members > 1) {
1098 const char *name = evsel->group_name ?: "{anon_group}"; 1097 const char *name = evsel->group_name ?: "{anon_group}";
@@ -1487,7 +1486,7 @@ static void print_group_desc(struct perf_header *ph, int fd __maybe_unused,
1487 1486
1488 session = container_of(ph, struct perf_session, header); 1487 session = container_of(ph, struct perf_session, header);
1489 1488
1490 list_for_each_entry(evsel, &session->evlist->entries, node) { 1489 evlist__for_each(session->evlist, evsel) {
1491 if (perf_evsel__is_group_leader(evsel) && 1490 if (perf_evsel__is_group_leader(evsel) &&
1492 evsel->nr_members > 1) { 1491 evsel->nr_members > 1) {
1493 fprintf(fp, "# group: %s{%s", evsel->group_name ?: "", 1492 fprintf(fp, "# group: %s{%s", evsel->group_name ?: "",
@@ -1768,7 +1767,7 @@ perf_evlist__find_by_index(struct perf_evlist *evlist, int idx)
1768{ 1767{
1769 struct perf_evsel *evsel; 1768 struct perf_evsel *evsel;
1770 1769
1771 list_for_each_entry(evsel, &evlist->entries, node) { 1770 evlist__for_each(evlist, evsel) {
1772 if (evsel->idx == idx) 1771 if (evsel->idx == idx)
1773 return evsel; 1772 return evsel;
1774 } 1773 }
@@ -2071,7 +2070,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
2071 session->evlist->nr_groups = nr_groups; 2070 session->evlist->nr_groups = nr_groups;
2072 2071
2073 i = nr = 0; 2072 i = nr = 0;
2074 list_for_each_entry(evsel, &session->evlist->entries, node) { 2073 evlist__for_each(session->evlist, evsel) {
2075 if (evsel->idx == (int) desc[i].leader_idx) { 2074 if (evsel->idx == (int) desc[i].leader_idx) {
2076 evsel->leader = evsel; 2075 evsel->leader = evsel;
2077 /* {anon_group} is a dummy name */ 2076 /* {anon_group} is a dummy name */
@@ -2298,7 +2297,7 @@ int perf_session__write_header(struct perf_session *session,
2298 2297
2299 lseek(fd, sizeof(f_header), SEEK_SET); 2298 lseek(fd, sizeof(f_header), SEEK_SET);
2300 2299
2301 list_for_each_entry(evsel, &evlist->entries, node) { 2300 evlist__for_each(session->evlist, evsel) {
2302 evsel->id_offset = lseek(fd, 0, SEEK_CUR); 2301 evsel->id_offset = lseek(fd, 0, SEEK_CUR);
2303 err = do_write(fd, evsel->id, evsel->ids * sizeof(u64)); 2302 err = do_write(fd, evsel->id, evsel->ids * sizeof(u64));
2304 if (err < 0) { 2303 if (err < 0) {
@@ -2309,7 +2308,7 @@ int perf_session__write_header(struct perf_session *session,
2309 2308
2310 attr_offset = lseek(fd, 0, SEEK_CUR); 2309 attr_offset = lseek(fd, 0, SEEK_CUR);
2311 2310
2312 list_for_each_entry(evsel, &evlist->entries, node) { 2311 evlist__for_each(evlist, evsel) {
2313 f_attr = (struct perf_file_attr){ 2312 f_attr = (struct perf_file_attr){
2314 .attr = evsel->attr, 2313 .attr = evsel->attr,
2315 .ids = { 2314 .ids = {
@@ -2742,7 +2741,7 @@ static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist,
2742{ 2741{
2743 struct perf_evsel *pos; 2742 struct perf_evsel *pos;
2744 2743
2745 list_for_each_entry(pos, &evlist->entries, node) { 2744 evlist__for_each(evlist, pos) {
2746 if (pos->attr.type == PERF_TYPE_TRACEPOINT && 2745 if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
2747 perf_evsel__prepare_tracepoint_event(pos, pevent)) 2746 perf_evsel__prepare_tracepoint_event(pos, pevent))
2748 return -1; 2747 return -1;
@@ -2890,7 +2889,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
2890 struct perf_evsel *evsel; 2889 struct perf_evsel *evsel;
2891 int err = 0; 2890 int err = 0;
2892 2891
2893 list_for_each_entry(evsel, &session->evlist->entries, node) { 2892 evlist__for_each(session->evlist, evsel) {
2894 err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids, 2893 err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids,
2895 evsel->id, process); 2894 evsel->id, process);
2896 if (err) { 2895 if (err) {
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 0153435b8427..a7f1b6a91fdd 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -820,8 +820,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
820 if (!add && get_event_modifier(&mod, str, NULL)) 820 if (!add && get_event_modifier(&mod, str, NULL))
821 return -EINVAL; 821 return -EINVAL;
822 822
823 list_for_each_entry(evsel, list, node) { 823 __evlist__for_each(list, evsel) {
824
825 if (add && get_event_modifier(&mod, str, evsel)) 824 if (add && get_event_modifier(&mod, str, evsel))
826 return -EINVAL; 825 return -EINVAL;
827 826
@@ -845,7 +844,7 @@ int parse_events_name(struct list_head *list, char *name)
845{ 844{
846 struct perf_evsel *evsel; 845 struct perf_evsel *evsel;
847 846
848 list_for_each_entry(evsel, list, node) { 847 __evlist__for_each(list, evsel) {
849 if (!evsel->name) 848 if (!evsel->name)
850 evsel->name = strdup(name); 849 evsel->name = strdup(name);
851 } 850 }
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 4bf8ace7f511..122669c18ff4 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -908,9 +908,10 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i)
908 if (i >= pevlist->evlist.nr_entries) 908 if (i >= pevlist->evlist.nr_entries)
909 return NULL; 909 return NULL;
910 910
911 list_for_each_entry(pos, &pevlist->evlist.entries, node) 911 evlist__for_each(&pevlist->evlist, pos) {
912 if (i-- == 0) 912 if (i-- == 0)
913 break; 913 break;
914 }
914 915
915 return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); 916 return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel));
916} 917}
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 104a47563d39..373762501dad 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -89,19 +89,19 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
89 if (evlist->cpus->map[0] < 0) 89 if (evlist->cpus->map[0] < 0)
90 opts->no_inherit = true; 90 opts->no_inherit = true;
91 91
92 list_for_each_entry(evsel, &evlist->entries, node) 92 evlist__for_each(evlist, evsel)
93 perf_evsel__config(evsel, opts); 93 perf_evsel__config(evsel, opts);
94 94
95 if (evlist->nr_entries > 1) { 95 if (evlist->nr_entries > 1) {
96 struct perf_evsel *first = perf_evlist__first(evlist); 96 struct perf_evsel *first = perf_evlist__first(evlist);
97 97
98 list_for_each_entry(evsel, &evlist->entries, node) { 98 evlist__for_each(evlist, evsel) {
99 if (evsel->attr.sample_type == first->attr.sample_type) 99 if (evsel->attr.sample_type == first->attr.sample_type)
100 continue; 100 continue;
101 use_sample_identifier = perf_can_sample_identifier(); 101 use_sample_identifier = perf_can_sample_identifier();
102 break; 102 break;
103 } 103 }
104 list_for_each_entry(evsel, &evlist->entries, node) 104 evlist__for_each(evlist, evsel)
105 perf_evsel__set_sample_id(evsel, use_sample_identifier); 105 perf_evsel__set_sample_id(evsel, use_sample_identifier);
106 } 106 }
107 107
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8ffe29c55d0f..7acc03e8f3b2 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1384,7 +1384,7 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
1384{ 1384{
1385 struct perf_evsel *evsel; 1385 struct perf_evsel *evsel;
1386 1386
1387 list_for_each_entry(evsel, &session->evlist->entries, node) { 1387 evlist__for_each(session->evlist, evsel) {
1388 if (evsel->attr.type == PERF_TYPE_TRACEPOINT) 1388 if (evsel->attr.type == PERF_TYPE_TRACEPOINT)
1389 return true; 1389 return true;
1390 } 1390 }
@@ -1442,7 +1442,7 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
1442 1442
1443 ret += events_stats__fprintf(&session->stats, fp); 1443 ret += events_stats__fprintf(&session->stats, fp);
1444 1444
1445 list_for_each_entry(pos, &session->evlist->entries, node) { 1445 evlist__for_each(session->evlist, pos) {
1446 ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); 1446 ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos));
1447 ret += events_stats__fprintf(&pos->hists.stats, fp); 1447 ret += events_stats__fprintf(&pos->hists.stats, fp);
1448 } 1448 }
@@ -1464,7 +1464,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
1464{ 1464{
1465 struct perf_evsel *pos; 1465 struct perf_evsel *pos;
1466 1466
1467 list_for_each_entry(pos, &session->evlist->entries, node) { 1467 evlist__for_each(session->evlist, pos) {
1468 if (pos->attr.type == type) 1468 if (pos->attr.type == type)
1469 return pos; 1469 return pos;
1470 } 1470 }