Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
f74b9d3
Documentation
arch
block
certs
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
build
cgroup
firewire
gpio
hv
iio
include
kvm
laptop
leds
lib
net
nfsd
objtool
pci
pcmcia
perf
Documentation
arch
bench
jvmti
pmu-events
python
scripts
tests
attr
shell
.gitignore
Build
attr.c
attr.py
backward-ring-buffer.c
bitmap.c
bp_signal.c
bp_signal_overflow.c
bpf-script-example.c
bpf-script-test-kbuild.c
bpf-script-test-prologue.c
bpf-script-test-relocation.c
bpf.c
builtin-test.c
clang.c
code-reading.c
cpumap.c
dso-data.c
dwarf-unwind.c
event-times.c
event_update.c
evsel-roundtrip-name.c
evsel-tp-sched.c
expr.c
fdarray.c
hists_common.c
hists_common.h
hists_cumulate.c
hists_filter.c
hists_link.c
hists_output.c
is_printable_array.c
keep-tracking.c
kmod-path.c
llvm.c
llvm.h
make
mem.c
mmap-basic.c
mmap-thread-lookup.c
openat-syscall-all-cpus.c
openat-syscall-tp-fields.c
openat-syscall.c
parse-events.c
parse-no-sample-id-all.c
perf-hooks.c
perf-record.c
perf-targz-src-pkg
pmu.c
python-use.c
sample-parsing.c
sdt.c
stat.c
sw-clock.c
switch-tracking.c
task-exit.c
tests.h
thread-map.c
thread-mg-share.c
topology.c
unit_number__scnprintf.c
vmlinux-kallsyms.c
trace
ui
util
.gitignore
Build
CREDITS
MANIFEST
Makefile
Makefile.config
Makefile.perf
builtin-annotate.c
builtin-bench.c
builtin-buildid-cache.c
builtin-buildid-list.c
builtin-c2c.c
builtin-config.c
builtin-data.c
builtin-diff.c
builtin-evlist.c
builtin-ftrace.c
builtin-help.c
builtin-inject.c
builtin-kallsyms.c
builtin-kmem.c
builtin-kvm.c
builtin-list.c
builtin-lock.c
builtin-mem.c
builtin-probe.c
builtin-record.c
builtin-report.c
builtin-sched.c
builtin-script.c
builtin-stat.c
builtin-timechart.c
builtin-top.c
builtin-trace.c
builtin-version.c
builtin.h
check-headers.sh
command-list.txt
design.txt
perf-archive.sh
perf-completion.sh
perf-read-vdso.c
perf-sys.h
perf-with-kcore.sh
perf.c
perf.h
power
scripts
spi
testing
thermal
time
usb
virtio
vm
Makefile
usr
virt
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
perf
/
tests
/
backward-ring-buffer.c
Copy path
Blame
Blame
Latest commit
History
History
153 lines (128 loc) · 3.42 KB
Breadcrumbs
linux
/
tools
/
perf
/
tests
/
backward-ring-buffer.c
Top
File metadata and controls
Code
Blame
153 lines (128 loc) · 3.42 KB
Raw
// SPDX-License-Identifier: GPL-2.0 /* * Test backward bit in event attribute, read ring buffer from end to * beginning */ #include <perf.h> #include <evlist.h> #include <sys/prctl.h> #include "tests.h" #include "debug.h" #include <errno.h> #define NR_ITERS 111 static void testcase(void) { int i; for (i = 0; i < NR_ITERS; i++) { char proc_name[10]; snprintf(proc_name, sizeof(proc_name), "p:%d\n", i); prctl(PR_SET_NAME, proc_name); } } static int count_samples(struct perf_evlist *evlist, int *sample_count, int *comm_count) { int i; for (i = 0; i < evlist->nr_mmaps; i++) { union perf_event *event; perf_mmap__read_catchup(&evlist->backward_mmap[i]); while ((event = perf_mmap__read_backward(&evlist->backward_mmap[i])) != NULL) { const u32 type = event->header.type; switch (type) { case PERF_RECORD_SAMPLE: (*sample_count)++; break; case PERF_RECORD_COMM: (*comm_count)++; break; default: pr_err("Unexpected record of type %d\n", type); return TEST_FAIL; } } } return TEST_OK; } static int do_test(struct perf_evlist *evlist, int mmap_pages, int *sample_count, int *comm_count) { int err; char sbuf[STRERR_BUFSIZE]; err = perf_evlist__mmap(evlist, mmap_pages); if (err < 0) { pr_debug("perf_evlist__mmap: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); return TEST_FAIL; } perf_evlist__enable(evlist); testcase(); perf_evlist__disable(evlist); err = count_samples(evlist, sample_count, comm_count); perf_evlist__munmap(evlist); return err; } int test__backward_ring_buffer(struct test *test __maybe_unused, int subtest __maybe_unused) { int ret = TEST_SKIP, err, sample_count = 0, comm_count = 0; char pid[16], sbuf[STRERR_BUFSIZE]; struct perf_evlist *evlist; struct perf_evsel *evsel __maybe_unused; struct parse_events_error parse_error; struct record_opts opts = { .target = { .uid = UINT_MAX, .uses_mmap = true, }, .freq = 0, .mmap_pages = 256, .default_interval = 1, }; snprintf(pid, sizeof(pid), "%d", getpid()); pid[sizeof(pid) - 1] = '\0'; opts.target.tid = opts.target.pid = pid; evlist = perf_evlist__new(); if (!evlist) { pr_debug("Not enough memory to create evlist\n"); return TEST_FAIL; } err = perf_evlist__create_maps(evlist, &opts.target); if (err < 0) { pr_debug("Not enough memory to create thread/cpu maps\n"); goto out_delete_evlist; } bzero(&parse_error, sizeof(parse_error)); /* * Set backward bit, ring buffer should be writing from end. Record * it in aux evlist */ err = parse_events(evlist, "syscalls:sys_enter_prctl/overwrite/", &parse_error); if (err) { pr_debug("Failed to parse tracepoint event, try use root\n"); ret = TEST_SKIP; goto out_delete_evlist; } perf_evlist__config(evlist, &opts, NULL); err = perf_evlist__open(evlist); if (err < 0) { pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); goto out_delete_evlist; } ret = TEST_FAIL; err = do_test(evlist, opts.mmap_pages, &sample_count, &comm_count); if (err != TEST_OK) goto out_delete_evlist; if ((sample_count != NR_ITERS) || (comm_count != NR_ITERS)) { pr_err("Unexpected counter: sample_count=%d, comm_count=%d\n", sample_count, comm_count); goto out_delete_evlist; } err = do_test(evlist, 1, &sample_count, &comm_count); if (err != TEST_OK) goto out_delete_evlist; ret = TEST_OK; out_delete_evlist: perf_evlist__delete(evlist); return ret; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
You can’t perform that action at this time.