aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Okunev <hait.08@mail.ru>2017-11-13 23:54:34 +0300
committerBruce A. Mah <bmah@kitchenlab.org>2017-11-13 12:54:34 -0800
commit5b27ea39a72617734373ca1b42c251949f6b51fe (patch)
tree209f0e930578d2edb0e2f3a6414528c5a50c740c
parent480824e3c1c13d3ba9f918235491291b72fd25a1 (diff)
downloadiperf3-5b27ea39a72617734373ca1b42c251949f6b51fe.tar.gz
Implemented -A flag for Windows (#665)
TODO: Need to update some documentation that reflects `-A` is applicable to Windows. @bmah888 to do this.
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rwxr-xr-xsrc/iperf_api.c24
-rw-r--r--src/iperf_config.h.in3
4 files changed, 29 insertions, 2 deletions
diff --git a/configure b/configure
index 045006c..4f5d1f2 100755
--- a/configure
+++ b/configure
@@ -13002,7 +13002,7 @@ fi
# FreeBSD uses cpuset_setaffinity while Linux uses sched_setaffinity.
# Define HAVE_CPU_AFFINITY to indicate the CPU affinity setting as a
# generic concept is available.
-for ac_func in cpuset_setaffinity sched_setaffinity
+for ac_func in cpuset_setaffinity sched_setaffinity SetProcessAffinityMask
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.ac b/configure.ac
index 936ff39..128fa1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,7 +153,7 @@ fi
# FreeBSD uses cpuset_setaffinity while Linux uses sched_setaffinity.
# Define HAVE_CPU_AFFINITY to indicate the CPU affinity setting as a
# generic concept is available.
-AC_CHECK_FUNCS([cpuset_setaffinity sched_setaffinity],
+AC_CHECK_FUNCS([cpuset_setaffinity sched_setaffinity SetProcessAffinityMask],
AC_DEFINE([HAVE_CPU_AFFINITY], [1],
[Have CPU affinity support.]))
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 722af37..b3d8acd 100755
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -62,6 +62,10 @@
#include <sys/cpuset.h>
#endif /* HAVE_CPUSET_SETAFFINITY */
+#if defined(HAVE_SETPROCESSAFFINITYMASK)
+#include <Windows.h>
+#endif /* HAVE_SETPROCESSAFFINITYMASK */
+
#include "net.h"
#include "iperf.h"
#include "iperf_api.h"
@@ -3576,6 +3580,15 @@ iperf_setaffinity(struct iperf_test *test, int affinity)
return -1;
}
return 0;
+#elif defined(HAVE_SETPROCESSAFFINITYMASK)
+ HANDLE process = GetCurrentProcess();
+ DWORD_PTR processAffinityMask = 1 << affinity;
+
+ if (SetProcessAffinityMask(process, processAffinityMask) == 0) {
+ i_errno = IEAFFINITY;
+ return -1;
+ }
+ return 0;
#else /* neither HAVE_SCHED_SETAFFINITY nor HAVE_CPUSET_SETAFFINITY */
i_errno = IEAFFINITY;
return -1;
@@ -3604,6 +3617,17 @@ iperf_clearaffinity(struct iperf_test *test)
return -1;
}
return 0;
+#elif defined(HAVE_SETPROCESSAFFINITYMASK)
+ HANDLE process = GetCurrentProcess();
+ DWORD_PTR processAffinityMask;
+ DWORD_PTR lpSystemAffinityMask;
+
+ if (GetProcessAffinityMask(process, &processAffinityMask, &lpSystemAffinityMask) == 0
+ || SetProcessAffinityMask(process, lpSystemAffinityMask) == 0) {
+ i_errno = IEAFFINITY;
+ return -1;
+ }
+ return 0;
#else /* neither HAVE_SCHED_SETAFFINITY nor HAVE_CPUSET_SETAFFINITY */
i_errno = IEAFFINITY;
return -1;
diff --git a/src/iperf_config.h.in b/src/iperf_config.h.in
index 438d672..2d13f98 100644
--- a/src/iperf_config.h.in
+++ b/src/iperf_config.h.in
@@ -42,6 +42,9 @@
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
+/* Define to 1 if you have the `SetProcessAffinityMask' function. */
+#undef HAVE_SETPROCESSAFFINITYMASK
+
/* Have SO_MAX_PACING_RATE sockopt. */
#undef HAVE_SO_MAX_PACING_RATE