From 7a5e4d94774d2cbfeb96664ed7295f20b8618fe8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 3 Jul 2017 13:14:35 +0200 Subject: score: Add processor mask to/from cpu_set_t 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 (limited to 'cpukit/score') 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 -#include -#include +#include #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 + * + * + * 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 + +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; + } + + 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; +} -- cgit v1.2.3