[PATCH] score: Indroduce cancel job scheduler operation
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Aug 3 13:43:36 UTC 2016
Do not use a deadline value of zero to indicate a job cancellation. Use
a dedicated scheduler operation for this.
---
cpukit/rtems/src/ratemoncancel.c | 2 +-
cpukit/score/include/rtems/score/scheduler.h | 17 ++++++++
cpukit/score/include/rtems/score/schedulercbs.h | 1 +
cpukit/score/include/rtems/score/scheduleredf.h | 8 +++-
cpukit/score/include/rtems/score/schedulerimpl.h | 14 +++++++
.../score/include/rtems/score/schedulerpriority.h | 1 +
.../rtems/score/schedulerpriorityaffinitysmp.h | 1 +
.../include/rtems/score/schedulerprioritysmp.h | 1 +
cpukit/score/include/rtems/score/schedulersimple.h | 1 +
.../score/include/rtems/score/schedulersimplesmp.h | 1 +
.../score/include/rtems/score/schedulerstrongapa.h | 1 +
cpukit/score/src/schedulerdefaultreleasejob.c | 9 +++++
cpukit/score/src/scheduleredfreleasejob.c | 46 ++++++++++++++++++----
13 files changed, 94 insertions(+), 9 deletions(-)
diff --git a/cpukit/rtems/src/ratemoncancel.c b/cpukit/rtems/src/ratemoncancel.c
index af6b1ec..41ba488 100644
--- a/cpukit/rtems/src/ratemoncancel.c
+++ b/cpukit/rtems/src/ratemoncancel.c
@@ -38,7 +38,7 @@ void _Rate_monotonic_Cancel(
cpu_self = _Thread_Dispatch_disable_critical( lock_context );
_Rate_monotonic_Release( owner, lock_context );
- _Scheduler_Release_job( owner, 0 );
+ _Scheduler_Cancel_job( owner );
_Thread_Dispatch_enable( cpu_self );
}
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
index c20e68c..20615a2 100644
--- a/cpukit/score/include/rtems/score/scheduler.h
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -141,6 +141,12 @@ typedef struct {
uint64_t
);
+ /** @see _Scheduler_Cancel_job() */
+ void ( *cancel_job ) (
+ const Scheduler_Control *,
+ Thread_Control *
+ );
+
/** @see _Scheduler_Tick() */
void ( *tick )( const Scheduler_Control *, Thread_Control * );
@@ -376,6 +382,17 @@ void _Scheduler_default_Release_job(
);
/**
+ * @brief Does nothing.
+ *
+ * @param[in] scheduler Unused.
+ * @param[in] the_thread Unused.
+ */
+void _Scheduler_default_Cancel_job(
+ const Scheduler_Control *scheduler,
+ Thread_Control *the_thread
+);
+
+/**
* @brief Performs tick operations depending on the CPU budget algorithm for
* each executing thread.
*
diff --git a/cpukit/score/include/rtems/score/schedulercbs.h b/cpukit/score/include/rtems/score/schedulercbs.h
index a46314c..bfad633 100644
--- a/cpukit/score/include/rtems/score/schedulercbs.h
+++ b/cpukit/score/include/rtems/score/schedulercbs.h
@@ -61,6 +61,7 @@ extern "C" {
_Scheduler_CBS_Node_initialize, /* node initialize entry point */ \
_Scheduler_default_Node_destroy, /* node destroy entry point */ \
_Scheduler_CBS_Release_job, /* new period of task */ \
+ _Scheduler_EDF_Cancel_job, /* cancel period of task */ \
_Scheduler_default_Tick, /* tick entry point */ \
_Scheduler_default_Start_idle /* start idle entry point */ \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/include/rtems/score/scheduleredf.h b/cpukit/score/include/rtems/score/scheduleredf.h
index de06344..5d9b435 100644
--- a/cpukit/score/include/rtems/score/scheduleredf.h
+++ b/cpukit/score/include/rtems/score/scheduleredf.h
@@ -61,6 +61,7 @@ extern "C" {
_Scheduler_EDF_Node_initialize, /* node initialize entry point */ \
_Scheduler_default_Node_destroy, /* node destroy entry point */ \
_Scheduler_EDF_Release_job, /* new period of task */ \
+ _Scheduler_EDF_Cancel_job, /* cancel period of task */ \
_Scheduler_default_Tick, /* tick entry point */ \
_Scheduler_default_Start_idle /* start idle entry point */ \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
@@ -227,12 +228,17 @@ Scheduler_Void_or_thread _Scheduler_EDF_Yield(
* the job was cancelled or deleted, thus a running task
* has to be suspended.
*/
-void _Scheduler_EDF_Release_job (
+void _Scheduler_EDF_Release_job(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
uint64_t deadline
);
+void _Scheduler_EDF_Cancel_job(
+ const Scheduler_Control *scheduler,
+ Thread_Control *the_thread
+);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index dd7fa28..23b73f0 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -499,6 +499,20 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Release_job(
}
/**
+ * @brief Cancels a job of a thread with respect to the scheduler.
+ *
+ * @param[in] the_thread The thread.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Cancel_job(
+ Thread_Control *the_thread
+)
+{
+ const Scheduler_Control *scheduler = _Scheduler_Get( the_thread );
+
+ ( *scheduler->Operations.cancel_job )( scheduler, the_thread );
+}
+
+/**
* @brief Scheduler method invoked at each clock tick.
*
* This method is invoked at each clock tick to allow the scheduler
diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
index 9501e3d..f3e805a 100644
--- a/cpukit/score/include/rtems/score/schedulerpriority.h
+++ b/cpukit/score/include/rtems/score/schedulerpriority.h
@@ -51,6 +51,7 @@ extern "C" {
_Scheduler_priority_Node_initialize, /* node initialize entry point */ \
_Scheduler_default_Node_destroy, /* node destroy entry point */ \
_Scheduler_default_Release_job, /* new period of task */ \
+ _Scheduler_default_Cancel_job, /* cancel period of task */ \
_Scheduler_default_Tick, /* tick entry point */ \
_Scheduler_default_Start_idle /* start idle entry point */ \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h b/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
index 763523a..317411a 100644
--- a/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
+++ b/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
@@ -61,6 +61,7 @@ extern "C" {
_Scheduler_priority_affinity_SMP_Node_initialize, \
_Scheduler_default_Node_destroy, \
_Scheduler_default_Release_job, \
+ _Scheduler_default_Cancel_job, \
_Scheduler_default_Tick, \
_Scheduler_SMP_Start_idle, \
_Scheduler_priority_affinity_SMP_Get_affinity, \
diff --git a/cpukit/score/include/rtems/score/schedulerprioritysmp.h b/cpukit/score/include/rtems/score/schedulerprioritysmp.h
index 97370ac..6ae933f 100644
--- a/cpukit/score/include/rtems/score/schedulerprioritysmp.h
+++ b/cpukit/score/include/rtems/score/schedulerprioritysmp.h
@@ -90,6 +90,7 @@ typedef struct {
_Scheduler_priority_SMP_Node_initialize, \
_Scheduler_default_Node_destroy, \
_Scheduler_default_Release_job, \
+ _Scheduler_default_Cancel_job, \
_Scheduler_default_Tick, \
_Scheduler_SMP_Start_idle \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/include/rtems/score/schedulersimple.h b/cpukit/score/include/rtems/score/schedulersimple.h
index 3fa4b33..2239379 100644
--- a/cpukit/score/include/rtems/score/schedulersimple.h
+++ b/cpukit/score/include/rtems/score/schedulersimple.h
@@ -51,6 +51,7 @@ extern "C" {
_Scheduler_default_Node_initialize, /* node initialize entry point */ \
_Scheduler_default_Node_destroy, /* node destroy entry point */ \
_Scheduler_default_Release_job, /* new period of task */ \
+ _Scheduler_default_Cancel_job, /* cancel period of task */ \
_Scheduler_default_Tick, /* tick entry point */ \
_Scheduler_default_Start_idle /* start idle entry point */ \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/include/rtems/score/schedulersimplesmp.h b/cpukit/score/include/rtems/score/schedulersimplesmp.h
index bbcdbdb..95176dc 100644
--- a/cpukit/score/include/rtems/score/schedulersimplesmp.h
+++ b/cpukit/score/include/rtems/score/schedulersimplesmp.h
@@ -73,6 +73,7 @@ typedef struct {
_Scheduler_simple_SMP_Node_initialize, \
_Scheduler_default_Node_destroy, \
_Scheduler_default_Release_job, \
+ _Scheduler_default_Cancel_job, \
_Scheduler_default_Tick, \
_Scheduler_SMP_Start_idle \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/include/rtems/score/schedulerstrongapa.h b/cpukit/score/include/rtems/score/schedulerstrongapa.h
index 8390c2d..2cc9183 100644
--- a/cpukit/score/include/rtems/score/schedulerstrongapa.h
+++ b/cpukit/score/include/rtems/score/schedulerstrongapa.h
@@ -90,6 +90,7 @@ typedef struct {
_Scheduler_strong_APA_Node_initialize, \
_Scheduler_default_Node_destroy, \
_Scheduler_default_Release_job, \
+ _Scheduler_default_Cancel_job, \
_Scheduler_default_Tick, \
_Scheduler_SMP_Start_idle \
SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
diff --git a/cpukit/score/src/schedulerdefaultreleasejob.c b/cpukit/score/src/schedulerdefaultreleasejob.c
index db4ab0e..439f6b2 100644
--- a/cpukit/score/src/schedulerdefaultreleasejob.c
+++ b/cpukit/score/src/schedulerdefaultreleasejob.c
@@ -31,3 +31,12 @@ void _Scheduler_default_Release_job(
(void) the_thread;
(void) deadline;
}
+
+void _Scheduler_default_Cancel_job(
+ const Scheduler_Control *scheduler,
+ Thread_Control *the_thread
+)
+{
+ (void) scheduler;
+ (void) the_thread;
+}
diff --git a/cpukit/score/src/scheduleredfreleasejob.c b/cpukit/score/src/scheduleredfreleasejob.c
index 76c08e0..f2ee75b 100644
--- a/cpukit/score/src/scheduleredfreleasejob.c
+++ b/cpukit/score/src/scheduleredfreleasejob.c
@@ -20,7 +20,7 @@
#include <rtems/score/scheduleredfimpl.h>
-static bool _Scheduler_EDF_Priority_filter(
+static bool _Scheduler_EDF_Release_job_filter(
Thread_Control *the_thread,
Priority_Control *new_priority_p,
void *arg
@@ -35,10 +35,6 @@ static bool _Scheduler_EDF_Priority_filter(
current_priority = _Thread_Get_priority( the_thread );
new_priority = *new_priority_p;
- if ( new_priority == 0 ) {
- new_priority = node->background_priority;
- }
-
node->current_priority = new_priority;
the_thread->real_priority = new_priority;
@@ -54,9 +50,45 @@ void _Scheduler_EDF_Release_job(
{
_Thread_Change_priority(
the_thread,
- (Priority_Control) deadline,
+ deadline,
+ NULL,
+ _Scheduler_EDF_Release_job_filter,
+ true
+ );
+}
+
+static bool _Scheduler_EDF_Cancel_job_filter(
+ Thread_Control *the_thread,
+ Priority_Control *new_priority_p,
+ void *arg
+)
+{
+ Scheduler_EDF_Node *node;
+ Priority_Control current_priority;
+ Priority_Control new_priority;
+
+ node = _Scheduler_EDF_Thread_get_node( the_thread );
+
+ current_priority = _Thread_Get_priority( the_thread );
+ new_priority = node->background_priority;
+
+ node->current_priority = new_priority;
+ the_thread->real_priority = new_priority;
+
+ return _Thread_Priority_less_than( current_priority, new_priority )
+ || !_Thread_Owns_resources( the_thread );
+}
+
+void _Scheduler_EDF_Cancel_job(
+ const Scheduler_Control *scheduler,
+ Thread_Control *the_thread
+)
+{
+ _Thread_Change_priority(
+ the_thread,
+ 0,
NULL,
- _Scheduler_EDF_Priority_filter,
+ _Scheduler_EDF_Cancel_job_filter,
true
);
}
--
1.8.4.5
More information about the devel
mailing list