diff --git a/src/task_bulk.c b/src/task_bulk.c index 3d69110143aa2e1cd9a4e622ce7063f20ccba276..b4c12f02d5423bea655b310ec06eb8d8f26998c0 100644 --- a/src/task_bulk.c +++ b/src/task_bulk.c @@ -41,15 +41,16 @@ static void bump_memlock_rlimit(void) } static void print_usage(char **argv) { - fprintf(stderr, "Usage: %s user|bpf <iter>", argv[0]); + fprintf(stderr, "Usage: %s user|bpf <init> <iter>", argv[0]); } int main(int argc, char **argv) { - if (argc != 3) { + if (argc != 4) { print_usage(argv); return 1; } + bool user; if (strcmp("bpf", argv[1]) == 0) { user = false; @@ -59,73 +60,80 @@ int main(int argc, char **argv) print_usage(argv); return 1; } - int iter = atoi(argv[2]); - if (iter < 0) { + + int init = atoi(argv[2]); + if (init < 0) { print_usage(argv); return 1; } - int err; - + int iter = atoi(argv[3]); + if (iter < 0) { + print_usage(argv); + return 1; + } - if (user) { - int *fds = malloc(sizeof(int) * SIZE); - if (fds == NULL) { - return 1; - } + int err = 0; + for (int k = 0; k < init; k++) { + if (user) { + int *fds = malloc(sizeof(int) * SIZE); + if (fds == NULL) { + return 1; + } - for (int j = 0; j < iter; j++) { - for (int i = 0; i < SIZE; i++) { - int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); - if (fd == -1) { - perror("open"); - return 1; + for (int j = 0; j < iter; j++) { + for (int i = 0; i < SIZE; i++) { + int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); + if (fd == -1) { + perror("open"); + return 1; + } + fds[i] = fd; } - fds[i] = fd; - } - for (int i = 0; i < SIZE; i++) { - err = close(fds[i]); - if (err) { - perror("close"); - return 1; + for (int i = 0; i < SIZE; i++) { + err = close(fds[i]); + if (err) { + perror("close"); + return 1; + } } } - } - free(fds); - } else { - struct task_bulk_bpf *skel; + free(fds); + } else { + struct task_bulk_bpf *skel; - /* Set up libbpf errors and debug info callback */ - libbpf_set_print(libbpf_print_fn); + /* 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(); + /* Bump RLIMIT_MEMLOCK to allow BPF sub-system to do anything */ + bump_memlock_rlimit(); - /* Open BPF application */ - skel = task_bulk_bpf__open(); - if (!skel) { - fprintf(stderr, "Failed to open BPF skeleton\n"); - return 1; - } + /* Open BPF application */ + skel = task_bulk_bpf__open(); + if (!skel) { + fprintf(stderr, "Failed to open BPF skeleton\n"); + return 1; + } - skel->bss->dir = "/tmp"; + skel->bss->dir = "/tmp"; - /* Load & verify BPF programs */ - err = task_bulk_bpf__load(skel); - if (err) { - fprintf(stderr, "Failed to load and verify BPF skeleton\n"); - goto cleanup; - } + /* Load & verify BPF programs */ + err = task_bulk_bpf__load(skel); + if (err) { + fprintf(stderr, "Failed to load and verify BPF skeleton\n"); + goto cleanup; + } - int prog_fd = bpf_program__fd(skel->progs.entry); + int prog_fd = bpf_program__fd(skel->progs.entry); - for (int j = 0; j < iter; j++) { - err = syscall(SYS_bpftask, prog_fd, NULL); - } + for (int j = 0; j < iter; j++) { + err = syscall(SYS_bpftask, prog_fd, NULL); + } - cleanup: - task_bulk_bpf__destroy(skel); + cleanup: + task_bulk_bpf__destroy(skel); + } } return -err;