0001
0002
0003
0004
0005
0006 #define _GNU_SOURCE
0007
0008 #include <stdio.h>
0009 #include <sys/syscall.h>
0010 #include <time.h>
0011 #include <unistd.h>
0012 #include <linux/futex.h>
0013
0014 #include "utils.h"
0015
0016 #define ITERATIONS 100000000
0017
0018 #define futex(A, B, C, D, E, F) syscall(__NR_futex, A, B, C, D, E, F)
0019
0020 int test_futex(void)
0021 {
0022 struct timespec ts_start, ts_end;
0023 unsigned long i = ITERATIONS;
0024
0025 clock_gettime(CLOCK_MONOTONIC, &ts_start);
0026
0027 while (i--) {
0028 unsigned int addr = 0;
0029 futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0);
0030 }
0031
0032 clock_gettime(CLOCK_MONOTONIC, &ts_end);
0033
0034 printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
0035
0036 return 0;
0037 }
0038
0039 int main(void)
0040 {
0041 test_harness_set_timeout(300);
0042 return test_harness(test_futex, "futex_bench");
0043 }