[PATCH v1] move isr_level of SMP_lock_Context into ISR_lock_Context

Zhu Zhongjie zhongjiezhu1 at gmail.com
Sun Jan 15 10:12:30 UTC 2023


From: Zhongjie Zhu <zhongjiezhu1 at gmail.com>

when Acquires an ISR lock in SMP system, it first call _ISR_Local_disable()
to disable ISR, this is the same with in UP system, so we could
use the same isr_level in ISR_lock_Context, this change will also save 4 Bytes
of SMP_lock_Context.
---
 cpukit/include/rtems/score/isrlock.h    | 39 ++++----------
 cpukit/include/rtems/score/smpisrlock.h | 69 +++++++++++++++++++++++++
 cpukit/include/rtems/score/smplock.h    | 60 ---------------------
 cpukit/score/src/profilingsmplock.c     | 11 ++--
 cpukit/score/src/smplock.c              |  5 +-
 testsuites/smptests/smpload01/init.c    |  2 +-
 testsuites/smptests/smpmrsp01/init.c    |  6 +--
 7 files changed, 93 insertions(+), 99 deletions(-)
 create mode 100644 cpukit/include/rtems/score/smpisrlock.h

diff --git a/cpukit/include/rtems/score/isrlock.h b/cpukit/include/rtems/score/isrlock.h
index 72ac760196..663410387b 100644
--- a/cpukit/include/rtems/score/isrlock.h
+++ b/cpukit/include/rtems/score/isrlock.h
@@ -79,10 +79,9 @@ typedef struct {
  * @brief Local ISR lock context for acquire and release pairs.
  */
 typedef struct {
+  ISR_Level isr_level;
 #if defined( RTEMS_SMP )
   SMP_lock_Context Lock_context;
-#else
-  ISR_Level isr_level;
 #endif
 #if defined( RTEMS_PROFILING )
   /**
@@ -177,11 +176,7 @@ static inline void _ISR_lock_Context_set_level(
   ISR_Level         level
 )
 {
-#if defined( RTEMS_SMP )
-  context->Lock_context.isr_level = level;
-#else
   context->isr_level = level;
-#endif
 }
 
 /**
@@ -230,6 +225,7 @@ static inline void _ISR_lock_Context_set_level(
   #define _ISR_lock_Set_name( _lock, _name )
 #endif
 
+#include <rtems/score/smpisrlock.h>
 /**
  * @brief Acquires an ISR lock.
  *
@@ -248,7 +244,7 @@ static inline void _ISR_lock_Context_set_level(
   #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
     _SMP_lock_ISR_disable_and_acquire( \
       &( _lock )->Lock, \
-      &( _context )->Lock_context \
+      ( _context ) \
     )
 #else
   #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
@@ -273,7 +269,7 @@ static inline void _ISR_lock_Context_set_level(
   #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
     _SMP_lock_Release_and_ISR_enable( \
       &( _lock )->Lock, \
-      &( _context )->Lock_context \
+      ( _context ) \
     )
 #else
   #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
@@ -404,19 +400,11 @@ static inline void _ISR_lock_Context_set_level(
  *
  * @see _ISR_lock_ISR_enable().
  */
-#if defined( RTEMS_SMP )
-  #define _ISR_lock_ISR_disable( _context ) \
-    do { \
-      _ISR_Local_disable( ( _context )->Lock_context.isr_level ); \
-      _ISR_lock_ISR_disable_profile( _context ) \
-    } while ( 0 )
-#else
-  #define _ISR_lock_ISR_disable( _context ) \
-    do { \
-      _ISR_Local_disable( ( _context )->isr_level ); \
-      _ISR_lock_ISR_disable_profile( _context ) \
-    } while ( 0 )
-#endif
+#define _ISR_lock_ISR_disable( _context ) \
+  do { \
+    _ISR_Local_disable( ( _context )->isr_level ); \
+    _ISR_lock_ISR_disable_profile( _context ) \
+  } while ( 0 )
 
 /**
  * @brief Restores the saved interrupt state of the ISR lock context.
@@ -428,13 +416,8 @@ static inline void _ISR_lock_Context_set_level(
  *
  * @see _ISR_lock_ISR_disable().
  */
-#if defined( RTEMS_SMP )
-  #define _ISR_lock_ISR_enable( _context ) \
-    _ISR_Local_enable( ( _context )->Lock_context.isr_level )
-#else
-  #define _ISR_lock_ISR_enable( _context ) \
-    _ISR_Local_enable( ( _context )->isr_level )
-#endif
+#define _ISR_lock_ISR_enable( _context ) \
+  _ISR_Local_enable( ( _context )->isr_level )
 
 /** @} */
 
diff --git a/cpukit/include/rtems/score/smpisrlock.h b/cpukit/include/rtems/score/smpisrlock.h
new file mode 100644
index 0000000000..984bbcf861
--- /dev/null
+++ b/cpukit/include/rtems/score/smpisrlock.h
@@ -0,0 +1,69 @@
+#ifndef _RTEMS_SCORE_SMP_ISR_LOCK_H
+#define _RTEMS_SCORE_SMP_ISR_LOCK_H
+
+#if defined(RTEMS_SMP)
+
+#include <rtems/score/smplock.h>
+#include <rtems/score/isrlock.h>
+/**
+ * @brief Disables interrupts and acquires the SMP lock
+ *
+ * @param[in, out] lock The lock to acquire.
+ * @param[in, out] context The lock context.
+ */
+static inline void _SMP_lock_ISR_disable_and_acquire_inline(
+  SMP_lock_Control *lock,
+  ISR_lock_Context *context
+)
+{
+  _ISR_Local_disable( context->isr_level );
+  _SMP_lock_Acquire_inline( lock, &context->Lock_context );
+}
+
+/**
+ * @brief Disables interrupts and acquires the SMP lock.
+ *
+ * @param[in, out] lock The SMP lock control.
+ * @param[in, out] context The local SMP lock context for an acquire and release
+ * pair.
+ */
+void _SMP_lock_ISR_disable_and_acquire(
+  SMP_lock_Control *lock,
+  ISR_lock_Context *context
+);
+
+/**
+ * @brief Releases the SMP lock and enables interrupts.
+ *
+ * @param[in, out] lock The SMP lock to release.
+ * @param[in, out] context The lock context.
+ */
+static inline void _SMP_lock_Release_and_ISR_enable_inline(
+  SMP_lock_Control *lock,
+  ISR_lock_Context *context
+)
+{
+  _SMP_lock_Release_inline( lock, &context->Lock_context );
+  _ISR_Local_enable( context->isr_level );
+}
+
+/**
+ * @brief Releases the SMP lock and enables interrupts.
+ *
+ * @param[in, out] lock The SMP lock control.
+ * @param[in, out] context The local SMP lock context for an acquire and release
+ * pair.
+ */
+#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
+void _SMP_lock_Release_and_ISR_enable(
+  SMP_lock_Control *lock,
+  ISR_lock_Context *context
+);
+#else
+#define _SMP_lock_Release_and_ISR_enable( lock, context ) \
+  _SMP_lock_Release_and_ISR_enable_inline( lock, context )
+#endif
+
+#endif  /* RTEMS_SMP */
+
+#endif
diff --git a/cpukit/include/rtems/score/smplock.h b/cpukit/include/rtems/score/smplock.h
index ca874fef08..84831499be 100644
--- a/cpukit/include/rtems/score/smplock.h
+++ b/cpukit/include/rtems/score/smplock.h
@@ -109,7 +109,6 @@ typedef struct {
  * @brief Local SMP lock context for acquire and release pairs.
  */
 typedef struct {
-  ISR_Level isr_level;
 #if defined(RTEMS_DEBUG)
   SMP_lock_Control *lock_used_for_acquire;
 #endif
@@ -327,65 +326,6 @@ void _SMP_lock_Release(
   _SMP_lock_Release_inline( lock, context )
 #endif
 
-/**
- * @brief Disables interrupts and acquires the SMP lock
- *
- * @param[in, out] lock The lock to acquire.
- * @param[in, out] context The lock context.
- */
-static inline void _SMP_lock_ISR_disable_and_acquire_inline(
-  SMP_lock_Control *lock,
-  SMP_lock_Context *context
-)
-{
-  _ISR_Local_disable( context->isr_level );
-  _SMP_lock_Acquire_inline( lock, context );
-}
-
-/**
- * @brief Disables interrupts and acquires the SMP lock.
- *
- * @param[in, out] lock The SMP lock control.
- * @param[in, out] context The local SMP lock context for an acquire and release
- * pair.
- */
-void _SMP_lock_ISR_disable_and_acquire(
-  SMP_lock_Control *lock,
-  SMP_lock_Context *context
-);
-
-/**
- * @brief Releases the SMP lock and enables interrupts.
- *
- * @param[in, out] lock The SMP lock to release.
- * @param[in, out] context The lock context.
- */
-static inline void _SMP_lock_Release_and_ISR_enable_inline(
-  SMP_lock_Control *lock,
-  SMP_lock_Context *context
-)
-{
-  _SMP_lock_Release_inline( lock, context );
-  _ISR_Local_enable( context->isr_level );
-}
-
-/**
- * @brief Releases the SMP lock and enables interrupts.
- *
- * @param[in, out] lock The SMP lock control.
- * @param[in, out] context The local SMP lock context for an acquire and release
- * pair.
- */
-#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
-void _SMP_lock_Release_and_ISR_enable(
-  SMP_lock_Control *lock,
-  SMP_lock_Context *context
-);
-#else
-#define _SMP_lock_Release_and_ISR_enable( lock, context ) \
-  _SMP_lock_Release_and_ISR_enable_inline( lock, context )
-#endif
-
 #if defined(RTEMS_DEBUG)
 /**
  * @brief Checks if the SMP lock is owned by the current processor.
diff --git a/cpukit/score/src/profilingsmplock.c b/cpukit/score/src/profilingsmplock.c
index 5c5b4d9196..41ebbcbed3 100644
--- a/cpukit/score/src/profilingsmplock.c
+++ b/cpukit/score/src/profilingsmplock.c
@@ -41,6 +41,7 @@
 #endif
 
 #include <rtems/score/smplock.h>
+#include <rtems/score/isrlock.h>
 #include <rtems/score/chainimpl.h>
 
 #include <string.h>
@@ -78,7 +79,7 @@ void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats )
 {
   if ( !_Chain_Is_node_off_chain( &stats->Node ) ) {
     SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
-    SMP_lock_Context lock_context;
+    ISR_lock_Context lock_context;
     SMP_lock_Stats_iteration_context *iteration_context;
     SMP_lock_Stats_iteration_context *iteration_context_tail;
     SMP_lock_Stats *next_stats;
@@ -115,7 +116,7 @@ void _SMP_lock_Stats_register_or_max_section_time(
 
   if ( _Chain_Is_node_off_chain( &stats->Node ) ) {
     SMP_lock_Stats_control *control;
-    SMP_lock_Context        lock_context;
+    ISR_lock_Context        lock_context;
 
     control = &_SMP_lock_Stats_control;
     _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
@@ -129,7 +130,7 @@ void _SMP_lock_Stats_iteration_start(
 )
 {
   SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
 
   _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
 
@@ -152,7 +153,7 @@ bool _SMP_lock_Stats_iteration_next(
 )
 {
   SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
   SMP_lock_Stats *current;
   bool valid;
 
@@ -190,7 +191,7 @@ void _SMP_lock_Stats_iteration_stop(
 )
 {
   SMP_lock_Stats_control *control = &_SMP_lock_Stats_control;
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
 
   _SMP_lock_ISR_disable_and_acquire( &control->Lock, &lock_context );
   _Chain_Extract_unprotected( &iteration_context->Node );
diff --git a/cpukit/score/src/smplock.c b/cpukit/score/src/smplock.c
index c3a41300bb..a0ff2b3ab0 100644
--- a/cpukit/score/src/smplock.c
+++ b/cpukit/score/src/smplock.c
@@ -41,6 +41,7 @@
 #endif
 
 #include <rtems/score/smplock.h>
+#include <rtems/score/isrlock.h>
 
 #if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
 void _SMP_lock_Initialize(
@@ -77,7 +78,7 @@ void _SMP_lock_Release(
 
 void _SMP_lock_ISR_disable_and_acquire(
   SMP_lock_Control *lock,
-  SMP_lock_Context *context
+  ISR_lock_Context *context
 )
 {
   _SMP_lock_ISR_disable_and_acquire_inline( lock, context );
@@ -86,7 +87,7 @@ void _SMP_lock_ISR_disable_and_acquire(
 #if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
 void _SMP_lock_Release_and_ISR_enable(
   SMP_lock_Control *lock,
-  SMP_lock_Context *context
+  ISR_lock_Context *context
 )
 {
   _SMP_lock_Release_and_ISR_enable_inline( lock, context );
diff --git a/testsuites/smptests/smpload01/init.c b/testsuites/smptests/smpload01/init.c
index d28e728746..c72b5e1ef5 100644
--- a/testsuites/smptests/smpload01/init.c
+++ b/testsuites/smptests/smpload01/init.c
@@ -241,7 +241,7 @@ static void get_obtain_delay_estimate(test_context *ctx)
   _ISR_Local_disable(level);
 
   for (i = 0; i < n; ++i) {
-    SMP_lock_Context lock_context;
+    ISR_lock_Context lock_context;
     rtems_counter_ticks a;
     rtems_counter_ticks b;
 
diff --git a/testsuites/smptests/smpmrsp01/init.c b/testsuites/smptests/smpmrsp01/init.c
index e435f77b2a..2338b1e493 100644
--- a/testsuites/smptests/smpmrsp01/init.c
+++ b/testsuites/smptests/smpmrsp01/init.c
@@ -157,7 +157,7 @@ static void assert_executing_worker(test_context *ctx)
 static void switch_extension(Thread_Control *executing, Thread_Control *heir)
 {
   test_context *ctx = &test_instance;
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
   size_t i;
 
   _SMP_lock_ISR_disable_and_acquire(&ctx->switch_lock, &lock_context);
@@ -181,7 +181,7 @@ static void switch_extension(Thread_Control *executing, Thread_Control *heir)
 
 static void reset_switch_events(test_context *ctx)
 {
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
 
   _SMP_lock_ISR_disable_and_acquire(&ctx->switch_lock, &lock_context);
   ctx->switch_index = 0;
@@ -190,7 +190,7 @@ static void reset_switch_events(test_context *ctx)
 
 static size_t get_switch_events(test_context *ctx)
 {
-  SMP_lock_Context lock_context;
+  ISR_lock_Context lock_context;
   size_t events;
 
   _SMP_lock_ISR_disable_and_acquire(&ctx->switch_lock, &lock_context);
-- 
2.34.1



More information about the devel mailing list