summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/threaddispatch.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-08-05 14:54:11 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-08-09 23:02:38 +0200
commitd19cce29dcaffa7c679407bc211ee09c2d9dc40a (patch)
tree2e0eb6211f0199680fcf9445b644a25495e53732 /cpukit/score/include/rtems/score/threaddispatch.h
parentscore: Add and use _Per_CPU_Acquire_all(). (diff)
downloadrtems-d19cce29dcaffa7c679407bc211ee09c2d9dc40a.tar.bz2
score: Per-CPU thread dispatch disable level
Use a per-CPU thread dispatch disable level. So instead of one global thread dispatch disable level we have now one instance per processor. This is a major performance improvement for SMP. On non-SMP configurations this may simplifiy the interrupt entry/exit code. The giant lock is still present, but it is now decoupled from the thread dispatching in _Thread_Dispatch(), _Thread_Handler(), _Thread_Restart_self() and the interrupt entry/exit. Access to the giant lock is now available via _Giant_Acquire() and _Giant_Release(). The giant lock is still implicitly acquired via _Thread_Dispatch_decrement_disable_level(). The giant lock is only acquired for high-level operations in interrupt handlers (e.g. release of a semaphore, sending of an event). As a side-effect this change fixes the lost thread dispatch necessary indication bug in _Thread_Dispatch(). A per-CPU thread dispatch disable level greatly simplifies the SMP support for the interrupt entry/exit code since no spin locks have to be acquired in this area. It is only necessary to get the current processor index and use this to calculate the address of the own per-CPU control. This reduces the interrupt latency considerably. All elements for the interrupt entry/exit code are now part of the Per_CPU_Control structure: thread dispatch disable level, ISR nest level and thread dispatch necessary. Nothing else is required (except CPU port specific stuff like on SPARC).
Diffstat (limited to 'cpukit/score/include/rtems/score/threaddispatch.h')
-rw-r--r--cpukit/score/include/rtems/score/threaddispatch.h95
1 files changed, 48 insertions, 47 deletions
diff --git a/cpukit/score/include/rtems/score/threaddispatch.h b/cpukit/score/include/rtems/score/threaddispatch.h
index 7e7afb9161..9cd12873fb 100644
--- a/cpukit/score/include/rtems/score/threaddispatch.h
+++ b/cpukit/score/include/rtems/score/threaddispatch.h
@@ -14,7 +14,7 @@
#ifndef _RTEMS_SCORE_THREADDISPATCH_H
#define _RTEMS_SCORE_THREADDISPATCH_H
-#include <rtems/score/cpu.h>
+#include <rtems/score/percpu.h>
#include <rtems/score/smplock.h>
#ifdef __cplusplus
@@ -40,13 +40,6 @@ extern "C" {
*/
/**
- * The following declares the dispatch critical section nesting
- * counter which is used to prevent context switches at inopportune
- * moments.
- */
-SCORE_EXTERN volatile uint32_t _Thread_Dispatch_disable_level;
-
-/**
* @brief Indicates if the executing thread is inside a thread dispatch
* critical section.
*
@@ -56,36 +49,64 @@ SCORE_EXTERN volatile uint32_t _Thread_Dispatch_disable_level;
*/
RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
{
- return _Thread_Dispatch_disable_level == 0;
-}
+ bool enabled;
#if defined(RTEMS_SMP)
- typedef struct {
- SMP_lock_Control lock;
- uint32_t owner_cpu;
- uint32_t nest_level;
- } Thread_Dispatch_disable_level_lock_control;
+ ISR_Level level;
- /**
- * The following declares the smp spinlock to be used to control
- * the dispatch critical section accesses across cpus.
- */
- SCORE_EXTERN Thread_Dispatch_disable_level_lock_control
- _Thread_Dispatch_disable_level_lock;
+ _ISR_Disable( level );
+#endif
+
+ enabled = _Thread_Dispatch_disable_level == 0;
+
+#if defined(RTEMS_SMP)
+ _ISR_Enable( level );
+#endif
+
+ return enabled;
+}
+
+/**
+ * @briefs Gets thread dispatch disable level.
+ *
+ * @return The value of the thread dispatch level.
+ */
+RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
+{
+ return _Thread_Dispatch_disable_level;
+}
+
+/**
+ * @brief Thread dispatch initialization.
+ *
+ * This routine initializes the thread dispatching subsystem.
+ */
+RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
+{
+ _Thread_Dispatch_disable_level = 1;
+}
+#if defined(RTEMS_SMP)
/**
- * @brief Initializes the thread dispatching subsystem.
+ * @brief Acquires the giant lock.
+ *
+ * The giant lock is a recursive SMP lock protecting nearly all operating
+ * system services.
+ *
+ * This lock is implicitly acquired in
+ * _Thread_Dispatch_increment_disable_level().
*
- * This routine initializes the thread dispatching subsystem.
+ * Thread dispatching must be disabled before this lock can be acquired.
*/
- void _Thread_Dispatch_initialization(void);
+ void _Giant_Acquire( void );
/**
- * @brief Returns value of the the thread dispatch level.
+ * @brief Releases the giant lock.
*
- * This routine returns value of the the thread dispatch level.
+ * This lock is implicitly released in
+ * _Thread_Dispatch_decrement_disable_level().
*/
- uint32_t _Thread_Dispatch_get_disable_level(void);
+ void _Giant_Release( void );
/**
* @brief Sets thread dispatch level to the value passed in.
@@ -110,16 +131,6 @@ RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
uint32_t _Thread_Dispatch_decrement_disable_level(void);
#else /* RTEMS_SMP */
/**
- * @brief Get thread dispatch disable level.
- *
- * This routine returns value of the the thread dispatch level.
- */
- RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
- {
- return _Thread_Dispatch_disable_level;
- }
-
- /**
* @brief Set thread dispatch disable level.
*
* This routine sets thread dispatch level to the
@@ -160,16 +171,6 @@ RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
return level;
}
-
- /**
- * @brief Thread dispatch initialization.
- *
- * This routine initializes the thread dispatching subsystem.
- */
- RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
- {
- _Thread_Dispatch_set_disable_level( 1 );
- }
#endif /* RTEMS_SMP */
/**