score: Add processor mask to/from cpu_set_t

Update #3059.
This commit is contained in:
Sebastian Huber
2017-07-06 15:29:27 +02:00
parent 3dfe55ee15
commit 7a5e4d9477
3 changed files with 126 additions and 2 deletions
+1
View File
@@ -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
@@ -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
+75
View File
@@ -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@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;
}
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;
}