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
79553c20
Commit
79553c20
authored
Sep 07, 2015
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #184 from iovisor/bblanco_dev
Add BPF_HASH macro with variadic arguments
parents
489e4f52
7b9e5f11
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
2 deletions
+24
-2
examples/disksnoop.c
examples/disksnoop.c
+1
-1
examples/vfsreadlat.c
examples/vfsreadlat.c
+1
-1
src/cc/export/helpers.h
src/cc/export/helpers.h
+14
-0
tests/cc/test_clang.py
tests/cc/test_clang.py
+8
-0
No files found.
examples/disksnoop.c
View file @
79553c20
...
...
@@ -16,7 +16,7 @@
struct
key_t
{
struct
request
*
req
;
};
BPF_
TABLE
(
"hash"
,
struct
key_t
,
u64
,
start
,
10240
);
BPF_
HASH
(
start
,
struct
key_t
);
int
do_request
(
struct
pt_regs
*
ctx
,
struct
request
*
req
)
{
struct
key_t
key
=
{};
...
...
examples/vfsreadlat.c
View file @
79553c20
...
...
@@ -17,7 +17,7 @@ struct key_t {
u32
pid
;
};
BPF_
TABLE
(
"hash"
,
struct
key_t
,
u64
,
start
,
10240
);
BPF_
HASH
(
start
,
struct
key_t
);
BPF_TABLE
(
"array"
,
int
,
u64
,
dist
,
64
);
static
unsigned
int
log2
(
unsigned
int
v
)
...
...
src/cc/export/helpers.h
View file @
79553c20
...
...
@@ -41,6 +41,20 @@ struct _name##_table_t { \
__attribute__((section("maps/" _table_type))) \
struct _name##_table_t _name
#define BPF_HASH1(_name) \
BPF_TABLE("hash", u64, u64, _name, 10240)
#define BPF_HASH2(_name, _key_type) \
BPF_TABLE("hash", _key_type, u64, _name, 10240)
#define BPF_HASH3(_name, _key_type, _leaf_type) \
BPF_TABLE("hash", _key_type, _leaf_type, _name, 10240)
// helper for default-variable macro function
#define BPF_HASHX(_1, _2, _3, NAME, ...) NAME
// Define a hash function, some arguments optional
// BPF_HASH(name, key_type=u64, leaf_type=u64, size=10240)
#define BPF_HASH(...) \
BPF_HASHX(__VA_ARGS__, BPF_HASH3, BPF_HASH2, BPF_HASH1)(__VA_ARGS__)
// packet parsing state machine helpers
#define cursor_advance(_cursor, _len) \
({ void *_tmp = _cursor; _cursor += _len; _tmp; })
...
...
tests/cc/test_clang.py
View file @
79553c20
...
...
@@ -100,5 +100,13 @@ int do_request(struct pt_regs *ctx, int req) {
b
=
BPF
(
text
=
text
,
debug
=
0
)
fn
=
b
.
load_func
(
"do_request"
,
BPF
.
KPROBE
)
def
test_bpf_hash
(
self
):
text
=
"""
BPF_HASH(table1);
BPF_HASH(table2, u32);
BPF_HASH(table3, u32, int);
"""
b
=
BPF
(
text
=
text
,
debug
=
0
)
if
__name__
==
"__main__"
:
main
()
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