Thanks Justin.

I've been away from civilization for a week (a vacation plus a
malfunctioning laptop) so hopefully I'll be able to commit your patch
tomorrow.

The patch looks good and correct..

--
Nadav Har'El
n...@scylladb.com

On Thu, Aug 18, 2016 at 3:30 PM, Justin Cinkelj <justin.cink...@xlab.si>
wrote:

> 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 <justin.cink...@xlab.si>
> ---
>  include/api/sched.h | 12 ++++--------
>  libc/pthread.cc     |  2 +-
>  2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/include/api/sched.h b/include/api/sched.h
> index 14f24de..925ea98 100644
> --- 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
> index 1e6d357..ac7b3f0 100644
> --- 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;
> --
> 2.5.5
>
> --
> 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 osv-dev+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to