Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libbpf-bootstrap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luis Gerhorst
libbpf-bootstrap
Commits
7c5a180e
Commit
7c5a180e
authored
Mar 16, 2021
by
Luis Gerhorst
Browse files
Options
Downloads
Patches
Plain Diff
openv/closev
parent
799ad2b4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/task_bulk.bpf.c
+13
-3
13 additions, 3 deletions
src/task_bulk.bpf.c
src/task_bulk.c
+25
-12
25 additions, 12 deletions
src/task_bulk.c
with
38 additions
and
15 deletions
src/task_bulk.bpf.c
+
13
−
3
View file @
7c5a180e
...
...
@@ -9,14 +9,15 @@
char
LICENSE
[]
SEC
(
"license"
)
=
"Dual BSD/GPL"
;
char
*
dir
;
size_t
nr_syscalls
;
int
fds
[
SIZE
];
SEC
(
"task"
)
int
entry
(
long
**
ctx
)
int
openv
(
long
**
ctx
)
{
int
err
=
0
;
for
(
int
i
=
0
;
i
<
SIZE
;
i
++
)
{
for
(
int
i
=
0
;
i
<
SIZE
&&
i
<
nr_syscalls
;
i
++
)
{
int
fd
=
bpf_task_sys_open_3
((
uint64_t
)
dir
,
O_TMPFILE
|
O_RDWR
,
0777
);
if
(
fd
==
-
1
)
{
err
=
-
1
;
...
...
@@ -25,7 +26,16 @@ int entry(long **ctx)
fds
[
i
]
=
fd
;
}
for
(
int
i
=
0
;
i
<
SIZE
;
i
++
)
{
end:
return
err
;
}
SEC
(
"task"
)
int
closev
(
long
**
ctx
)
{
int
err
=
0
;
for
(
int
i
=
0
;
i
<
SIZE
&&
i
<
nr_syscalls
;
i
++
)
{
err
=
bpf_task_sys_close_1
(
fds
[
i
]);
if
(
err
)
{
break
;
...
...
This diff is collapsed.
Click to expand it.
src/task_bulk.c
+
25
−
12
View file @
7c5a180e
...
...
@@ -41,12 +41,12 @@ static void bump_memlock_rlimit(void)
}
static
void
print_usage
(
char
**
argv
)
{
fprintf
(
stderr
,
"Usage: %s user|bpf <init> <iter>"
,
argv
[
0
]);
fprintf
(
stderr
,
"Usage: %s user|bpf <
nr_
init> <iter>
<nr_syscalls>
"
,
argv
[
0
]);
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
4
)
{
if
(
argc
!=
5
)
{
print_usage
(
argv
);
return
1
;
}
...
...
@@ -61,8 +61,8 @@ int main(int argc, char **argv)
return
1
;
}
int
init
=
atoi
(
argv
[
2
]);
if
(
init
<
0
)
{
int
nr_
init
=
atoi
(
argv
[
2
]);
if
(
nr_
init
<
0
)
{
print_usage
(
argv
);
return
1
;
}
...
...
@@ -73,8 +73,14 @@ int main(int argc, char **argv)
return
1
;
}
int
nr_syscalls
=
atoi
(
argv
[
4
]);
if
(
nr_syscalls
<
0
)
{
print_usage
(
argv
);
return
1
;
}
int
err
=
0
;
for
(
int
k
=
0
;
k
<
init
;
k
++
)
{
for
(
int
k
=
0
;
k
<
nr_
init
;
k
++
)
{
if
(
user
)
{
int
*
fds
=
malloc
(
sizeof
(
int
)
*
SIZE
);
if
(
fds
==
NULL
)
{
...
...
@@ -82,7 +88,7 @@ int main(int argc, char **argv)
}
for
(
int
j
=
0
;
j
<
iter
;
j
++
)
{
for
(
int
i
=
0
;
i
<
SIZE
;
i
++
)
{
for
(
int
i
=
0
;
i
<
SIZE
&&
i
<
nr_syscalls
;
i
++
)
{
int
fd
=
open
(
"/tmp"
,
O_TMPFILE
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
);
if
(
fd
==
-
1
)
{
perror
(
"open"
);
...
...
@@ -90,7 +96,7 @@ int main(int argc, char **argv)
}
fds
[
i
]
=
fd
;
}
for
(
int
i
=
0
;
i
<
SIZE
;
i
++
)
{
for
(
int
i
=
0
;
i
<
SIZE
&&
i
<
nr_syscalls
;
i
++
)
{
err
=
close
(
fds
[
i
]);
if
(
err
)
{
perror
(
"close"
);
...
...
@@ -103,9 +109,6 @@ int main(int argc, char **argv)
}
else
{
struct
task_bulk_bpf
*
skel
;
/* Set up libbpf errors and debug info callback */
/* libbpf_set_print(libbpf_print_fn); */
/* Bump RLIMIT_MEMLOCK to allow BPF sub-system to do anything */
bump_memlock_rlimit
();
...
...
@@ -117,6 +120,7 @@ int main(int argc, char **argv)
}
skel
->
bss
->
dir
=
"/tmp"
;
skel
->
bss
->
nr_syscalls
=
nr_syscalls
;
/* Load & verify BPF programs */
err
=
task_bulk_bpf__load
(
skel
);
...
...
@@ -125,10 +129,19 @@ int main(int argc, char **argv)
goto
cleanup
;
}
int
prog_fd
=
bpf_program__fd
(
skel
->
progs
.
entry
);
int
open_prog_fd
=
bpf_program__fd
(
skel
->
progs
.
openv
);
int
close_prog_fd
=
bpf_program__fd
(
skel
->
progs
.
closev
);
for
(
int
j
=
0
;
j
<
iter
;
j
++
)
{
err
=
syscall
(
SYS_bpftask
,
prog_fd
,
NULL
);
err
=
syscall
(
SYS_bpftask
,
open_prog_fd
,
NULL
);
if
(
err
)
{
break
;
}
err
=
syscall
(
SYS_bpftask
,
close_prog_fd
,
NULL
);
if
(
err
)
{
break
;
}
}
cleanup:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment