Merge branch 'master' of https://github.com/ben-ihelputech/fio
[fio.git] / os / windows / cpu-affinity.c
index 69997b2417b4a7127c5cb244fded3440b97dfe15..7601970fc7c284bd120d0ed1b6637ed46882dae3 100644 (file)
@@ -2,78 +2,6 @@
 
 #include <windows.h>
 
-#ifdef CONFIG_WINDOWS_XP
-int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
-{
-       HANDLE h;
-       BOOL bSuccess = FALSE;
-
-       h = OpenThread(THREAD_QUERY_INFORMATION | THREAD_SET_INFORMATION, TRUE,
-                      pid);
-       if (h != NULL) {
-               bSuccess = SetThreadAffinityMask(h, cpumask);
-               if (!bSuccess)
-                       log_err("fio_setaffinity failed: failed to set thread affinity (pid %d, mask %.16llx)\n",
-                               pid, cpumask);
-
-               CloseHandle(h);
-       } else {
-               log_err("fio_setaffinity failed: failed to get handle for pid %d\n",
-                       pid);
-       }
-
-       return bSuccess ? 0 : -1;
-}
-
-int fio_getaffinity(int pid, os_cpu_mask_t *mask)
-{
-       os_cpu_mask_t systemMask;
-
-       HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, pid);
-
-       if (h != NULL) {
-               GetProcessAffinityMask(h, mask, &systemMask);
-               CloseHandle(h);
-       } else {
-               log_err("fio_getaffinity failed: failed to get handle for pid %d\n",
-                       pid);
-               return -1;
-       }
-
-       return 0;
-}
-
-void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)
-{
-       *mask &= ~(1ULL << cpu);
-}
-
-void fio_cpu_set(os_cpu_mask_t *mask, int cpu)
-{
-       *mask |= 1ULL << cpu;
-}
-
-int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
-{
-       return (*mask & (1ULL << cpu)) != 0;
-}
-
-int fio_cpu_count(os_cpu_mask_t *mask)
-{
-       return hweight64(*mask);
-}
-
-int fio_cpuset_init(os_cpu_mask_t *mask)
-{
-       *mask = 0;
-       return 0;
-}
-
-int fio_cpuset_exit(os_cpu_mask_t *mask)
-{
-       return 0;
-}
-#else /* CONFIG_WINDOWS_XP */
 /* Return all processors regardless of processor group */
 unsigned int cpus_online(void)
 {
@@ -83,7 +11,7 @@ unsigned int cpus_online(void)
 static void print_mask(os_cpu_mask_t *cpumask)
 {
        for (int i = 0; i < FIO_CPU_MASK_ROWS; i++)
-               dprint(FD_PROCESS, "cpumask[%d]=%lu\n", i, cpumask->row[i]);
+               dprint(FD_PROCESS, "cpumask[%d]=%" PRIu64 "\n", i, cpumask->row[i]);
 }
 
 /* Return the index of the least significant set CPU in cpumask or -1 if no
@@ -99,7 +27,7 @@ int first_set_cpu(os_cpu_mask_t *cpumask)
                int row_first_cpu;
 
                row_first_cpu = __builtin_ffsll(cpumask->row[row]) - 1;
-               dprint(FD_PROCESS, "row_first_cpu=%d cpumask->row[%d]=%lu\n",
+               dprint(FD_PROCESS, "row_first_cpu=%d cpumask->row[%d]=%" PRIu64 "\n",
                       row_first_cpu, row, cpumask->row[row]);
                if (row_first_cpu > -1) {
                        mask_first_cpu = cpus_offset + row_first_cpu;
@@ -136,7 +64,7 @@ static int last_set_cpu(os_cpu_mask_t *cpumask)
                            row_last_cpu++;
                }
 
-               dprint(FD_PROCESS, "row_last_cpu=%d cpumask->row[%d]=%lu\n",
+               dprint(FD_PROCESS, "row_last_cpu=%d cpumask->row[%d]=%" PRIu64 "\n",
                       row_last_cpu, row, cpumask->row[row]);
                if (row_last_cpu > -1) {
                        mask_last_cpu = cpus_offset + row_last_cpu;
@@ -213,13 +141,17 @@ static int mask_to_group_mask(os_cpu_mask_t *cpumask, int *processor_group, uint
                needed_shift = FIO_CPU_MASK_STRIDE - bit_offset;
                needed_mask_shift = FIO_CPU_MASK_STRIDE - needed;
                needed_mask = (uint64_t)-1 >> needed_mask_shift;
-               dprint(FD_PROCESS, "bit_offset=%d end=%d needed=%d needed_shift=%d needed_mask=%ld needed_mask_shift=%d\n", bit_offset, end, needed, needed_shift, needed_mask, needed_mask_shift);
+               dprint(FD_PROCESS,
+                      "bit_offset=%d end=%d needed=%d needed_shift=%d needed_mask=%" PRIu64 "needed_mask_shift=%d\n",
+                      bit_offset, end, needed, needed_shift, needed_mask,
+                      needed_mask_shift);
                group_cpumask |= (cpumask->row[row + 1] & needed_mask) << needed_shift;
        }
        group_cpumask &= (uint64_t)-1 >> (FIO_CPU_MASK_STRIDE - group_size);
 
        /* Return group and mask */
-       dprint(FD_PROCESS, "Returning group=%d group_mask=%lu\n", group, group_cpumask);
+       dprint(FD_PROCESS, "Returning group=%d group_mask=%" PRIu64 "\n",
+              group, group_cpumask);
        *processor_group = group;
        *affinity_mask = group_cpumask;
 
@@ -257,10 +189,8 @@ int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
        if (SetThreadGroupAffinity(handle, &new_group_affinity, NULL) != 0)
                ret = 0;
        else {
-               log_err("fio_setaffinity: failed to set thread affinity "
-                        "(pid %d, group %d, mask %" PRIx64 ", "
-                        "GetLastError=%d)\n", pid, group, group_mask,
-                        GetLastError());
+               log_err("fio_setaffinity: failed to set thread affinity (pid %d, group %d, mask %" PRIx64 ", GetLastError=%lu)\n",
+                       pid, group, group_mask, GetLastError());
                goto err;
        }
 
@@ -319,7 +249,7 @@ int fio_getaffinity(int pid, os_cpu_mask_t *mask)
                goto err;
        }
        if (!GetProcessGroupAffinity(handle, &group_count, current_groups)) {
-               log_err("%s: failed to get single group affinity for pid %d (%d)\n",
+               log_err("%s: failed to get single group affinity for pid %d (%lu)\n",
                        __func__, pid, GetLastError());
                goto err;
        }
@@ -329,7 +259,7 @@ int fio_getaffinity(int pid, os_cpu_mask_t *mask)
                goto err;
        }
        if (!GetProcessAffinityMask(handle, &process_mask, &system_mask)) {
-               log_err("%s: GetProcessAffinityMask() failed for pid\n",
+               log_err("%s: GetProcessAffinityMask() failed for pid %d\n",
                        __func__, pid);
                goto err;
        }
@@ -441,4 +371,3 @@ int fio_cpuset_exit(os_cpu_mask_t *mask)
 {
        return 0;
 }
-#endif /* CONFIG_WINDOWS_XP */