[PATCH 15/25] score: Error for non-preemptible tasks on SMP
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Jul 18 14:26:03 UTC 2013
A common use case for disabled preemption was to ensure mutual exclusion
on single-processor configurations. On SMP this does not work.
To abandon non-preemptible tasks simplifies the scheduler.
---
cpukit/rtems/src/taskcreate.c | 1 +
cpukit/rtems/src/taskmode.c | 13 ++++++++++++-
cpukit/sapi/include/confdefs.h | 6 +++++-
cpukit/score/src/threadinitialize.c | 7 +++++++
testsuites/smptests/smpunsupported01/init.c | 20 +++++++++++++++++++-
5 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/cpukit/rtems/src/taskcreate.c b/cpukit/rtems/src/taskcreate.c
index 64ad1eb..471990d 100644
--- a/cpukit/rtems/src/taskcreate.c
+++ b/cpukit/rtems/src/taskcreate.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/system.h>
+#include <rtems/config.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/modes.h>
diff --git a/cpukit/rtems/src/taskmode.c b/cpukit/rtems/src/taskmode.c
index d9c7fce..eb3636d 100644
--- a/cpukit/rtems/src/taskmode.c
+++ b/cpukit/rtems/src/taskmode.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/system.h>
+#include <rtems/config.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/modes.h>
@@ -67,8 +68,18 @@ rtems_status_code rtems_task_mode(
/*
* These are generic thread scheduling characteristics.
*/
- if ( mask & RTEMS_PREEMPT_MASK )
+ if ( mask & RTEMS_PREEMPT_MASK ) {
+#if defined( RTEMS_SMP )
+ if (
+ rtems_configuration_is_smp_enabled()
+ && !_Modes_Is_preempt( mode_set )
+ ) {
+ return RTEMS_NOT_IMPLEMENTED;
+ }
+#endif
+
executing->is_preemptible = _Modes_Is_preempt( mode_set );
+ }
if ( mask & RTEMS_TIMESLICE_MASK ) {
if ( _Modes_Is_timeslice(mode_set) ) {
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index b7cbfaa..c969fa7 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -1021,7 +1021,11 @@ const rtems_libio_helper rtems_fs_init_helper =
#endif
#ifndef CONFIGURE_INIT_TASK_INITIAL_MODES
- #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_PREEMPT
+ #if defined(RTEMS_SMP) && defined(CONFIGURE_SMP_APPLICATION)
+ #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
+ #else
+ #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_PREEMPT
+ #endif
#endif
#ifndef CONFIGURE_INIT_TASK_ARGUMENTS
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 4c40ae8..cc74573 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -18,6 +18,7 @@
#endif
#include <rtems/system.h>
+#include <rtems/config.h>
#include <rtems/score/apiext.h>
#include <rtems/score/context.h>
#include <rtems/score/interr.h>
@@ -57,6 +58,12 @@ bool _Thread_Initialize(
bool extension_status;
int i;
+#if defined( RTEMS_SMP )
+ if ( rtems_configuration_is_smp_enabled() && !is_preemptible ) {
+ return false;
+ }
+#endif
+
/*
* Initialize the Ada self pointer
*/
diff --git a/testsuites/smptests/smpunsupported01/init.c b/testsuites/smptests/smpunsupported01/init.c
index 3379de6..bfce1f2 100644
--- a/testsuites/smptests/smpunsupported01/init.c
+++ b/testsuites/smptests/smpunsupported01/init.c
@@ -21,6 +21,8 @@
static void test(void)
{
rtems_status_code sc;
+ rtems_mode mode;
+ rtems_id id;
rtems_test_assert(rtems_configuration_is_smp_enabled());
@@ -35,6 +37,22 @@ static void test(void)
sc = rtems_task_variable_get(RTEMS_SELF, NULL, NULL);
rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);
+
+ sc = rtems_task_variable_get(RTEMS_SELF, NULL, NULL);
+ rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);
+
+ sc = rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &mode);
+ rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);
+
+ sc = rtems_task_create(
+ rtems_build_name('T', 'A', 'S', 'K'),
+ RTEMS_MINIMUM_PRIORITY,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_NO_PREEMPT,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &id
+ );
+ rtems_test_assert(sc == RTEMS_UNSATISFIED);
}
static void Init(rtems_task_argument arg)
@@ -55,7 +73,7 @@ static void Init(rtems_task_argument arg)
#define CONFIGURE_SMP_MAXIMUM_PROCESSORS 1
-#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_MAXIMUM_TASKS 2
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
--
1.7.7
More information about the devel
mailing list