1 #ifndef FIO_OS_WINDOWS_H
\r
2 #define FIO_OS_WINDOWS_H
\r
4 #include <sys/types.h>
\r
9 #include "../smalloc.h"
\r
10 #include "../file.h"
\r
13 #define FIO_HAVE_ODIRECT
\r
14 #define FIO_HAVE_CPU_AFFINITY
\r
15 #define FIO_HAVE_CHARDEV_SIZE
\r
16 #define FIO_HAVE_FALLOCATE
\r
17 #define FIO_HAVE_FDATASYNC
\r
18 #define FIO_HAVE_WINDOWSAIO
\r
20 #define FIO_USE_GENERIC_RAND
\r
22 #define OS_MAP_ANON MAP_ANON
\r
24 #define OS_CLOCK CLOCK_REALTIME
\r
26 #define FIO_PREFERRED_ENGINE "windowsaio"
\r
28 typedef off_t off64_t;
\r
31 LARGE_INTEGER Length;
\r
32 } GET_LENGTH_INFORMATION;
\r
34 #define IOCTL_DISK_GET_LENGTH_INFO 0x7405C
\r
36 pid_t cygwin_winpid_to_pid(int winpid);
\r
38 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
\r
43 if (f->hFile == NULL) {
\r
44 hFile = CreateFile(f->file_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
\r
45 NULL, OPEN_EXISTING, 0, NULL);
\r
50 GET_LENGTH_INFORMATION info;
\r
54 if (DeviceIoControl(hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &outBytes, NULL))
\r
55 *bytes = info.Length.QuadPart;
\r
59 /* If we were passed a POSIX fd,
\r
60 * close the HANDLE we created via CreateFile */
\r
61 if (hFile != INVALID_HANDLE_VALUE && f->hFile == NULL)
\r
67 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
\r
69 return blockdev_size(f, bytes);
\r
72 static inline int blockdev_invalidate_cache(struct fio_file *f)
\r
74 /* There's no way to invalidate the cache in Windows
\r
75 * so just pretend to succeed */
\r
79 static inline unsigned long long os_phys_mem(void)
\r
81 SYSTEM_INFO sysInfo;
\r
83 GetSystemInfo(&sysInfo);
\r
84 addr = (unsigned long)sysInfo.lpMaximumApplicationAddress;
\r
88 static inline void os_get_tmpdir(char *path, int len)
\r
90 GetTempPath(len, path);
\r
93 typedef DWORD_PTR os_cpu_mask_t;
\r
95 static inline int pid_to_winpid(int pid)
\r
102 allocsize = sizeof(DWORD) * 1024;
\r
105 if (allocsize == outbytes)
\r
108 ids = realloc(ids, allocsize);
\r
109 EnumProcesses(ids, allocsize, &outbytes);
\r
110 } while (allocsize == outbytes);
\r
112 for (int i = 0; i < (outbytes/sizeof(DWORD)); i++) {
\r
113 if (cygwin_winpid_to_pid(ids[i]) == pid) {
\r
123 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
\r
125 int winpid = pid_to_winpid(pid);
\r
126 HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION, TRUE, winpid);
\r
130 BOOL bSuccess = SetProcessAffinityMask(h, cpumask);
\r
132 return (bSuccess)? 0 : -1;
\r
135 static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask)
\r
137 os_cpu_mask_t systemMask;
\r
138 int winpid = pid_to_winpid(pid);
\r
139 HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, winpid);
\r
142 printf("OpenProcess failed!\n");
\r
146 GetProcessAffinityMask(h, mask, &systemMask);
\r
150 static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)
\r
152 *mask ^= 1 << (cpu-1);
\r
155 static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu)
\r
157 *mask |= 1 << (cpu-1);
\r
160 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
\r
166 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
\r
171 #define FIO_MAX_CPUS MAXIMUM_PROCESSORS
\r
174 #define FIO_MADV_FREE MADV_FREE
\r
177 #endif /* FIO_OS_WINDOWS_H */
\r