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
0feb40e6
Commit
0feb40e6
authored
May 22, 2017
by
4ast
Committed by
GitHub
May 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1192 from palmtenor/perf_config
Unify Perf Event related Enums and checks
parents
cce028d8
f510b6b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
44 deletions
+35
-44
src/cc/libbpf.c
src/cc/libbpf.c
+23
-2
src/python/bcc/table.py
src/python/bcc/table.py
+3
-41
tests/python/test_perf_event.py
tests/python/test_perf_event.py
+9
-1
No files found.
src/cc/libbpf.c
View file @
0feb40e6
...
...
@@ -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
;
}
...
...
src/python/bcc/table.py
View file @
0feb40e6
...
...
@@ -468,41 +468,6 @@ class ProgArray(ArrayBase):
raise
Exception
(
"Could not delete item"
)
class
PerfEventArray
(
ArrayBase
):
class
Event
(
object
):
def
__init__
(
self
,
typ
,
config
):
self
.
typ
=
typ
self
.
config
=
config
HW_CPU_CYCLES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
0
)
HW_INSTRUCTIONS
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
1
)
HW_CACHE_REFERENCES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
2
)
HW_CACHE_MISSES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
3
)
HW_BRANCH_INSTRUCTIONS
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
4
)
HW_BRANCH_MISSES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
5
)
HW_BUS_CYCLES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
6
)
HW_STALLED_CYCLES_FRONTEND
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
7
)
HW_STALLED_CYCLES_BACKEND
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
8
)
HW_REF_CPU_CYCLES
=
Event
(
Perf
.
PERF_TYPE_HARDWARE
,
9
)
# not yet supported, wip
#HW_CACHE_L1D_READ = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|0<<8|0<<16)
#HW_CACHE_L1D_READ_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|0<<8|1<<16)
#HW_CACHE_L1D_WRITE = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|1<<8|0<<16)
#HW_CACHE_L1D_WRITE_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|1<<8|1<<16)
#HW_CACHE_L1D_PREF = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|2<<8|0<<16)
#HW_CACHE_L1D_PREF_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 0<<0|2<<8|1<<16)
#HW_CACHE_L1I_READ = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|0<<8|0<<16)
#HW_CACHE_L1I_READ_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|0<<8|1<<16)
#HW_CACHE_L1I_WRITE = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|1<<8|0<<16)
#HW_CACHE_L1I_WRITE_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|1<<8|1<<16)
#HW_CACHE_L1I_PREF = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|2<<8|0<<16)
#HW_CACHE_L1I_PREF_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 1<<0|2<<8|1<<16)
#HW_CACHE_LL_READ = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|0<<8|0<<16)
#HW_CACHE_LL_READ_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|0<<8|1<<16)
#HW_CACHE_LL_WRITE = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|1<<8|0<<16)
#HW_CACHE_LL_WRITE_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|1<<8|1<<16)
#HW_CACHE_LL_PREF = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|2<<8|0<<16)
#HW_CACHE_LL_PREF_MISS = Event(Perf.PERF_TYPE_HW_CACHE, 2<<0|2<<8|1<<16)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
PerfEventArray
,
self
).
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -556,18 +521,15 @@ class PerfEventArray(ArrayBase):
# the fd is kept open in the map itself by the kernel
os
.
close
(
fd
)
def
open_perf_event
(
self
,
ev
):
"""open_perf_event(
ev
)
def
open_perf_event
(
self
,
typ
,
config
):
"""open_perf_event(
typ, config
)
Configures the table such that calls from the bpf program to
table.perf_read(bpf_get_smp_processor_id()) will return the hardware
counter denoted by event ev on the local cpu.
"""
if
not
isinstance
(
ev
,
self
.
Event
):
raise
Exception
(
"argument must be an Event, got %s"
,
type
(
ev
))
for
i
in
get_online_cpus
():
self
.
_open_perf_event
(
i
,
ev
.
typ
,
ev
.
config
)
self
.
_open_perf_event
(
i
,
typ
,
config
)
class
PerCpuHash
(
HashTable
):
...
...
tests/python/test_perf_event.py
View file @
0feb40e6
...
...
@@ -18,12 +18,20 @@ BPF_HISTOGRAM(dist);
int kprobe__sys_getuid(void *ctx) {
u32 cpu = bpf_get_smp_processor_id();
u64 val = cnt1.perf_read(cpu);
if (((s64)val < 0) && ((s64)val > -256))
return 0;
prev.update(&cpu, &val);
return 0;
}
int kretprobe__sys_getuid(void *ctx) {
u32 cpu = bpf_get_smp_processor_id();
u64 val = cnt1.perf_read(cpu);
if (((s64)val < 0) && ((s64)val > -256))
return 0;
u64 *prevp = prev.lookup(&cpu);
if (prevp)
dist.increment(bpf_log2l(val - *prevp));
...
...
@@ -34,7 +42,7 @@ int kretprobe__sys_getuid(void *ctx) {
cflags
=
[
"-DNUM_CPUS=%d"
%
multiprocessing
.
cpu_count
()])
cnt1
=
b
[
"cnt1"
]
try
:
cnt1
.
open_perf_event
(
cnt1
.
HW_
CPU_CYCLES
)
cnt1
.
open_perf_event
(
bcc
.
PerfType
.
HARDWARE
,
bcc
.
PerfHWConfig
.
CPU_CYCLES
)
except
:
if
ctypes
.
get_errno
()
==
2
:
raise
self
.
skipTest
(
"hardware events unsupported"
)
...
...
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