2 * Test backward bit in event attribute, read ring buffer from end to
14 static void testcase(void)
18 for (i
= 0; i
< NR_ITERS
; i
++) {
21 snprintf(proc_name
, sizeof(proc_name
), "p:%d\n", i
);
22 prctl(PR_SET_NAME
, proc_name
);
26 static int count_samples(struct perf_evlist
*evlist
, int *sample_count
,
31 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
32 union perf_event
*event
;
34 perf_mmap__read_catchup(&evlist
->backward_mmap
[i
]);
35 while ((event
= perf_mmap__read_backward(&evlist
->backward_mmap
[i
])) != NULL
) {
36 const u32 type
= event
->header
.type
;
39 case PERF_RECORD_SAMPLE
:
42 case PERF_RECORD_COMM
:
46 pr_err("Unexpected record of type %d\n", type
);
54 static int do_test(struct perf_evlist
*evlist
, int mmap_pages
,
55 int *sample_count
, int *comm_count
)
58 char sbuf
[STRERR_BUFSIZE
];
60 err
= perf_evlist__mmap(evlist
, mmap_pages
, true);
62 pr_debug("perf_evlist__mmap: %s\n",
63 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
67 perf_evlist__enable(evlist
);
69 perf_evlist__disable(evlist
);
71 err
= count_samples(evlist
, sample_count
, comm_count
);
72 perf_evlist__munmap(evlist
);
77 int test__backward_ring_buffer(int subtest __maybe_unused
)
79 int ret
= TEST_SKIP
, err
, sample_count
= 0, comm_count
= 0;
80 char pid
[16], sbuf
[STRERR_BUFSIZE
];
81 struct perf_evlist
*evlist
;
82 struct perf_evsel
*evsel __maybe_unused
;
83 struct parse_events_error parse_error
;
84 struct record_opts opts
= {
91 .default_interval
= 1,
94 snprintf(pid
, sizeof(pid
), "%d", getpid());
95 pid
[sizeof(pid
) - 1] = '\0';
96 opts
.target
.tid
= opts
.target
.pid
= pid
;
98 evlist
= perf_evlist__new();
100 pr_debug("No enough memory to create evlist\n");
104 err
= perf_evlist__create_maps(evlist
, &opts
.target
);
106 pr_debug("Not enough memory to create thread/cpu maps\n");
107 goto out_delete_evlist
;
110 bzero(&parse_error
, sizeof(parse_error
));
112 * Set backward bit, ring buffer should be writing from end. Record
115 err
= parse_events(evlist
, "syscalls:sys_enter_prctl/overwrite/", &parse_error
);
117 pr_debug("Failed to parse tracepoint event, try use root\n");
119 goto out_delete_evlist
;
122 perf_evlist__config(evlist
, &opts
, NULL
);
124 err
= perf_evlist__open(evlist
);
126 pr_debug("perf_evlist__open: %s\n",
127 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
128 goto out_delete_evlist
;
132 err
= do_test(evlist
, opts
.mmap_pages
, &sample_count
,
135 goto out_delete_evlist
;
137 if ((sample_count
!= NR_ITERS
) || (comm_count
!= NR_ITERS
)) {
138 pr_err("Unexpected counter: sample_count=%d, comm_count=%d\n",
139 sample_count
, comm_count
);
140 goto out_delete_evlist
;
143 err
= do_test(evlist
, 1, &sample_count
, &comm_count
);
145 goto out_delete_evlist
;
149 perf_evlist__delete(evlist
);