Skip to content

Commit 32fdc2c

Browse files
olsajiriacmel
authored andcommitted
libperf: Adopt perf_mmap__read_done() from tools/perf
Move perf_mmap__read_init() from tools/perf to libperf and export it in the perf/mmap.h header. Signed-off-by: Jiri 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 <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20191007125344.14268-12-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7c4d418 commit 32fdc2c

20 files changed

Lines changed: 34 additions & 33 deletions

‎tools/perf/arch/x86/tests/perf-time-to-tsc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
142142
next_event:
143143
perf_mmap__consume(&md->core);
144144
}
145-
perf_mmap__read_done(md);
145+
perf_mmap__read_done(&md->core);
146146
}
147147

148148
if (!comm1_time || !comm2_time)

‎tools/perf/builtin-kvm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
794794
break;
795795
}
796796

797-
perf_mmap__read_done(md);
797+
perf_mmap__read_done(&md->core);
798798
return n;
799799
}
800800

‎tools/perf/builtin-top.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
894894
}
895895
}
896896

897-
perf_mmap__read_done(md);
897+
perf_mmap__read_done(&md->core);
898898
}
899899

900900
static void perf_top__mmap_read(struct perf_top *top)

‎tools/perf/builtin-trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3821,7 +3821,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
38213821
draining = true;
38223822
}
38233823
}
3824-
perf_mmap__read_done(md);
3824+
perf_mmap__read_done(&md->core);
38253825
}
38263826

38273827
if (trace->nr_events == before) {

‎tools/perf/lib/include/perf/mmap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ struct perf_mmap;
88

99
LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
1010
LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
11+
LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
1112

1213
#endif /* __LIBPERF_MMAP_H */

‎tools/perf/lib/libperf.map‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 {
4242
perf_evlist__poll;
4343
perf_mmap__consume;
4444
perf_mmap__read_init;
45+
perf_mmap__read_done;
4546
local:
4647
*;
4748
};

‎tools/perf/lib/mmap.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,20 @@ int perf_mmap__read_init(struct perf_mmap *map)
175175

176176
return __perf_mmap__read_init(map);
177177
}
178+
179+
/*
180+
* Mandatory for overwrite mode
181+
* The direction of overwrite mode is backward.
182+
* The last perf_mmap__read() will set tail to map->core.prev.
183+
* Need to correct the map->core.prev to head which is the end of next read.
184+
*/
185+
void perf_mmap__read_done(struct perf_mmap *map)
186+
{
187+
/*
188+
* Check if event was unmapped due to a POLLHUP/POLLERR.
189+
*/
190+
if (!refcount_read(&map->refcnt))
191+
return;
192+
193+
map->prev = perf_mmap__read_head(map);
194+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
5454
return TEST_FAIL;
5555
}
5656
}
57-
perf_mmap__read_done(map);
57+
perf_mmap__read_done(&map->core);
5858
}
5959
return TEST_OK;
6060
}

‎tools/perf/tests/bpf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
194194
if (type == PERF_RECORD_SAMPLE)
195195
count ++;
196196
}
197-
perf_mmap__read_done(md);
197+
perf_mmap__read_done(&md->core);
198198
}
199199

200200
if (count != expect) {

‎tools/perf/tests/code-reading.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
435435
if (ret < 0)
436436
return ret;
437437
}
438-
perf_mmap__read_done(md);
438+
perf_mmap__read_done(&md->core);
439439
}
440440
return 0;
441441
}

0 commit comments

Comments
 (0)