#include <sys/types.h>\r
#include <errno.h>\r
#include <windows.h>\r
+#include <psapi.h>\r
\r
#include "../smalloc.h"\r
#include "../file.h"\r
#include "../log.h"\r
\r
#define FIO_HAVE_ODIRECT\r
-#define FIO_USE_GENERIC_RAND\r
+#define FIO_HAVE_CPU_AFFINITY\r
#define FIO_HAVE_CHARDEV_SIZE\r
-#define FIO_USE_GENERIC_RAND\r
-\r
#define FIO_HAVE_FALLOCATE\r
#define FIO_HAVE_FDATASYNC\r
#define FIO_HAVE_WINDOWSAIO\r
\r
+#define FIO_USE_GENERIC_RAND\r
+\r
#define OS_MAP_ANON MAP_ANON\r
\r
#define OS_CLOCK CLOCK_REALTIME\r
\r
#define IOCTL_DISK_GET_LENGTH_INFO 0x7405C\r
\r
+pid_t cygwin_winpid_to_pid(int winpid);\r
+\r
static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)\r
{\r
int rc = 0;\r
GetTempPath(len, path);\r
}\r
\r
+typedef DWORD_PTR os_cpu_mask_t;\r
+\r
+static inline int pid_to_winpid(int pid)\r
+{\r
+ int winpid = 0;\r
+ DWORD outbytes = 0;\r
+ DWORD *ids = NULL;\r
+ size_t allocsize;\r
+ \r
+ allocsize = sizeof(DWORD) * 1024;\r
+ \r
+ do {\r
+ if (allocsize == outbytes)\r
+ allocsize *= 2;\r
+\r
+ ids = realloc(ids, allocsize);\r
+ EnumProcesses(ids, allocsize, &outbytes);\r
+ } while (allocsize == outbytes);\r
+ \r
+ for (int i = 0; i < (outbytes/sizeof(DWORD)); i++) {\r
+ if (cygwin_winpid_to_pid(ids[i]) == pid) {\r
+ winpid = ids[i];\r
+ break;\r
+ }\r
+ }\r
+ \r
+ free(ids);\r
+ return winpid;\r
+}\r
+\r
+static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)\r
+{\r
+ int winpid = pid_to_winpid(pid);\r
+ HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION, TRUE, winpid);\r
+ if (h == NULL)\r
+ return -1;\r
+ \r
+ BOOL bSuccess = SetProcessAffinityMask(h, cpumask);\r
+ CloseHandle(h);\r
+ return (bSuccess)? 0 : -1;\r
+}\r
+\r
+static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask)\r
+{\r
+ os_cpu_mask_t systemMask;\r
+ int winpid = pid_to_winpid(pid);\r
+ HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, winpid);\r
+ if (h == NULL)\r
+ {\r
+ printf("OpenProcess failed!\n");\r
+ return;\r
+ }\r
+ \r
+ GetProcessAffinityMask(h, mask, &systemMask);\r
+ CloseHandle(h);\r
+}\r
+\r
+static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)\r
+{\r
+ *mask ^= 1 << (cpu-1);\r
+}\r
+\r
+static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu)\r
+{\r
+ *mask |= 1 << (cpu-1);\r
+}\r
+\r
+static inline int fio_cpuset_init(os_cpu_mask_t *mask)\r
+{\r
+ *mask = 0;\r
+ return 0;\r
+}\r
+\r
+static inline int fio_cpuset_exit(os_cpu_mask_t *mask)\r
+{\r
+ return 0;\r
+}\r
+\r
+#define FIO_MAX_CPUS MAXIMUM_PROCESSORS\r
+\r
#ifdef MADV_FREE\r
#define FIO_MADV_FREE MADV_FREE\r
#endif\r