Skip to content

Commit 09fa4f4

Browse files
WangNan0acmel
authored andcommitted
perf record: Rename variable to make code clear
record__mmap_read() writes data from ring buffer into perf.data. 'head' is maintained by the kernel, points to the last written record. 'old' is maintained by perf, points to the record read in previous round. record__mmap_read() saves data from 'old' to 'head' to perf.data. The names of these variables are not very intutive. In addition, when dealing with backward writing ring buffer, the md->prev pointer should point to 'head' instead of the last byte it got. Add 'start' and 'end' pointer to make code clear and set md->prev to 'head' instead of the moved 'old' pointer. This patch doesn't change behavior since: buf = &data[old & md->mask]; size = head - old; old += size; <--- Here, old == head Signed-off-by: Wang Nan <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: He Kuang <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2d11c65 commit 09fa4f4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tools/perf/builtin-record.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ static int record__mmap_read(struct record *rec, int idx)
8888
struct perf_mmap *md = &rec->evlist->mmap[idx];
8989
u64 head = perf_mmap__read_head(md);
9090
u64 old = md->prev;
91+
u64 end = head, start = old;
9192
unsigned char *data = md->base + page_size;
9293
unsigned long size;
9394
void *buf;
9495
int rc = 0;
9596

96-
if (old == head)
97+
if (start == end)
9798
return 0;
9899

99100
rec->samples++;
100101

101-
size = head - old;
102+
size = end - start;
102103
if (size > (unsigned long)(md->mask) + 1) {
103104
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
104105

@@ -107,27 +108,27 @@ static int record__mmap_read(struct record *rec, int idx)
107108
return 0;
108109
}
109110

110-
if ((old & md->mask) + size != (head & md->mask)) {
111-
buf = &data[old & md->mask];
112-
size = md->mask + 1 - (old & md->mask);
113-
old += size;
111+
if ((start & md->mask) + size != (end & md->mask)) {
112+
buf = &data[start & md->mask];
113+
size = md->mask + 1 - (start & md->mask);
114+
start += size;
114115

115116
if (record__write(rec, buf, size) < 0) {
116117
rc = -1;
117118
goto out;
118119
}
119120
}
120121

121-
buf = &data[old & md->mask];
122-
size = head - old;
123-
old += size;
122+
buf = &data[start & md->mask];
123+
size = end - start;
124+
start += size;
124125

125126
if (record__write(rec, buf, size) < 0) {
126127
rc = -1;
127128
goto out;
128129
}
129130

130-
md->prev = old;
131+
md->prev = head;
131132
perf_evlist__mmap_consume(rec->evlist, idx);
132133
out:
133134
return rc;

0 commit comments

Comments
 (0)