13 static struct timeval tp1,tp2;
15 static void start_timer()
17 gettimeofday(&tp1,NULL);
20 static double end_timer()
22 gettimeofday(&tp2,NULL);
23 return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
24 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
27 struct aio_open_args {
35 static int aio_pipe[2];
37 static int aio_open_child(void *ptr)
39 struct aio_open_args *args = ptr;
40 args->ret = open(args->fname, args->flags, args->mode);
42 write(aio_pipe[1], &ptr, sizeof(ptr));
46 static int aio_open(const char *fname, int flags, mode_t mode)
48 static char stack[8192];
49 struct aio_open_args *args, *a2;
53 args = malloc(sizeof(*args));
58 pid = clone(aio_open_child, stack+sizeof(stack)-32,
59 CLONE_FS|CLONE_FILES|CLONE_VM,
62 if (read(aio_pipe[0], &a2, sizeof(a2)) != sizeof(a2)) {
67 waitpid(pid, &status, __WCLONE);
69 // printf("args=%p a2=%p\n", args, a2);
82 static void run_test(const char *name, int (*fn)(const char *, int, mode_t))
84 const char *fname = "test.dat";
91 while (end_timer() < timeout) {
92 int fd = fn(fname, O_CREAT|O_TRUNC|O_RDWR, 0600);
101 printf("%.1f ops/sec (%s)\n", count/end_timer(), name);
109 run_test("aio_open", aio_open);
110 run_test("open", open);
111 run_test("aio_open", aio_open);
112 run_test("open", open);