[PATCH 2/4] score: Postpone SMP shutdown in _Terminate()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jul 5 08:33:17 UTC 2016


This enables fatal extensions to continue program execution after some
fatal errors.
---
 cpukit/score/src/interr.c             |  4 ++--
 cpukit/score/src/smp.c                |  7 +++++--
 testsuites/smptests/smpfatal02/init.c | 38 ++++++++++++++++-------------------
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/cpukit/score/src/interr.c b/cpukit/score/src/interr.c
index 526023f..8740027 100644
--- a/cpukit/score/src/interr.c
+++ b/cpukit/score/src/interr.c
@@ -33,8 +33,6 @@ void _Terminate(
   Internal_errors_t       the_error
 )
 {
-  _SMP_Request_shutdown();
-
   _User_extensions_Fatal( the_source, is_internal, the_error );
 
   _Internal_errors_What_happened.the_source  = the_source;
@@ -43,6 +41,8 @@ void _Terminate(
 
   _System_state_Set( SYSTEM_STATE_TERMINATED );
 
+  _SMP_Request_shutdown();
+
   _CPU_Fatal_halt( the_source, the_error );
 
   /* will not return from this routine */
diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c
index d6aad85..b8d9cb6 100644
--- a/cpukit/score/src/smp.c
+++ b/cpukit/score/src/smp.c
@@ -158,9 +158,12 @@ void _SMP_Start_multitasking_on_secondary_processor( void )
 
 void _SMP_Request_shutdown( void )
 {
-  Per_CPU_Control *self_cpu = _Per_CPU_Get();
+  ISR_Level level;
+
+  _ISR_Local_disable( level );
+  (void) level;
 
-  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_SHUTDOWN );
+  _Per_CPU_State_change( _Per_CPU_Get(), PER_CPU_STATE_SHUTDOWN );
 }
 
 void _SMP_Send_message( uint32_t cpu_index, unsigned long message )
diff --git a/testsuites/smptests/smpfatal02/init.c b/testsuites/smptests/smpfatal02/init.c
index 71fff0c..ae075ec 100644
--- a/testsuites/smptests/smpfatal02/init.c
+++ b/testsuites/smptests/smpfatal02/init.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -47,33 +47,29 @@ static void fatal_extension(
 )
 {
   SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
+  uint32_t self = rtems_get_current_processor();
 
-  if (
-    source == RTEMS_FATAL_SOURCE_APPLICATION
-      || source == RTEMS_FATAL_SOURCE_SMP
-  ) {
-    uint32_t self = rtems_get_current_processor();
-
-    assert(!is_internal);
+  assert(!is_internal);
 
-    if (self == main_cpu) {
-      uint32_t cpu;
+  if ( source == RTEMS_FATAL_SOURCE_APPLICATION ) {
+    uint32_t cpu;
 
-      assert(source == RTEMS_FATAL_SOURCE_APPLICATION);
-      assert(code == 0xdeadbeef);
+    assert(self == main_cpu);
+    assert(code == 0xdeadbeef);
 
-      for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
-        const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
-        Per_CPU_State state = per_cpu->state;
+    _SMP_Request_shutdown();
 
-        assert(state == PER_CPU_STATE_SHUTDOWN);
-      }
+    for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
+      const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
+      Per_CPU_State state = per_cpu->state;
 
-      TEST_END();
-    } else {
-      assert(source == RTEMS_FATAL_SOURCE_SMP);
-      assert(code == SMP_FATAL_SHUTDOWN);
+      assert(state == PER_CPU_STATE_SHUTDOWN);
     }
+
+    TEST_END();
+  } else if ( source == RTEMS_FATAL_SOURCE_SMP ) {
+    assert(self != main_cpu);
+    assert(code == SMP_FATAL_SHUTDOWN);
   }
 
   _SMP_barrier_Wait(&barrier, &barrier_state, rtems_get_processor_count());
-- 
1.8.4.5



More information about the devel mailing list