From: Justin Cinkelj <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master
libc: add CPU_COUNT_S
CPU set allocated dynamically with CPU_ALLOC_SIZE has to be processed with
_S set of macros (e.g. CPU_COUNT_S instead of CPU_COUNT). Open MPI uses
dynamic CPU sets, hence the need to implement such macros. As only
CPU_COUNT_S is actually needed, only that one is implemented here.
The setaffinity function from 705f9cf96cd47a5e0916e2d8641a0ab1d2743c8c
missed to use CPU_COUNT_S on (possibly) dinamically allocated CPU set.
This is fixed here too.
Refs #776.
Signed-off-by: Justin Cinkelj <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Nadav Har'El <[email protected]>
---
diff --git a/include/api/sched.h b/include/api/sched.h
--- a/include/api/sched.h
+++ b/include/api/sched.h
@@ -83,6 +83,8 @@ typedef struct {
__cpu_mask __bits[_NCPUWORDS];
} cpu_set_t;
+int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp);
+
inline static void CPU_ZERO(cpu_set_t *cpuset) {
size_t i;
for (i = 0; i < _NCPUWORDS; i++) {
@@ -118,14 +120,8 @@ inline static int CPU_ISSET(size_t n, const cpu_set_t
*cpuset) {
return (cpuset->__bits[__cpuset_word(n)] & __cpuset_mask(n)) != 0;
}
-inline static int CPU_COUNT(const cpu_set_t *cpuset) {
- size_t i;
- int count = 0;
- for (i = 0; i < _NCPUWORDS; i++) {
- count += __builtin_popcountl(cpuset->__bits[i]);
- }
- return count;
-}
+#define CPU_COUNT_S(setsize, cpuset) __sched_cpucount(setsize, cpuset)
+#define CPU_COUNT(cpuset) __sched_cpucount(_NCPUWORDS*sizeof (__cpu_mask),
cpuset)
inline static size_t CPU_ALLOC_SIZE(size_t count) {
return ((count + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask);
diff --git a/libc/pthread.cc b/libc/pthread.cc
--- a/libc/pthread.cc
+++ b/libc/pthread.cc
@@ -943,7 +943,7 @@ int pthread_attr_setaffinity_np(pthread_attr_t *attr,
size_t cpusetsize,
static int setaffinity(sched::thread* t, size_t cpusetsize,
const cpu_set_t *cpuset)
{
- int count = CPU_COUNT(cpuset);
+ int count = CPU_COUNT_S(cpusetsize, cpuset);
if (count == 0) {
// Having a cpuset with no CPUs in it is invalid.
return EINVAL;
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.