diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-07-03 11:46:12 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-07-06 15:29:16 +0200 |
commit | 3dfe55ee154b6053e936e7b458206b71aad51caa (patch) | |
tree | b455d560a13cccc855c3259c67f3fafa20f4fb97 /cpukit | |
parent | xz: Suppress attribute warnings (diff) | |
download | rtems-3dfe55ee154b6053e936e7b458206b71aad51caa.tar.bz2 |
score: Use <sys/bitset.h> for Processor_mask
Implement the Processor_mask via <sys/bitset.h>. Provide
_Processor_mask_To_uint32_t() to enable its use in device specific
routines, e.g. interrupt affinity register in an interrupt controller.
Update #3059.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/libdrvmgr/drvmgr.h | 4 | ||||
-rw-r--r-- | cpukit/libdrvmgr/drvmgr_drvinf.c | 2 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/processormask.h | 91 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/smpimpl.h | 4 | ||||
-rw-r--r-- | cpukit/score/src/smp.c | 8 | ||||
-rw-r--r-- | cpukit/score/src/smpmulticastaction.c | 16 |
6 files changed, 59 insertions, 66 deletions
diff --git a/cpukit/libdrvmgr/drvmgr.h b/cpukit/libdrvmgr/drvmgr.h index a8e1c8c311..cb8f4a5f5a 100644 --- a/cpukit/libdrvmgr/drvmgr.h +++ b/cpukit/libdrvmgr/drvmgr.h @@ -140,7 +140,7 @@ struct drvmgr_bus_ops { int (*int_unmask)(struct drvmgr_dev *, int index); #ifdef RTEMS_SMP int (*int_set_affinity)(struct drvmgr_dev *, int index, - Processor_mask cpus); + const Processor_mask *cpus); #endif /* Get Parameters */ @@ -645,7 +645,7 @@ extern int drvmgr_interrupt_mask( extern int drvmgr_interrupt_set_affinity( struct drvmgr_dev *dev, int index, - Processor_mask cpus); + const Processor_mask *cpus); #endif /*! drvmgr_translate() translation options */ diff --git a/cpukit/libdrvmgr/drvmgr_drvinf.c b/cpukit/libdrvmgr/drvmgr_drvinf.c index 5bb6e6edbf..346a66fef9 100644 --- a/cpukit/libdrvmgr/drvmgr_drvinf.c +++ b/cpukit/libdrvmgr/drvmgr_drvinf.c @@ -142,7 +142,7 @@ int drvmgr_interrupt_mask( int drvmgr_interrupt_set_affinity( struct drvmgr_dev *dev, int index, - Processor_mask cpus) + const Processor_mask *cpus) { if (!dev || !dev->parent || !dev->parent->ops->int_set_affinity) return -1; diff --git a/cpukit/score/include/rtems/score/processormask.h b/cpukit/score/include/rtems/score/processormask.h index 8ee869a895..ebf19ca035 100644 --- a/cpukit/score/include/rtems/score/processormask.h +++ b/cpukit/score/include/rtems/score/processormask.h @@ -7,7 +7,7 @@ */ /* - * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * Copyright (c) 2016, 2017 embedded brains GmbH. All rights reserved. * * embedded brains GmbH * Dornierstr. 4 @@ -25,6 +25,9 @@ #include <rtems/score/cpu.h> +#include <sys/_bitset.h> +#include <sys/bitset.h> + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -41,75 +44,65 @@ extern "C" { * @{ */ -#define PROCESSOR_MASK_BITS_PER_FIELD 32 - -#define PROCESSOR_MASK_FIELD_COUNT \ - ( ( CPU_MAXIMUM_PROCESSORS + PROCESSOR_MASK_BITS_PER_FIELD - 1 ) \ - / PROCESSOR_MASK_BITS_PER_FIELD ) - -#define PROCESSOR_MASK_BIT( index ) \ - (1UL << ( ( index ) % PROCESSOR_MASK_BITS_PER_FIELD ) ) - -#define PROCESSOR_MASK_FIELD( index ) \ - ( ( index ) / PROCESSOR_MASK_BITS_PER_FIELD ) - /** - * @brief A bit map consisting of 32-bit integer fields which is large enough - * to provide one bit for each processor in the system. - * - * Processor 0 corresponds to the bit 0 (least-significant) of the field 0 in - * the array, and so on. + * @brief A bit map which is large enough to provide one bit for each processor + * in the system. */ -typedef uint32_t Processor_mask[ PROCESSOR_MASK_FIELD_COUNT ]; +typedef BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask; -RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask mask ) +RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask *mask ) { - size_t i; - - for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) { - mask[ i ] = 0; - } + BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask ); } -RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask mask ) +RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask *mask ) { - size_t i; - - for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) { - if ( mask[ i ] != 0 ) { - return false; - } - } - - return true; + return BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask ); } -RTEMS_INLINE_ROUTINE void _Processor_mask_Assign( Processor_mask dst, const Processor_mask src ) +RTEMS_INLINE_ROUTINE void _Processor_mask_Assign( + Processor_mask *dst, const Processor_mask *src +) { - size_t i; - - for ( i = 0; i < PROCESSOR_MASK_FIELD_COUNT; ++i ) { - dst[ i ] = src[ i ]; - } + BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst ); } -RTEMS_INLINE_ROUTINE void _Processor_mask_Set( Processor_mask mask, uint32_t index ) +RTEMS_INLINE_ROUTINE void _Processor_mask_Set( + Processor_mask *mask, + uint32_t index +) { - mask[ PROCESSOR_MASK_FIELD( index ) ] |= PROCESSOR_MASK_BIT( index ); + BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask ); } -RTEMS_INLINE_ROUTINE void _Processor_mask_Clear( Processor_mask mask, uint32_t index ) +RTEMS_INLINE_ROUTINE void _Processor_mask_Clear( + Processor_mask *mask, + uint32_t index +) { - mask[ PROCESSOR_MASK_FIELD( index ) ] &= ~PROCESSOR_MASK_BIT( index ); + BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask ); } RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set( - const Processor_mask mask, - uint32_t index + const Processor_mask *mask, + uint32_t index +) +{ + return BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask ); +} + +/** + * @brief Returns the subset of 32 processors containing the specified index as + * an unsigned 32-bit integer. + */ +RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t( + const Processor_mask *mask, + uint32_t index ) { - return ( mask[ PROCESSOR_MASK_FIELD( index ) ] - & PROCESSOR_MASK_BIT( index ) ) != 0; + long bits = mask->__bits[ __bitset_words( index ) ]; + + return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32)); } /** @} */ diff --git a/cpukit/score/include/rtems/score/smpimpl.h b/cpukit/score/include/rtems/score/smpimpl.h index f85251e8b0..bc800b9e42 100644 --- a/cpukit/score/include/rtems/score/smpimpl.h +++ b/cpukit/score/include/rtems/score/smpimpl.h @@ -241,8 +241,8 @@ void _SMP_Send_message_broadcast( * @param[in] message The message. */ void _SMP_Send_message_multicast( - const Processor_mask targets, - unsigned long message + const Processor_mask *targets, + unsigned long message ); typedef void ( *SMP_Action_handler )( void *arg ); diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c index 434483c5ad..a69b7ed46a 100644 --- a/cpukit/score/src/smp.c +++ b/cpukit/score/src/smp.c @@ -101,7 +101,7 @@ static void _SMP_Start_processors( uint32_t cpu_count ) cpu->Scheduler.control = scheduler; cpu->Scheduler.context = context; - _Processor_mask_Set( _SMP_Online_processors, cpu_index ); + _Processor_mask_Set( &_SMP_Online_processors, cpu_index ); } } } @@ -217,7 +217,7 @@ void _SMP_Send_message_broadcast( unsigned long message ) for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { if ( cpu_index != cpu_index_self - && _Processor_mask_Is_set( _SMP_Online_processors, cpu_index ) + && _Processor_mask_Is_set( &_SMP_Online_processors, cpu_index ) ) { _SMP_Send_message( cpu_index, message ); } @@ -225,8 +225,8 @@ void _SMP_Send_message_broadcast( unsigned long message ) } void _SMP_Send_message_multicast( - const Processor_mask targets, - unsigned long message + const Processor_mask *targets, + unsigned long message ) { uint32_t cpu_count = _SMP_Get_processor_count(); diff --git a/cpukit/score/src/smpmulticastaction.c b/cpukit/score/src/smpmulticastaction.c index a7c63498a3..73b15001ab 100644 --- a/cpukit/score/src/smpmulticastaction.c +++ b/cpukit/score/src/smpmulticastaction.c @@ -47,12 +47,12 @@ void _SMP_Multicast_actions_process( void ) while ( !_Chain_Is_tail( &_SMP_Multicast.Actions, &node->Node ) ) { next = (SMP_Multicast_action *) _Chain_Next( &node->Node ); - if ( _Processor_mask_Is_set( node->targets, cpu_self_index ) ) { - _Processor_mask_Clear( node->targets, cpu_self_index ); + if ( _Processor_mask_Is_set( &node->targets, cpu_self_index ) ) { + _Processor_mask_Clear( &node->targets, cpu_self_index ); ( *node->handler )( node->arg ); - if ( _Processor_mask_Is_zero( node->targets ) ) { + if ( _Processor_mask_Is_zero( &node->targets ) ) { _Chain_Extract_unprotected( &node->Node ); _Atomic_Store_ulong( &node->done, 1, ATOMIC_ORDER_RELEASE ); } @@ -106,13 +106,13 @@ void _SMP_Multicast_action( } if( cpus == NULL ) { - _Processor_mask_Assign( targets, _SMP_Online_processors ); + _Processor_mask_Assign( &targets, &_SMP_Online_processors ); } else { - _Processor_mask_Zero( targets ); + _Processor_mask_Zero( &targets ); for ( i = 0; i < _SMP_Get_processor_count(); ++i ) { if ( CPU_ISSET_S( i, setsize, cpus ) ) { - _Processor_mask_Set( targets, i ); + _Processor_mask_Set( &targets, i ); } } } @@ -120,14 +120,14 @@ void _SMP_Multicast_action( _Chain_Initialize_node( &node.Node ); node.handler = handler; node.arg = arg; - _Processor_mask_Assign( node.targets, targets ); + _Processor_mask_Assign( &node.targets, &targets ); _Atomic_Store_ulong( &node.done, 0, ATOMIC_ORDER_RELAXED ); _SMP_lock_ISR_disable_and_acquire( &_SMP_Multicast.Lock, &lock_context ); _Chain_Prepend_unprotected( &_SMP_Multicast.Actions, &node.Node ); _SMP_lock_Release_and_ISR_enable( &_SMP_Multicast.Lock, &lock_context ); - _SMP_Send_message_multicast( targets, SMP_MESSAGE_MULTICAST_ACTION ); + _SMP_Send_message_multicast( &targets, SMP_MESSAGE_MULTICAST_ACTION ); _SMP_Multicasts_try_process(); while ( _Atomic_Load_ulong( &node.done, ATOMIC_ORDER_ACQUIRE ) == 0 ) { |