[Openmp-commits] [PATCH] D51944: openmp: Use glibc wrappers for accessing cpu affinity mask
Tom Stellard via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Wed Sep 12 20:58:57 PDT 2018
tstellar updated this revision to Diff 165199.
tstellar added a comment.
Is this more what you had in mind?
Repository:
rOMP OpenMP
https://reviews.llvm.org/D51944
Files:
runtime/src/kmp.h
runtime/src/kmp_affinity.h
Index: runtime/src/kmp_affinity.h
===================================================================
--- runtime/src/kmp_affinity.h
+++ runtime/src/kmp_affinity.h
@@ -237,12 +237,12 @@
#endif /* KMP_ARCH_* */
class KMPNativeAffinity : public KMPAffinity {
class Mask : public KMPAffinity::Mask {
- typedef unsigned char mask_t;
+ typedef unsigned long mask_t;
static const int BITS_PER_MASK_T = sizeof(mask_t) * CHAR_BIT;
public:
mask_t *mask;
- Mask() { mask = (mask_t *)__kmp_allocate(__kmp_affin_mask_size); }
+ Mask() { mask = (mask_t *)__kmp_allocate(sizeof(mask_t) * __kmp_affin_mask_size); }
~Mask() {
if (mask)
__kmp_free(mask);
@@ -296,7 +296,7 @@
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
"Illegal get affinity operation when not capable");
int retval =
- syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask);
+ syscall(__NR_sched_getaffinity, 0, sizeof(mask_t) * __kmp_affin_mask_size, mask);
if (retval >= 0) {
return 0;
}
@@ -310,7 +310,7 @@
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
"Illegal get affinity operation when not capable");
int retval =
- syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask);
+ syscall(__NR_sched_setaffinity, 0, sizeof(mask_t) * __kmp_affin_mask_size, mask);
if (retval >= 0) {
return 0;
}
Index: runtime/src/kmp.h
===================================================================
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -596,7 +596,11 @@
extern size_t __kmp_affin_mask_size;
#define KMP_AFFINITY_CAPABLE() (__kmp_affin_mask_size > 0)
#define KMP_AFFINITY_DISABLE() (__kmp_affin_mask_size = 0)
-#define KMP_AFFINITY_ENABLE(mask_size) (__kmp_affin_mask_size = mask_size)
+// Round to the nearest multiple of sizeof(unsigned long), which is the
+// size of mask_t.
+#define KMP_AFFINITY_ENABLE(mask_size) \
+ (__kmp_affin_mask_size = ((mask_size + sizeof(unsigned long) - 1) & \
+ ~(sizeof(unsigned long)-1)))
#define KMP_CPU_SET_ITERATE(i, mask) \
for (i = (mask)->begin(); (int)i != (mask)->end(); i = (mask)->next(i))
#define KMP_CPU_SET(i, mask) (mask)->set(i)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51944.165199.patch
Type: text/x-patch
Size: 2313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20180913/70cd0057/attachment.bin>
More information about the Openmp-commits
mailing list