LIBS += -lpthread -ldl
endif
ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
- SOURCE += os/windows/cpu-affinity.c os/windows/posix.c
- WINDOWS_OBJS = os/windows/cpu-affinity.o os/windows/posix.o lib/hweight.o
+ SOURCE += os/windows/cpu-affinity.c os/windows/posix.c os/windows/dlls.c
+ WINDOWS_OBJS = os/windows/cpu-affinity.o os/windows/posix.o os/windows/dlls.o lib/hweight.o
LIBS += -lpthread -lpsapi -lws2_32 -lssp
FIO_CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format
endif
#define DRD_IGNORE_VAR(x) do { } while (0)
#endif
+#ifdef WIN32
+#include "os/os-windows.h"
+#endif
+
#include "fio.h"
#include "smalloc.h"
#include "helper_thread.h"
}
};
struct timespec ts;
- int clk_tck, ret = 0;
+ long clk_tck;
+ int ret = 0;
-#ifdef _SC_CLK_TCK
- clk_tck = sysconf(_SC_CLK_TCK);
-#else
- /*
- * The timer frequence is variable on Windows. Instead of trying to
- * query it, use 64 Hz, the clock frequency lower bound. See also
- * https://carpediemsystems.co.uk/2019/07/18/windows-system-timer-granularity/.
- */
- clk_tck = 64;
-#endif
- dprint(FD_HELPERTHREAD, "clk_tck = %d\n", clk_tck);
+ os_clk_tck(&clk_tck);
+
+ dprint(FD_HELPERTHREAD, "clk_tck = %ld\n", clk_tck);
assert(clk_tck > 0);
sleep_accuracy_ms = (1000 + clk_tck - 1) / clk_tck;
# define fio_mkdir(path, mode) mkdir(path, mode)
#endif
+#ifdef _SC_CLK_TCK
+static inline void os_clk_tck(long *clk_tck)
+{
+ *clk_tck = sysconf(_SC_CLK_TCK);
+}
+#else
+extern void os_clk_tck(long *clk_tck);
+#endif
+
#endif /* FIO_OS_H */
--- /dev/null
+#include "os/os.h"
+
+#include <windows.h>
+
+void os_clk_tck(long *clk_tck)
+{
+ /*
+ * The timer resolution is variable on Windows. Try to query it
+ * or use 64 Hz, the clock frequency lower bound. See also
+ * https://carpediemsystems.co.uk/2019/07/18/windows-system-timer-granularity/.
+ */
+ unsigned long minRes, maxRes, curRes;
+ HMODULE lib;
+ FARPROC queryTimer;
+ FARPROC setTimer;
+
+ if (!(lib = LoadLibrary(TEXT("ntdll.dll"))) ||
+ !(queryTimer = GetProcAddress(lib, "NtQueryTimerResolution")) ||
+ !(setTimer = GetProcAddress(lib, "NtSetTimerResolution"))) {
+ dprint(FD_HELPERTHREAD,
+ "Failed to load ntdll library, set to lower bound 64 Hz\n");
+ *clk_tck = 64;
+ } else {
+ queryTimer(&minRes, &maxRes, &curRes);
+ dprint(FD_HELPERTHREAD,
+ "minRes = %lu, maxRes = %lu, curRes = %lu\n",
+ minRes, maxRes, curRes);
+
+ /* Use maximum resolution for most accurate timestamps */
+ setTimer(maxRes, 1, &curRes);
+ *clk_tck = (long) (10000000L / maxRes);
+ }
+}
\ No newline at end of file
#include "zbd.h"
#include "oslib/asprintf.h"
+#ifdef WIN32
+#define LOG_MSEC_SLACK 2
+#else
#define LOG_MSEC_SLACK 1
+#endif
struct fio_sem *stat_sem;