futex_bench.c 834 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #define _GNU_SOURCE
  6. #include <stdio.h>
  7. #include <sys/syscall.h>
  8. #include <time.h>
  9. #include <unistd.h>
  10. #include <linux/futex.h>
  11. #include "utils.h"
  12. #define ITERATIONS 100000000
  13. #define futex(A, B, C, D, E, F) syscall(__NR_futex, A, B, C, D, E, F)
  14. int test_futex(void)
  15. {
  16. struct timespec ts_start, ts_end;
  17. unsigned long i = ITERATIONS;
  18. clock_gettime(CLOCK_MONOTONIC, &ts_start);
  19. while (i--) {
  20. unsigned int addr = 0;
  21. futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0);
  22. }
  23. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  24. printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
  25. return 0;
  26. }
  27. int main(void)
  28. {
  29. test_harness_set_timeout(300);
  30. return test_harness(test_futex, "futex_bench");
  31. }