1 #ifndef FIO_OS_WINDOWS_H
\r
2 #define FIO_OS_WINDOWS_H
\r
4 #define FIO_OS os_windows
\r
6 #include <sys/types.h>
\r
12 #include "../smalloc.h"
\r
13 #include "../file.h"
\r
16 #define FIO_HAVE_ODIRECT
\r
17 #define FIO_HAVE_CPU_AFFINITY
\r
18 #define FIO_HAVE_CHARDEV_SIZE
\r
19 #define FIO_HAVE_FALLOCATE
\r
20 #define FIO_HAVE_FDATASYNC
\r
21 #define FIO_HAVE_WINDOWSAIO
\r
22 #define FIO_HAVE_GETTID
\r
24 #define FIO_USE_GENERIC_RAND
\r
26 #define OS_MAP_ANON MAP_ANON
\r
28 #define OS_CLOCK CLOCK_REALTIME
\r
30 #define FIO_PREFERRED_ENGINE "windowsaio"
\r
32 #define FIO_LITTLE_ENDIAN
\r
33 #define fio_swap16(x) _byteswap_ushort(x)
\r
34 #define fio_swap32(x) _byteswap_ulong(x)
\r
35 #define fio_swap64(x) _byteswap_uint64(x)
\r
37 typedef off_t off64_t;
\r
40 LARGE_INTEGER Length;
\r
41 } GET_LENGTH_INFORMATION;
\r
43 #define IOCTL_DISK_GET_LENGTH_INFO 0x7405C
\r
45 pid_t cygwin_winpid_to_pid(int winpid);
\r
47 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
\r
52 if (f->hFile == NULL) {
\r
53 hFile = CreateFile(f->file_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
\r
54 NULL, OPEN_EXISTING, 0, NULL);
\r
59 GET_LENGTH_INFORMATION info;
\r
63 if (DeviceIoControl(hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &outBytes, NULL))
\r
64 *bytes = info.Length.QuadPart;
\r
68 /* If we were passed a POSIX fd,
\r
69 * close the HANDLE we created via CreateFile */
\r
70 if (hFile != INVALID_HANDLE_VALUE && f->hFile == NULL)
\r
76 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
\r
78 return blockdev_size(f, bytes);
\r
81 static inline int blockdev_invalidate_cache(struct fio_file *f)
\r
83 /* There's no way to invalidate the cache in Windows
\r
84 * so just pretend to succeed */
\r
88 static inline unsigned long long os_phys_mem(void)
\r
90 SYSTEM_INFO sysInfo;
\r
92 GetSystemInfo(&sysInfo);
\r
93 addr = (unsigned long)sysInfo.lpMaximumApplicationAddress;
\r
97 static inline void os_get_tmpdir(char *path, int len)
\r
99 GetTempPath(len, path);
\r
102 typedef DWORD_PTR os_cpu_mask_t;
\r
104 static inline int gettid(void)
\r
106 return GetCurrentThreadId();
\r
109 static inline int pid_to_winpid(int pid)
\r
112 DWORD outbytes = 0;
\r
116 allocsize = sizeof(DWORD) * 1024;
\r
119 if (allocsize == outbytes)
\r
122 ids = realloc(ids, allocsize);
\r
123 EnumProcesses(ids, allocsize, &outbytes);
\r
124 } while (allocsize == outbytes);
\r
126 for (int i = 0; i < (outbytes/sizeof(DWORD)); i++) {
\r
127 if (cygwin_winpid_to_pid(ids[i]) == pid) {
\r
137 HANDLE WINAPI OpenThread(
\r
138 DWORD dwDesiredAccess,
\r
139 BOOL bInheritHandle,
\r
142 DWORD WINAPI GetProcessIdOfThread(HANDLE Thread);
\r
144 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
\r
150 h = OpenThread(THREAD_QUERY_INFORMATION | THREAD_SET_INFORMATION, TRUE, pid);
\r
152 bSuccess = SetThreadAffinityMask(h, cpumask);
\r
154 // then we might have a process id instead of a thread id
\r
155 winpid = pid_to_winpid(pid);
\r
156 h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION, TRUE, winpid);
\r
160 bSuccess = SetProcessAffinityMask(h, cpumask);
\r
165 return (bSuccess)? 0 : -1;
\r
168 static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask)
\r
170 os_cpu_mask_t systemMask;
\r
173 HANDLE h = OpenThread(THREAD_QUERY_INFORMATION, TRUE, pid);
\r
175 winpid = GetProcessIdOfThread(h);
\r
177 winpid = pid_to_winpid(pid);
\r
179 h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, winpid);
\r
182 GetProcessAffinityMask(h, mask, &systemMask);
\r
185 fprintf(stderr, "fio_getaffinity failed: failed to get handle for pid %d\n", pid);
\r
190 static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)
\r
192 *mask ^= 1 << (cpu-1);
\r
195 static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu)
\r
197 *mask |= 1 << (cpu-1);
\r
200 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
\r
206 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
\r
211 #define FIO_MAX_CPUS MAXIMUM_PROCESSORS
\r
214 #define FIO_MADV_FREE MADV_FREE
\r
217 #endif /* FIO_OS_WINDOWS_H */
\r