From 7037b833e175aae32900b73bf597aad08c1d8472 Mon Sep 17 00:00:00 2001 From: Vincent Fu Date: Mon, 23 Jun 2025 12:29:43 -0400 Subject: [PATCH] windows: drop nanosleep and clock_gettime Cygwin and msys2 now provide nanosleep and clock_gettime, so fio no longer needs to implement them. The presence of our implementations was triggering build failures: https://github.com/axboe/fio/actions/runs/15828051168 Since fio no longer provides clock_gettime, stop unconditionally setting clock_gettime and clock_monotonic to yes on Windows and start detectinga these features at build time. These two features are successfully detected by our configure script: https://github.com/vincentkfu/fio/actions/runs/15832278184 Signed-off-by: Vincent Fu --- configure | 2 -- os/os-windows.h | 1 - os/windows/posix.c | 72 ---------------------------------------------- os/windows/posix.h | 1 - 4 files changed, 76 deletions(-) diff --git a/configure b/configure index 986eb0a6..9e69dc4b 100755 --- a/configure +++ b/configure @@ -462,8 +462,6 @@ CYGWIN*) build_static="yes" rusage_thread="yes" fdatasync="yes" - clock_gettime="yes" # clock_monotonic probe has dependency on this - clock_monotonic="yes" sched_idle="yes" pthread_condattr_setclock="no" pthread_affinity="no" diff --git a/os/os-windows.h b/os/os-windows.h index 12f33486..909c12e3 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -106,7 +106,6 @@ int fdatasync(int fildes); int lstat(const char * path, struct stat * buf); uid_t geteuid(void); char* ctime_r(const time_t *t, char *buf); -int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset); ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset); diff --git a/os/windows/posix.c b/os/windows/posix.c index 3e48c3ff..4c692a1e 100644 --- a/os/windows/posix.c +++ b/os/windows/posix.c @@ -549,50 +549,6 @@ return 0; #define CLOCK_MONOTONIC_RAW 4 #endif -/* - * Get the value of a local clock source. - * This implementation supports 3 clocks: CLOCK_MONOTONIC/CLOCK_MONOTONIC_RAW - * provide high-accuracy relative time, while CLOCK_REALTIME provides a - * low-accuracy wall time. - */ -int clock_gettime(clockid_t clock_id, struct timespec *tp) -{ - int rc = 0; - - if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_MONOTONIC_RAW) { - static LARGE_INTEGER freq = {{0,0}}; - LARGE_INTEGER counts; - uint64_t t; - - QueryPerformanceCounter(&counts); - if (freq.QuadPart == 0) - QueryPerformanceFrequency(&freq); - - tp->tv_sec = counts.QuadPart / freq.QuadPart; - /* Get the difference between the number of ns stored - * in 'tv_sec' and that stored in 'counts' */ - t = tp->tv_sec * freq.QuadPart; - t = counts.QuadPart - t; - /* 't' now contains the number of cycles since the last second. - * We want the number of nanoseconds, so multiply out by 1,000,000,000 - * and then divide by the frequency. */ - t *= 1000000000; - tp->tv_nsec = t / freq.QuadPart; - } else if (clock_id == CLOCK_REALTIME) { - /* clock_gettime(CLOCK_REALTIME,...) is just an alias for gettimeofday with a - * higher-precision field. */ - struct timeval tv; - gettimeofday(&tv, NULL); - tp->tv_sec = tv.tv_sec; - tp->tv_nsec = tv.tv_usec * 1000; - } else { - errno = EINVAL; - rc = -1; - } - - return rc; -} - int mlock(const void * addr, size_t len) { SIZE_T min, max; @@ -937,34 +893,6 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) return rc; } -int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) -{ - struct timespec tv; - DWORD ms_remaining; - DWORD ms_total = (rqtp->tv_sec * 1000) + (rqtp->tv_nsec / 1000000.0); - - if (ms_total == 0) - ms_total = 1; - - ms_remaining = ms_total; - - /* Since Sleep() can sleep for less than the requested time, add a loop to - ensure we only return after the requested length of time has elapsed */ - do { - fio_gettime(&tv, NULL); - Sleep(ms_remaining); - ms_remaining = ms_total - mtime_since_now(&tv); - } while (ms_remaining > 0 && ms_remaining < ms_total); - - /* this implementation will never sleep for less than the requested time */ - if (rmtp != NULL) { - rmtp->tv_sec = 0; - rmtp->tv_nsec = 0; - } - - return 0; -} - DIR *opendir(const char *dirname) { struct dirent_ctx *dc = NULL; diff --git a/os/windows/posix.h b/os/windows/posix.h index 02a9075b..afb00d5a 100644 --- a/os/windows/posix.h +++ b/os/windows/posix.h @@ -3,7 +3,6 @@ typedef int clockid_t; -extern int clock_gettime(clockid_t clock_id, struct timespec *tp); extern int inet_aton(const char *, struct in_addr *); extern int win_to_posix_error(DWORD winerr); -- 2.25.1