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
204df9ec
Commit
204df9ec
authored
May 23, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use BPF_F_CURRENT_CPU in perf_submit / perf_read when possible
parent
78f8ff9d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
3 deletions
+22
-3
src/cc/export/helpers.h
src/cc/export/helpers.h
+11
-0
src/cc/frontends/clang/CMakeLists.txt
src/cc/frontends/clang/CMakeLists.txt
+4
-0
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+1
-1
src/cc/frontends/clang/loader.cc
src/cc/frontends/clang/loader.cc
+4
-0
tests/python/test_perf_event.py
tests/python/test_perf_event.py
+2
-2
No files found.
src/cc/export/helpers.h
View file @
204df9ec
...
@@ -65,6 +65,17 @@ BPF_TABLE(_table_type, _key_type, _leaf_type, _name, _max_entries); \
...
@@ -65,6 +65,17 @@ BPF_TABLE(_table_type, _key_type, _leaf_type, _name, _max_entries); \
__attribute__((section("
maps
/
export
"))) \
__attribute__((section("
maps
/
export
"))) \
struct _name##_table_t __##_name
struct _name##_table_t __##_name
// Identifier for current CPU used in perf_submit and perf_read
// Prefer BPF_F_CURRENT_CPU flag, falls back to call helper for older kernel
// Can be overridden from BCC
#ifndef CUR_CPU_IDENTIFIER
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
#define CUR_CPU_IDENTIFIER BPF_F_CURRENT_CPU
#else
#define CUR_CPU_IDENTIFIER bpf_get_smp_processor_id()
#endif
#endif
// Table for pushing custom events to userspace via ring buffer
// Table for pushing custom events to userspace via ring buffer
#define BPF_PERF_OUTPUT(_name) \
#define BPF_PERF_OUTPUT(_name) \
struct _name##_table_t { \
struct _name##_table_t { \
...
...
src/cc/frontends/clang/CMakeLists.txt
View file @
204df9ec
...
@@ -2,4 +2,8 @@
...
@@ -2,4 +2,8 @@
# Licensed under the Apache License, Version 2.0 (the "License")
# Licensed under the Apache License, Version 2.0 (the "License")
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DKERNEL_MODULES_DIR='
\"
${
BCC_KERNEL_MODULES_DIR
}
\"
'"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DKERNEL_MODULES_DIR='
\"
${
BCC_KERNEL_MODULES_DIR
}
\"
'"
)
if
(
DEFINED BCC_CUR_CPU_IDENTIFIER
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DCUR_CPU_IDENTIFIER='
\"
${
BCC_CUR_CPU_IDENTIFIER
}
\"
'"
)
endif
()
add_library
(
clang_frontend STATIC loader.cc b_frontend_action.cc tp_frontend_action.cc kbuild_helper.cc ../../common.cc
)
add_library
(
clang_frontend STATIC loader.cc b_frontend_action.cc tp_frontend_action.cc kbuild_helper.cc ../../common.cc
)
src/cc/frontends/clang/b_frontend_action.cc
View file @
204df9ec
...
@@ -341,7 +341,7 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
...
@@ -341,7 +341,7 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
string
args_other
=
rewriter_
.
getRewrittenText
(
expansionRange
(
SourceRange
(
Call
->
getArg
(
1
)
->
getLocStart
(),
string
args_other
=
rewriter_
.
getRewrittenText
(
expansionRange
(
SourceRange
(
Call
->
getArg
(
1
)
->
getLocStart
(),
Call
->
getArg
(
2
)
->
getLocEnd
())));
Call
->
getArg
(
2
)
->
getLocEnd
())));
txt
=
"bpf_perf_event_output("
+
arg0
+
", bpf_pseudo_fd(1, "
+
fd
+
")"
;
txt
=
"bpf_perf_event_output("
+
arg0
+
", bpf_pseudo_fd(1, "
+
fd
+
")"
;
txt
+=
",
bpf_get_smp_processor_id()
, "
+
args_other
+
")"
;
txt
+=
",
CUR_CPU_IDENTIFIER
, "
+
args_other
+
")"
;
}
else
if
(
memb_name
==
"perf_submit_skb"
)
{
}
else
if
(
memb_name
==
"perf_submit_skb"
)
{
string
skb
=
rewriter_
.
getRewrittenText
(
expansionRange
(
Call
->
getArg
(
0
)
->
getSourceRange
()));
string
skb
=
rewriter_
.
getRewrittenText
(
expansionRange
(
Call
->
getArg
(
0
)
->
getSourceRange
()));
string
skb_len
=
rewriter_
.
getRewrittenText
(
expansionRange
(
Call
->
getArg
(
1
)
->
getSourceRange
()));
string
skb_len
=
rewriter_
.
getRewrittenText
(
expansionRange
(
Call
->
getArg
(
1
)
->
getSourceRange
()));
...
...
src/cc/frontends/clang/loader.cc
View file @
204df9ec
...
@@ -160,6 +160,10 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, TableStorage &ts, const st
...
@@ -160,6 +160,10 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, TableStorage &ts, const st
for
(
auto
i
=
0
;
i
<
ncflags
;
++
i
)
for
(
auto
i
=
0
;
i
<
ncflags
;
++
i
)
flags_cstr
.
push_back
(
cflags
[
i
]);
flags_cstr
.
push_back
(
cflags
[
i
]);
}
}
#ifdef CUR_CPU_IDENTIFIER
string
cur_cpu_flag
=
string
(
"-DCUR_CPU_IDENTIFIER="
)
+
CUR_CPU_IDENTIFIER
;
flags_cstr
.
push_back
(
cur_cpu_flag
.
c_str
());
#endif
// set up the error reporting class
// set up the error reporting class
IntrusiveRefCntPtr
<
DiagnosticOptions
>
diag_opts
(
new
DiagnosticOptions
());
IntrusiveRefCntPtr
<
DiagnosticOptions
>
diag_opts
(
new
DiagnosticOptions
());
...
...
tests/python/test_perf_event.py
View file @
204df9ec
...
@@ -17,7 +17,7 @@ BPF_ARRAY(prev, u64, NUM_CPUS);
...
@@ -17,7 +17,7 @@ BPF_ARRAY(prev, u64, NUM_CPUS);
BPF_HISTOGRAM(dist);
BPF_HISTOGRAM(dist);
int kprobe__sys_getuid(void *ctx) {
int kprobe__sys_getuid(void *ctx) {
u32 cpu = bpf_get_smp_processor_id();
u32 cpu = bpf_get_smp_processor_id();
u64 val = cnt1.perf_read(
cpu
);
u64 val = cnt1.perf_read(
CUR_CPU_IDENTIFIER
);
if (((s64)val < 0) && ((s64)val > -256))
if (((s64)val < 0) && ((s64)val > -256))
return 0;
return 0;
...
@@ -27,7 +27,7 @@ int kprobe__sys_getuid(void *ctx) {
...
@@ -27,7 +27,7 @@ int kprobe__sys_getuid(void *ctx) {
}
}
int kretprobe__sys_getuid(void *ctx) {
int kretprobe__sys_getuid(void *ctx) {
u32 cpu = bpf_get_smp_processor_id();
u32 cpu = bpf_get_smp_processor_id();
u64 val = cnt1.perf_read(
cpu
);
u64 val = cnt1.perf_read(
CUR_CPU_IDENTIFIER
);
if (((s64)val < 0) && ((s64)val > -256))
if (((s64)val < 0) && ((s64)val > -256))
return 0;
return 0;
...
...
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