18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#define _GNU_SOURCE 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <stdio.h> 98c2ecf20Sopenharmony_ci#include <sys/syscall.h> 108c2ecf20Sopenharmony_ci#include <time.h> 118c2ecf20Sopenharmony_ci#include <unistd.h> 128c2ecf20Sopenharmony_ci#include <linux/futex.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "utils.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define ITERATIONS 100000000 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define futex(A, B, C, D, E, F) syscall(__NR_futex, A, B, C, D, E, F) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciint test_futex(void) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci struct timespec ts_start, ts_end; 238c2ecf20Sopenharmony_ci unsigned long i = ITERATIONS; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &ts_start); 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci while (i--) { 288c2ecf20Sopenharmony_ci unsigned int addr = 0; 298c2ecf20Sopenharmony_ci futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0); 308c2ecf20Sopenharmony_ci } 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &ts_end); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci return 0; 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciint main(void) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci test_harness_set_timeout(300); 428c2ecf20Sopenharmony_ci return test_harness(test_futex, "futex_bench"); 438c2ecf20Sopenharmony_ci} 44