[rtems commit] score: Use <sys/bitset.h> for Processor_mask
Sebastian Huber
sebh at rtems.org
Mon Jul 10 07:37:06 UTC 2017
Module: rtems
Branch: master
Commit: 3dfe55ee154b6053e936e7b458206b71aad51caa
Changeset: http://git.rtems.org/rtems/commit/?id=3dfe55ee154b6053e936e7b458206b71aad51caa
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Jul 3 11:46:12 2017 +0200
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.
---
.../lib/libbsp/powerpc/qoriq/clock/clock-config.c | 5 +-
.../lib/libbsp/powerpc/qoriq/startup/bsprestart.c | 3 +-
c/src/lib/libbsp/shared/clockdrv_shell.h | 4 +-
c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus.c | 2 +-
.../libbsp/sparc/shared/drvmgr/ambapp_bus_grlib.c | 4 +-
.../sparc/shared/include/drvmgr/ambapp_bus.h | 2 +-
cpukit/libdrvmgr/drvmgr.h | 4 +-
cpukit/libdrvmgr/drvmgr_drvinf.c | 2 +-
cpukit/score/include/rtems/score/processormask.h | 91 ++++++++++------------
cpukit/score/include/rtems/score/smpimpl.h | 4 +-
cpukit/score/src/smp.c | 8 +-
cpukit/score/src/smpmulticastaction.c | 16 ++--
testsuites/smptests/smpipi01/init.c | 4 +-
13 files changed, 73 insertions(+), 76 deletions(-)
diff --git a/c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c b/c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c
index 17d4bde..42fdfda 100644
--- a/c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c
+++ b/c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c
@@ -133,7 +133,10 @@ static void qoriq_clock_cleanup(void)
qoriq_clock_handler_install(&old_isr)
#define Clock_driver_support_set_interrupt_affinity(online_processors) \
- qoriq_pic_set_affinities(CLOCK_INTERRUPT, online_processors[0])
+ qoriq_pic_set_affinities( \
+ CLOCK_INTERRUPT, \
+ _Processor_mask_To_uint32_t(online_processors, 0) \
+ )
#define Clock_driver_support_shutdown_hardware() \
qoriq_clock_cleanup()
diff --git a/c/src/lib/libbsp/powerpc/qoriq/startup/bsprestart.c b/c/src/lib/libbsp/powerpc/qoriq/startup/bsprestart.c
index 4159050..c85a6b8 100644
--- a/c/src/lib/libbsp/powerpc/qoriq/startup/bsprestart.c
+++ b/c/src/lib/libbsp/powerpc/qoriq/startup/bsprestart.c
@@ -99,7 +99,8 @@ static void restart_interrupt(void *arg)
static void raise_restart_interrupt(void)
{
- qoriq.pic.ipidr[RESTART_IPI_INDEX].reg = _SMP_Online_processors[0];
+ qoriq.pic.ipidr[RESTART_IPI_INDEX].reg =
+ _Processor_mask_To_uint32_t(&_SMP_Online_processors, 0);
ppc_synchronize_data();
ppc_synchronize_instructions();
}
diff --git a/c/src/lib/libbsp/shared/clockdrv_shell.h b/c/src/lib/libbsp/shared/clockdrv_shell.h
index 2b90fe6..bf74133 100644
--- a/c/src/lib/libbsp/shared/clockdrv_shell.h
+++ b/c/src/lib/libbsp/shared/clockdrv_shell.h
@@ -80,7 +80,7 @@ static void Clock_driver_timecounter_tick( void )
if ( _Per_CPU_Is_boot_processor( cpu ) ) {
rtems_timecounter_tick();
- } else if ( _Processor_mask_Is_set( _SMP_Online_processors, cpu_index ) ) {
+ } else if ( _Processor_mask_Is_set( &_SMP_Online_processors, cpu_index ) ) {
_Watchdog_Tick( cpu );
}
}
@@ -227,7 +227,7 @@ rtems_device_driver Clock_initialize(
Clock_driver_support_install_isr( Clock_isr, Old_ticker );
#ifdef RTEMS_SMP
- Clock_driver_support_set_interrupt_affinity( _SMP_Online_processors );
+ Clock_driver_support_set_interrupt_affinity( &_SMP_Online_processors );
#endif
/*
diff --git a/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus.c b/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus.c
index d17affb..c2a63a7 100644
--- a/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus.c
+++ b/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus.c
@@ -59,7 +59,7 @@ void ambapp_dev_info(struct drvmgr_dev *, void (*print)(void *p, char *str), voi
int ambapp_int_set_affinity(
struct drvmgr_dev *dev,
int index,
- Processor_mask cpus);
+ const Processor_mask *cpus);
#endif
struct drvmgr_bus_ops ambapp_bus_ops =
diff --git a/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus_grlib.c b/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus_grlib.c
index 5305527..f61d2a8 100644
--- a/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus_grlib.c
+++ b/c/src/lib/libbsp/sparc/shared/drvmgr/ambapp_bus_grlib.c
@@ -50,7 +50,7 @@ int ambapp_grlib_int_unmask(
int ambapp_grlib_int_set_affinity(
struct drvmgr_dev *dev,
int irq,
- Processor_mask cpus);
+ const Processor_mask *cpus);
#endif
int ambapp_grlib_get_params(
struct drvmgr_dev *dev,
@@ -233,7 +233,7 @@ int ambapp_grlib_int_set_affinity
(
struct drvmgr_dev *dev,
int irq,
- Processor_mask cpus
+ const Processor_mask *cpus
)
{
uint32_t cpu_count = rtems_get_processor_count();
diff --git a/c/src/lib/libbsp/sparc/shared/include/drvmgr/ambapp_bus.h b/c/src/lib/libbsp/sparc/shared/include/drvmgr/ambapp_bus.h
index e59af06..d034aae 100644
--- a/c/src/lib/libbsp/sparc/shared/include/drvmgr/ambapp_bus.h
+++ b/c/src/lib/libbsp/sparc/shared/include/drvmgr/ambapp_bus.h
@@ -91,7 +91,7 @@ struct ambapp_ops {
int (*int_unmask)(struct drvmgr_dev *dev, int index);
#ifdef RTEMS_SMP
int (*int_set_affinity)(struct drvmgr_dev *dev, int index,
- Processor_mask cpus);
+ const Processor_mask *cpus);
#endif
int (*get_params)
(struct drvmgr_dev *, struct drvmgr_bus_params *);
diff --git a/cpukit/libdrvmgr/drvmgr.h b/cpukit/libdrvmgr/drvmgr.h
index a8e1c8c..cb8f4a5 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 5bb6e6e..346a66f 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 8ee869a..ebf19ca 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 f85251e..bc800b9 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 434483c..a69b7ed 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 a7c6349..73b1500 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 ) {
diff --git a/testsuites/smptests/smpipi01/init.c b/testsuites/smptests/smpipi01/init.c
index 679b059..59f8771 100644
--- a/testsuites/smptests/smpipi01/init.c
+++ b/testsuites/smptests/smpipi01/init.c
@@ -162,7 +162,7 @@ static void test_send_message_flood(
for (cpu_index = 0; cpu_index < cpu_count; ++cpu_index) {
rtems_test_assert(
- _Processor_mask_Is_set(_SMP_Online_processors, cpu_index)
+ _Processor_mask_Is_set(&_SMP_Online_processors, cpu_index)
);
printf(
@@ -176,7 +176,7 @@ static void test_send_message_flood(
for (; cpu_index < CPU_COUNT; ++cpu_index) {
rtems_test_assert(
- !_Processor_mask_Is_set(_SMP_Online_processors, cpu_index)
+ !_Processor_mask_Is_set(&_SMP_Online_processors, cpu_index)
);
}
}
More information about the vc
mailing list