Created
May 29, 2020 09:46
-
-
Save upa/0a59d3cc4ec82e123923ae08dbba2b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <sys/time.h> | |
#include <lkl.h> | |
#include <lkl_host.h> | |
int main(int argc, char **argv) | |
{ | |
struct timeval b, a; | |
int n, fd, ret, count = 1000000; | |
double elapsed; | |
printf("setup lkl\n"); | |
ret = lkl_start_kernel(&lkl_host_ops, "mem=100M"); | |
ret = lkl_sys_mknod("/dev_null", LKL_S_IFCHR | 0600, LKL_MKDEV(1, 3)); | |
if (ret < 0) { | |
printf("lkl_sys_mknod failed: %d\n", ret); | |
return -1; | |
} | |
char *host_target = "/dev/null"; | |
char *lkl_target = "/dev_null"; | |
printf("\n"); | |
printf("test host kernel\n"); | |
gettimeofday(&b, NULL); | |
for (n = 0; n < count; n++) { | |
fd = open(host_target, 0, 0); | |
if (fd < 0) { | |
printf("open failed at count %d: %d\n", n, fd); | |
break; | |
} | |
close(fd); | |
} | |
gettimeofday(&a, NULL); | |
elapsed = a.tv_sec * 1000000 + a.tv_usec; | |
elapsed -= b.tv_sec * 1000000 + b.tv_usec; | |
printf("%d open()/close(): %lf second\n", count, elapsed / 1000000); | |
printf("test lkl\n"); | |
gettimeofday(&b, NULL); | |
for (n = 0; n < count; n++) { | |
fd = lkl_sys_open(lkl_target, 0, 0); | |
if (fd < 0) { | |
printf("open failed at count %d: %d\n", n, fd); | |
break; | |
} | |
lkl_sys_close(fd); | |
} | |
gettimeofday(&a, NULL); | |
elapsed = a.tv_sec * 1000000 + a.tv_usec; | |
elapsed -= b.tv_sec * 1000000 + b.tv_usec; | |
printf("%d open()/close(): %lf second\n", count, elapsed / 1000000); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment