summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/src/z_Windows_NT_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/runtime/src/z_Windows_NT_util.c')
-rw-r--r--openmp/runtime/src/z_Windows_NT_util.c239
1 files changed, 8 insertions, 231 deletions
diff --git a/openmp/runtime/src/z_Windows_NT_util.c b/openmp/runtime/src/z_Windows_NT_util.c
index 53b8eb8d746..8daa7d51993 100644
--- a/openmp/runtime/src/z_Windows_NT_util.c
+++ b/openmp/runtime/src/z_Windows_NT_util.c
@@ -18,6 +18,7 @@
#include "kmp_i18n.h"
#include "kmp_io.h"
#include "kmp_wait_release.h"
+#include "kmp_affinity.h"
/* This code is related to NtQuerySystemInformation() function. This function
is used in the Load balance algorithm for OMP_DYNAMIC=true to find the
@@ -127,9 +128,7 @@ HMODULE ntdll = NULL;
/* End of NtQuerySystemInformation()-related code */
-#if KMP_GROUP_AFFINITY
static HMODULE kernel32 = NULL;
-#endif /* KMP_GROUP_AFFINITY */
/* ----------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------- */
@@ -542,227 +541,9 @@ __kmp_gtid_get_specific()
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
-#if KMP_GROUP_AFFINITY
-
-//
-// Only 1 DWORD in the mask should have any procs set.
-// Return the appropriate index, or -1 for an invalid mask.
-//
-int
-__kmp_get_proc_group( kmp_affin_mask_t const *mask )
-{
- int i;
- int group = -1;
- for (i = 0; i < __kmp_num_proc_groups; i++) {
-#if KMP_USE_HWLOC
- // On windows, the long type is always 32 bits
- unsigned long first_32_bits = hwloc_bitmap_to_ith_ulong((hwloc_const_bitmap_t)mask, i*2);
- unsigned long second_32_bits = hwloc_bitmap_to_ith_ulong((hwloc_const_bitmap_t)mask, i*2+1);
- if (first_32_bits == 0 && second_32_bits == 0) {
- continue;
- }
-#else
- if (mask[i] == 0) {
- continue;
- }
-#endif
- if (group >= 0) {
- return -1;
- }
- group = i;
- }
- return group;
-}
-
-#endif /* KMP_GROUP_AFFINITY */
-
-int
-__kmp_set_system_affinity( kmp_affin_mask_t const *mask, int abort_on_error )
-{
-#if KMP_USE_HWLOC
- int retval = hwloc_set_cpubind(__kmp_hwloc_topology, (hwloc_cpuset_t)mask, HWLOC_CPUBIND_THREAD);
- if (retval >= 0) {
- return 0;
- }
- int error = errno;
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( FatalSysError ),
- KMP_ERR( error ),
- __kmp_msg_null
- );
- }
- return error;
-#else
-# if KMP_GROUP_AFFINITY
-
- if (__kmp_num_proc_groups > 1) {
- //
- // Check for a valid mask.
- //
- GROUP_AFFINITY ga;
- int group = __kmp_get_proc_group( mask );
- if (group < 0) {
- if (abort_on_error) {
- KMP_FATAL(AffinityInvalidMask, "kmp_set_affinity");
- }
- return -1;
- }
-
- //
- // Transform the bit vector into a GROUP_AFFINITY struct
- // and make the system call to set affinity.
- //
- ga.Group = group;
- ga.Mask = mask[group];
- ga.Reserved[0] = ga.Reserved[1] = ga.Reserved[2] = 0;
-
- KMP_DEBUG_ASSERT(__kmp_SetThreadGroupAffinity != NULL);
- if (__kmp_SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL) == 0) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( CantSetThreadAffMask ),
- KMP_ERR( error ),
- __kmp_msg_null
- );
- }
- return error;
- }
- }
- else
-
-# endif /* KMP_GROUP_AFFINITY */
-
- {
- if (!SetThreadAffinityMask( GetCurrentThread(), *mask )) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( CantSetThreadAffMask ),
- KMP_ERR( error ),
- __kmp_msg_null
- );
- }
- return error;
- }
- }
-#endif /* KMP_USE_HWLOC */
- return 0;
-}
-
-int
-__kmp_get_system_affinity( kmp_affin_mask_t *mask, int abort_on_error )
-{
-#if KMP_USE_HWLOC
- int retval = hwloc_get_cpubind(__kmp_hwloc_topology, (hwloc_cpuset_t)mask, HWLOC_CPUBIND_THREAD);
- if (retval >= 0) {
- return 0;
- }
- int error = errno;
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( FatalSysError ),
- KMP_ERR( error ),
- __kmp_msg_null
- );
- }
- return error;
-#else /* KMP_USE_HWLOC */
-# if KMP_GROUP_AFFINITY
-
- if (__kmp_num_proc_groups > 1) {
- KMP_CPU_ZERO(mask);
- GROUP_AFFINITY ga;
- KMP_DEBUG_ASSERT(__kmp_GetThreadGroupAffinity != NULL);
-
- if (__kmp_GetThreadGroupAffinity(GetCurrentThread(), &ga) == 0) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG(FunctionError, "GetThreadGroupAffinity()"),
- KMP_ERR(error),
- __kmp_msg_null
- );
- }
- return error;
- }
-
- if ((ga.Group < 0) || (ga.Group > __kmp_num_proc_groups)
- || (ga.Mask == 0)) {
- return -1;
- }
-
- mask[ga.Group] = ga.Mask;
- }
- else
-
-# endif /* KMP_GROUP_AFFINITY */
-
- {
- kmp_affin_mask_t newMask, sysMask, retval;
-
- if (!GetProcessAffinityMask(GetCurrentProcess(), &newMask, &sysMask)) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG(FunctionError, "GetProcessAffinityMask()"),
- KMP_ERR(error),
- __kmp_msg_null
- );
- }
- return error;
- }
- retval = SetThreadAffinityMask(GetCurrentThread(), newMask);
- if (! retval) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG(FunctionError, "SetThreadAffinityMask()"),
- KMP_ERR(error),
- __kmp_msg_null
- );
- }
- return error;
- }
- newMask = SetThreadAffinityMask(GetCurrentThread(), retval);
- if (! newMask) {
- DWORD error = GetLastError();
- if (abort_on_error) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG(FunctionError, "SetThreadAffinityMask()"),
- KMP_ERR(error),
- __kmp_msg_null
- );
- }
- }
- *mask = retval;
- }
-#endif /* KMP_USE_HWLOC */
- return 0;
-}
-
void
__kmp_affinity_bind_thread( int proc )
{
-#if KMP_USE_HWLOC
- kmp_affin_mask_t *mask;
- KMP_CPU_ALLOC_ON_STACK(mask);
- KMP_CPU_ZERO(mask);
- KMP_CPU_SET(proc, mask);
- __kmp_set_system_affinity(mask, TRUE);
- KMP_CPU_FREE_FROM_STACK(mask);
-#else /* KMP_USE_HWLOC */
-# if KMP_GROUP_AFFINITY
-
if (__kmp_num_proc_groups > 1) {
//
// Form the GROUP_AFFINITY struct directly, rather than filling
@@ -787,18 +568,14 @@ __kmp_affinity_bind_thread( int proc )
);
}
}
+ } else {
+ kmp_affin_mask_t *mask;
+ KMP_CPU_ALLOC_ON_STACK(mask);
+ KMP_CPU_ZERO(mask);
+ KMP_CPU_SET(proc, mask);
+ __kmp_set_system_affinity(mask, TRUE);
+ KMP_CPU_FREE_FROM_STACK(mask);
}
- else
-
-# endif /* KMP_GROUP_AFFINITY */
-
- {
- kmp_affin_mask_t mask;
- KMP_CPU_ZERO(&mask);
- KMP_CPU_SET(proc, &mask);
- __kmp_set_system_affinity(&mask, TRUE);
- }
-#endif /* KMP_USE_HWLOC */
}
void
OpenPOWER on IntegriCloud