[PATCH v2 02/15] score: Add processor mask to/from cpu_set_t

Gedare Bloom gedare at rtems.org
Sun Jul 9 11:49:53 UTC 2017


On Fri, Jul 7, 2017 at 9:54 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> Update #3059.
> ---
>  cpukit/score/Makefile.am                         |  1 +
>  cpukit/score/include/rtems/score/processormask.h | 52 +++++++++++++++-
>  cpukit/score/src/processormaskcopy.c             | 75 ++++++++++++++++++++++++
>  3 files changed, 126 insertions(+), 2 deletions(-)
>  create mode 100644 cpukit/score/src/processormaskcopy.c
>
> diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
> index 46b441737f..1ac7c1545c 100644
> --- a/cpukit/score/Makefile.am
> +++ b/cpukit/score/Makefile.am
> @@ -354,6 +354,7 @@ libscore_a_SOURCES += src/semaphore.c
>  libscore_a_SOURCES += src/smpbarrierwait.c
>  libscore_a_SOURCES += src/kern_tc.c
>  libscore_a_SOURCES += src/libatomic.c
> +libscore_a_SOURCES += src/processormaskcopy.c
>
>  EXTRA_DIST = src/Unlimited.txt
>
> diff --git a/cpukit/score/include/rtems/score/processormask.h b/cpukit/score/include/rtems/score/processormask.h
> index ebf19ca035..27c35d38f1 100644
> --- a/cpukit/score/include/rtems/score/processormask.h
> +++ b/cpukit/score/include/rtems/score/processormask.h
> @@ -25,8 +25,7 @@
>
>  #include <rtems/score/cpu.h>
>
> -#include <sys/_bitset.h>
> -#include <sys/bitset.h>
> +#include <sys/cpuset.h>
>
>  #ifdef __cplusplus
>  extern "C" {
> @@ -105,6 +104,55 @@ RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t(
>    return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32));
>  }
>
> +typedef enum {
> +  PROCESSOR_MASK_COPY_LOSSLESS,
> +  PROCESSOR_MASK_COPY_PARTIAL_LOSS,
> +  PROCESSOR_MASK_COPY_COMPLETE_LOSS,
> +  PROCESSOR_MASK_COPY_INVALID_SIZE
> +} Processor_mask_Copy_status;
> +
> +RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_at_most_partial_loss(
> +  Processor_mask_Copy_status status
> +)
> +{
> +  return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
> +}
> +
> +Processor_mask_Copy_status _Processor_mask_Copy(
> +  long       *dst,
> +  size_t      dst_size,
> +  const long *src,
> +  size_t      src_size
> +);
> +
> +RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(
> +  const Processor_mask *src,
> +  size_t                dst_size,
> +  cpu_set_t            *dst
> +)
> +{
> +  return _Processor_mask_Copy(
> +    &dst->__bits[ 0 ],
> +    dst_size,
> +    &src->__bits[ 0 ],
> +    sizeof( *src )
> +  );
> +}
> +
> +RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
> +  Processor_mask  *dst,
> +  size_t           src_size,
> +  const cpu_set_t *src
> +)
> +{
> +  return _Processor_mask_Copy(
> +    &dst->__bits[ 0 ],
> +    sizeof( *dst ),
> +    &src->__bits[ 0 ],
> +    src_size
> +  );
> +}
> +
>  /** @} */
>
>  #ifdef __cplusplus
> diff --git a/cpukit/score/src/processormaskcopy.c b/cpukit/score/src/processormaskcopy.c
> new file mode 100644
> index 0000000000..bf8082d3c4
> --- /dev/null
> +++ b/cpukit/score/src/processormaskcopy.c
> @@ -0,0 +1,75 @@
> +/**
> + * @file
> + *
> + * @brief Processor Mask Implementation
> + *
> + * @ingroup ScoreProcessorMask
> + */
> +
> +/*
> + * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
> + *
> + *  embedded brains GmbH
> + *  Dornierstr. 4
> + *  82178 Puchheim
> + *  Germany
> + *  <rtems at embedded-brains.de>
> + *
> + * The license and distribution terms for this file may be
> + * found in the file LICENSE in this distribution or at
> + * http://www.rtems.org/license/LICENSE.
> + */
> +
> +#if HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <rtems/score/processormask.h>
> +
> +Processor_mask_Copy_status _Processor_mask_Copy(
> +  long       *dst,
> +  size_t      dst_size,
> +  const long *src,
> +  size_t      src_size
> +)
> +{
> +  long inclusive = 0;
> +  long exclusive = 0;
> +
> +  if ( ( dst_size | src_size ) % sizeof( long ) != 0 ) {
> +    return PROCESSOR_MASK_COPY_INVALID_SIZE;
> +  }

Why is this specified in terms of long when the bit maps are defined
in terms of uint32_t?

> +
> +  while ( dst_size > 0 && src_size > 0 ) {
> +    long bits = *src;
> +
> +    inclusive |= bits;
> +    *dst = bits;
> +    ++dst;
> +    ++src;
> +    dst_size -= sizeof( long );
> +    src_size -= sizeof( long );
> +  }
> +
> +  while ( dst_size > 0 ) {
> +    *dst = 0;
> +    ++dst;
> +    dst_size -= sizeof( long );
> +  }
> +
> +  while ( src_size > 0 ) {
> +    exclusive |= *src;
> +    ++src;
> +    src_size -= sizeof( long );
> +  }
> +
> +  if ( exclusive != 0 ) {
> +    if ( inclusive != 0 ) {
> +      return PROCESSOR_MASK_COPY_PARTIAL_LOSS;
> +    } else {
> +      return PROCESSOR_MASK_COPY_COMPLETE_LOSS;
> +    }
> +  }
> +
> +  return PROCESSOR_MASK_COPY_LOSSLESS;
> +}
> --
> 2.12.3
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list