Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
0cf7f748
Commit
0cf7f748
authored
Jan 24, 2018
by
4ast
Committed by
GitHub
Jan 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1549 from iovisor/yhs_dev
fix a race condition between perf_reader munmap and read
parents
2af307b4
cd5d4a6c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
src/cc/perf_reader.c
src/cc/perf_reader.c
+12
-0
No files found.
src/cc/perf_reader.c
View file @
0cf7f748
...
...
@@ -28,6 +28,12 @@
#include "libbpf.h"
#include "perf_reader.h"
enum
{
RB_NOT_USED
=
0
,
// ring buffer not usd
RB_USED_IN_MUNMAP
=
1
,
// used in munmap
RB_USED_IN_READ
=
2
,
// used in read
};
struct
perf_reader
{
perf_reader_cb
cb
;
perf_reader_raw_cb
raw_cb
;
...
...
@@ -36,6 +42,7 @@ struct perf_reader {
void
*
buf
;
// for keeping segmented data
size_t
buf_size
;
void
*
base
;
int
rb_use_state
;
int
page_size
;
int
page_cnt
;
int
fd
;
...
...
@@ -63,6 +70,7 @@ struct perf_reader * perf_reader_new(perf_reader_cb cb,
void
perf_reader_free
(
void
*
ptr
)
{
if
(
ptr
)
{
struct
perf_reader
*
reader
=
ptr
;
while
(
!
__sync_bool_compare_and_swap
(
&
reader
->
rb_use_state
,
RB_NOT_USED
,
RB_USED_IN_MUNMAP
));
munmap
(
reader
->
base
,
reader
->
page_size
*
(
reader
->
page_cnt
+
1
));
if
(
reader
->
fd
>=
0
)
{
ioctl
(
reader
->
fd
,
PERF_EVENT_IOC_DISABLE
,
0
);
...
...
@@ -220,6 +228,9 @@ void perf_reader_event_read(struct perf_reader *reader) {
uint8_t
*
sentinel
=
(
uint8_t
*
)
reader
->
base
+
buffer_size
+
reader
->
page_size
;
uint8_t
*
begin
,
*
end
;
if
(
!
__sync_bool_compare_and_swap
(
&
reader
->
rb_use_state
,
RB_NOT_USED
,
RB_USED_IN_READ
))
return
;
// Consume all the events on this ring, calling the cb function for each one.
// The message may fall on the ring boundary, in which case copy the message
// into a malloced buffer.
...
...
@@ -268,6 +279,7 @@ void perf_reader_event_read(struct perf_reader *reader) {
write_data_tail
(
perf_header
,
perf_header
->
data_tail
+
e
->
size
);
}
reader
->
rb_use_state
=
RB_NOT_USED
;
}
int
perf_reader_poll
(
int
num_readers
,
struct
perf_reader
**
readers
,
int
timeout
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment