Skip to content

Commit 078c338

Browse files
WangNan0acmel
authored andcommitted
perf evlist: Map backward events to backward_mmap
In perf_evlist__mmap_per_evsel(), select backward_mmap for backward events. Utilize new perf_mmap APIs. Dynamically alloc backward_mmap. Remove useless functions. Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: He Kuang <hekuang@huawei.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nilay Vaish <nilayvaish@gmail.com> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1468485287-33422-9-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent b2cb615 commit 078c338

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

tools/perf/tests/backward-ring-buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,
3131
for (i = 0; i < evlist->nr_mmaps; i++) {
3232
union perf_event *event;
3333

34-
perf_evlist__mmap_read_catchup(evlist, i);
35-
while ((event = perf_evlist__mmap_read_backward(evlist, i)) != NULL) {
34+
perf_mmap__read_catchup(&evlist->backward_mmap[i]);
35+
while ((event = perf_mmap__read_backward(&evlist->backward_mmap[i])) != NULL) {
3636
const u32 type = event->header.type;
3737

3838
switch (type) {

tools/perf/util/evlist.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <linux/log2.h>
2828
#include <linux/err.h>
2929

30-
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
3130
static void perf_mmap__munmap(struct perf_mmap *map);
3231
static void perf_mmap__put(struct perf_mmap *map);
3332

@@ -692,8 +691,11 @@ static int perf_evlist__set_paused(struct perf_evlist *evlist, bool value)
692691
{
693692
int i;
694693

694+
if (!evlist->backward_mmap)
695+
return 0;
696+
695697
for (i = 0; i < evlist->nr_mmaps; i++) {
696-
int fd = evlist->mmap[i].fd;
698+
int fd = evlist->backward_mmap[i].fd;
697699
int err;
698700

699701
if (fd < 0)
@@ -904,16 +906,6 @@ static void perf_mmap__put(struct perf_mmap *md)
904906
perf_mmap__munmap(md);
905907
}
906908

907-
static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx)
908-
{
909-
perf_mmap__get(&evlist->mmap[idx]);
910-
}
911-
912-
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
913-
{
914-
perf_mmap__put(&evlist->mmap[idx]);
915-
}
916-
917909
void perf_mmap__consume(struct perf_mmap *md, bool overwrite)
918910
{
919911
if (!overwrite) {
@@ -1049,12 +1041,6 @@ static int perf_mmap__mmap(struct perf_mmap *map,
10491041
return 0;
10501042
}
10511043

1052-
static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
1053-
struct mmap_params *mp, int fd)
1054-
{
1055-
return perf_mmap__mmap(&evlist->mmap[idx], mp, fd);
1056-
}
1057-
10581044
static bool
10591045
perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
10601046
struct perf_evsel *evsel)
@@ -1066,16 +1052,27 @@ perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
10661052

10671053
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
10681054
struct mmap_params *mp, int cpu,
1069-
int thread, int *output)
1055+
int thread, int *_output, int *_output_backward)
10701056
{
10711057
struct perf_evsel *evsel;
10721058
int revent;
10731059

10741060
evlist__for_each_entry(evlist, evsel) {
1061+
struct perf_mmap *maps = evlist->mmap;
1062+
int *output = _output;
10751063
int fd;
10761064

1077-
if (!!evsel->attr.write_backward != (evlist->overwrite && evlist->backward))
1078-
continue;
1065+
if (evsel->attr.write_backward) {
1066+
output = _output_backward;
1067+
maps = evlist->backward_mmap;
1068+
1069+
if (!maps) {
1070+
maps = perf_evlist__alloc_mmap(evlist);
1071+
if (!maps)
1072+
return -1;
1073+
evlist->backward_mmap = maps;
1074+
}
1075+
}
10791076

10801077
if (evsel->system_wide && thread)
10811078
continue;
@@ -1084,13 +1081,14 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
10841081

10851082
if (*output == -1) {
10861083
*output = fd;
1087-
if (__perf_evlist__mmap(evlist, idx, mp, *output) < 0)
1084+
1085+
if (perf_mmap__mmap(&maps[idx], mp, *output) < 0)
10881086
return -1;
10891087
} else {
10901088
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
10911089
return -1;
10921090

1093-
perf_evlist__mmap_get(evlist, idx);
1091+
perf_mmap__get(&maps[idx]);
10941092
}
10951093

10961094
revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
@@ -1103,8 +1101,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
11031101
* Therefore don't add it for polling.
11041102
*/
11051103
if (!evsel->system_wide &&
1106-
__perf_evlist__add_pollfd(evlist, fd, &evlist->mmap[idx], revent) < 0) {
1107-
perf_evlist__mmap_put(evlist, idx);
1104+
__perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) {
1105+
perf_mmap__put(&maps[idx]);
11081106
return -1;
11091107
}
11101108

@@ -1130,13 +1128,14 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
11301128
pr_debug2("perf event ring buffer mmapped per cpu\n");
11311129
for (cpu = 0; cpu < nr_cpus; cpu++) {
11321130
int output = -1;
1131+
int output_backward = -1;
11331132

11341133
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
11351134
true);
11361135

11371136
for (thread = 0; thread < nr_threads; thread++) {
11381137
if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
1139-
thread, &output))
1138+
thread, &output, &output_backward))
11401139
goto out_unmap;
11411140
}
11421141
}
@@ -1157,12 +1156,13 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
11571156
pr_debug2("perf event ring buffer mmapped per thread\n");
11581157
for (thread = 0; thread < nr_threads; thread++) {
11591158
int output = -1;
1159+
int output_backward = -1;
11601160

11611161
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
11621162
false);
11631163

11641164
if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
1165-
&output))
1165+
&output, &output_backward))
11661166
goto out_unmap;
11671167
}
11681168

0 commit comments

Comments
 (0)