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
9875221c
Commit
9875221c
authored
May 19, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify perf_event type and config check
parent
cb3d1618
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
src/cc/libbpf.c
src/cc/libbpf.c
+23
-2
No files found.
src/cc/libbpf.c
View file @
9875221c
...
...
@@ -604,10 +604,32 @@ error:
return
NULL
;
}
int
invalid_perf_config
(
uint32_t
type
,
uint64_t
config
)
{
switch
(
type
)
{
case
PERF_TYPE_HARDWARE
:
return
config
>=
PERF_COUNT_HW_MAX
;
case
PERF_TYPE_SOFTWARE
:
return
config
>=
PERF_COUNT_SW_MAX
;
case
PERF_TYPE_RAW
:
return
0
;
default:
return
1
;
}
}
int
bpf_open_perf_event
(
uint32_t
type
,
uint64_t
config
,
int
pid
,
int
cpu
)
{
int
fd
;
struct
perf_event_attr
attr
=
{};
if
(
type
!=
PERF_TYPE_HARDWARE
&&
type
!=
PERF_TYPE_RAW
)
{
fprintf
(
stderr
,
"Unsupported perf event type
\n
"
);
return
-
1
;
}
if
(
invalid_perf_config
(
type
,
config
))
{
fprintf
(
stderr
,
"Invalid perf event config
\n
"
);
return
-
1
;
}
attr
.
sample_period
=
LONG_MAX
;
attr
.
type
=
type
;
attr
.
config
=
config
;
...
...
@@ -733,8 +755,7 @@ int bpf_attach_perf_event(int progfd, uint32_t ev_type, uint32_t ev_config,
fprintf
(
stderr
,
"Unsupported perf event type
\n
"
);
return
-
1
;
}
if
((
ev_type
==
PERF_TYPE_HARDWARE
&&
ev_config
>=
PERF_COUNT_HW_MAX
)
||
(
ev_type
==
PERF_TYPE_SOFTWARE
&&
ev_config
>=
PERF_COUNT_SW_MAX
))
{
if
(
invalid_perf_config
(
ev_type
,
ev_config
))
{
fprintf
(
stderr
,
"Invalid perf event config
\n
"
);
return
-
1
;
}
...
...
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