Skip to content
Snippets Groups Projects
Commit 7c5a180e authored by Luis Gerhorst's avatar Luis Gerhorst
Browse files

openv/closev

parent 799ad2b4
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment