27
27
#include <linux/log2.h>
28
28
#include <linux/err.h>
29
29
30
- static void perf_evlist__mmap_put (struct perf_evlist * evlist , int idx );
31
30
static void perf_mmap__munmap (struct perf_mmap * map );
32
31
static void perf_mmap__put (struct perf_mmap * map );
33
32
@@ -692,8 +691,11 @@ static int perf_evlist__set_paused(struct perf_evlist *evlist, bool value)
692
691
{
693
692
int i ;
694
693
694
+ if (!evlist -> backward_mmap )
695
+ return 0 ;
696
+
695
697
for (i = 0 ; i < evlist -> nr_mmaps ; i ++ ) {
696
- int fd = evlist -> mmap [i ].fd ;
698
+ int fd = evlist -> backward_mmap [i ].fd ;
697
699
int err ;
698
700
699
701
if (fd < 0 )
@@ -904,16 +906,6 @@ static void perf_mmap__put(struct perf_mmap *md)
904
906
perf_mmap__munmap (md );
905
907
}
906
908
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
-
917
909
void perf_mmap__consume (struct perf_mmap * md , bool overwrite )
918
910
{
919
911
if (!overwrite ) {
@@ -1049,12 +1041,6 @@ static int perf_mmap__mmap(struct perf_mmap *map,
1049
1041
return 0 ;
1050
1042
}
1051
1043
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
-
1058
1044
static bool
1059
1045
perf_evlist__should_poll (struct perf_evlist * evlist __maybe_unused ,
1060
1046
struct perf_evsel * evsel )
@@ -1066,16 +1052,27 @@ perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
1066
1052
1067
1053
static int perf_evlist__mmap_per_evsel (struct perf_evlist * evlist , int idx ,
1068
1054
struct mmap_params * mp , int cpu ,
1069
- int thread , int * output )
1055
+ int thread , int * _output , int * _output_backward )
1070
1056
{
1071
1057
struct perf_evsel * evsel ;
1072
1058
int revent ;
1073
1059
1074
1060
evlist__for_each_entry (evlist , evsel ) {
1061
+ struct perf_mmap * maps = evlist -> mmap ;
1062
+ int * output = _output ;
1075
1063
int fd ;
1076
1064
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
+ }
1079
1076
1080
1077
if (evsel -> system_wide && thread )
1081
1078
continue ;
@@ -1084,13 +1081,14 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
1084
1081
1085
1082
if (* output == -1 ) {
1086
1083
* output = fd ;
1087
- if (__perf_evlist__mmap (evlist , idx , mp , * output ) < 0 )
1084
+
1085
+ if (perf_mmap__mmap (& maps [idx ], mp , * output ) < 0 )
1088
1086
return -1 ;
1089
1087
} else {
1090
1088
if (ioctl (fd , PERF_EVENT_IOC_SET_OUTPUT , * output ) != 0 )
1091
1089
return -1 ;
1092
1090
1093
- perf_evlist__mmap_get ( evlist , idx );
1091
+ perf_mmap__get ( & maps [ idx ] );
1094
1092
}
1095
1093
1096
1094
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,
1103
1101
* Therefore don't add it for polling.
1104
1102
*/
1105
1103
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 ] );
1108
1106
return -1 ;
1109
1107
}
1110
1108
@@ -1130,13 +1128,14 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
1130
1128
pr_debug2 ("perf event ring buffer mmapped per cpu\n" );
1131
1129
for (cpu = 0 ; cpu < nr_cpus ; cpu ++ ) {
1132
1130
int output = -1 ;
1131
+ int output_backward = -1 ;
1133
1132
1134
1133
auxtrace_mmap_params__set_idx (& mp -> auxtrace_mp , evlist , cpu ,
1135
1134
true);
1136
1135
1137
1136
for (thread = 0 ; thread < nr_threads ; thread ++ ) {
1138
1137
if (perf_evlist__mmap_per_evsel (evlist , cpu , mp , cpu ,
1139
- thread , & output ))
1138
+ thread , & output , & output_backward ))
1140
1139
goto out_unmap ;
1141
1140
}
1142
1141
}
@@ -1157,12 +1156,13 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
1157
1156
pr_debug2 ("perf event ring buffer mmapped per thread\n" );
1158
1157
for (thread = 0 ; thread < nr_threads ; thread ++ ) {
1159
1158
int output = -1 ;
1159
+ int output_backward = -1 ;
1160
1160
1161
1161
auxtrace_mmap_params__set_idx (& mp -> auxtrace_mp , evlist , thread ,
1162
1162
false);
1163
1163
1164
1164
if (perf_evlist__mmap_per_evsel (evlist , thread , mp , 0 , thread ,
1165
- & output ))
1165
+ & output , & output_backward ))
1166
1166
goto out_unmap ;
1167
1167
}
1168
1168
0 commit comments