Ticket #1896: edf_scheduler6.diff
File edf_scheduler6.diff, 26.6 KB (added by Petr Benes, on 09/11/11 at 18:38:35) |
---|
-
cpukit/sapi/include/confdefs.h
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index 118e946..4ac9203 100644
a b rtems_fs_init_functions_t rtems_fs_init_helper = 573 573 * CONFIGURE_SCHEDULER_PRIORITY - Deterministic Priority Scheduler 574 574 * CONFIGURE_SCHEDULER_SIMPLE - Light-weight Priority Scheduler 575 575 * CONFIGURE_SCHEDULER_SIMPLE_SMP - Simple SMP Priority Scheduler 576 * CONFIGURE_SCHEDULER_EDF - EDF Scheduler 576 577 * 577 578 * If no configuration is specified by the application, then 578 579 * CONFIGURE_SCHEDULER_PRIORITY is assumed to be the default. … … rtems_fs_init_functions_t rtems_fs_init_helper = 598 599 #if !defined(CONFIGURE_SCHEDULER_USER) && \ 599 600 !defined(CONFIGURE_SCHEDULER_PRIORITY) && \ 600 601 !defined(CONFIGURE_SCHEDULER_SIMPLE) && \ 601 !defined(CONFIGURE_SCHEDULER_SIMPLE_SMP) 602 !defined(CONFIGURE_SCHEDULER_SIMPLE_SMP) && \ 603 !defined(CONFIGURE_SCHEDULER_EDF) 602 604 #if defined(RTEMS_SMP) && defined(CONFIGURE_SMP_APPLICATION) 603 605 #define CONFIGURE_SCHEDULER_SIMPLE_SMP 604 606 #else … … rtems_fs_init_functions_t rtems_fs_init_helper = 658 660 #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (0) 659 661 #endif 660 662 663 /* 664 * If the EDF Scheduler is selected, then configure for it. 665 */ 666 #if defined(CONFIGURE_SCHEDULER_EDF) 667 #include <rtems/score/scheduleredf.h> 668 #define CONFIGURE_SCHEDULER_ENTRY_POINTS SCHEDULER_EDF_ENTRY_POINTS 669 670 /** 671 * define the memory used by the EDF scheduler 672 */ 673 #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \ 674 _Configure_From_workspace(0)) 675 #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \ 676 _Configure_From_workspace(sizeof(Scheduler_EDF_Per_thread))) 677 #endif 678 661 679 #if defined(CONFIGURE_SCHEDULER_USER) 662 680 #define CONFIGURE_SCHEDULER_ENTRY_POINTS \ 663 681 CONFIGURE_SCHEDULER_USER_ENTRY_POINTS -
cpukit/score/Makefile.am
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 98e771c..bb88883 100644
a b include_rtems_score_HEADERS += include/rtems/score/priority.h 40 40 include_rtems_score_HEADERS += include/rtems/score/prioritybitmap.h 41 41 include_rtems_score_HEADERS += include/rtems/score/rbtree.h 42 42 include_rtems_score_HEADERS += include/rtems/score/scheduler.h 43 include_rtems_score_HEADERS += include/rtems/score/scheduleredf.h 43 44 include_rtems_score_HEADERS += include/rtems/score/schedulerpriority.h 44 45 include_rtems_score_HEADERS += include/rtems/score/schedulersimple.h 45 46 include_rtems_score_HEADERS += include/rtems/score/stack.h … … libscore_a_SOURCES += src/schedulersimple.c \ 222 223 src/schedulersimpleunblock.c \ 223 224 src/schedulersimpleyield.c 224 225 226 ## SCHEDULEREDF_C_FILES 227 libscore_a_SOURCES += src/scheduleredf.c \ 228 src/scheduleredfallocate.c \ 229 src/scheduleredfblock.c \ 230 src/scheduleredfenqueue.c \ 231 src/scheduleredfenqueuefirst.c \ 232 src/scheduleredfextract.c \ 233 src/scheduleredffree.c \ 234 src/scheduleredfprioritycompare.c \ 235 src/scheduleredfreleasejob.c \ 236 src/scheduleredfschedule.c \ 237 src/scheduleredfunblock.c \ 238 src/scheduleredfupdate.c \ 239 src/scheduleredfyield.c 240 225 241 ## PROTECTED_HEAP_C_FILES 226 242 libscore_a_SOURCES += src/pheapallocate.c \ 227 243 src/pheapextend.c src/pheapfree.c src/pheapgetsize.c \ -
new file cpukit/score/include/rtems/score/scheduleredf.h
diff --git a/cpukit/score/include/rtems/score/scheduleredf.h b/cpukit/score/include/rtems/score/scheduleredf.h new file mode 100644 index 0000000..0656906
- + 1 /** 2 * @file rtems/score/scheduleredf.h 3 * 4 * This include file contains all the constants and structures associated 5 * with the manipulation of threads for the EDF scheduler. 6 */ 7 8 /* 9 * Copryight (c) 2011 Petr Benes. 10 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 11 * 12 * The license and distribution terms for this file may be 13 * found in the file LICENSE in this distribution or at 14 * http://www.rtems.com/license/LICENSE. 15 * 16 * $Id$ 17 */ 18 19 #ifndef _RTEMS_SCORE_SCHEDULEREDF_H 20 #define _RTEMS_SCORE_SCHEDULEREDF_H 21 22 #include <rtems/score/priority.h> 23 #include <rtems/score/scheduler.h> 24 #include <rtems/score/schedulerpriority.h> 25 #include <rtems/score/rbtree.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** 32 * @addtogroup ScoreScheduler 33 * 34 */ 35 /**@{*/ 36 37 /** 38 * Entry points for the Earliest Deadline First Scheduler. 39 */ 40 #define SCHEDULER_EDF_ENTRY_POINTS \ 41 { \ 42 _Scheduler_EDF_Initialize, /* initialize entry point */ \ 43 _Scheduler_EDF_Schedule, /* schedule entry point */ \ 44 _Scheduler_EDF_Yield, /* yield entry point */ \ 45 _Scheduler_EDF_Block, /* block entry point */ \ 46 _Scheduler_EDF_Unblock, /* unblock entry point */ \ 47 _Scheduler_EDF_Allocate, /* allocate entry point */ \ 48 _Scheduler_EDF_Free, /* free entry point */ \ 49 _Scheduler_EDF_Update, /* update entry point */ \ 50 _Scheduler_EDF_Enqueue, /* enqueue entry point */ \ 51 _Scheduler_EDF_Enqueue_first, /* enqueue_first entry point */ \ 52 _Scheduler_EDF_Extract, /* extract entry point */ \ 53 _Scheduler_EDF_Priority_compare, /* compares two priorities */ \ 54 _Scheduler_EDF_Release_job, /* new period of task */ \ 55 _Scheduler_priority_Tick /* tick entry point */ \ 56 } 57 58 /** 59 * This is just a most significant bit of Priority_Control type. It 60 * distinguishes threads which are deadline driven (priority 61 * represented by a lower number than @a SCHEDULER_EDF_PRIO_MSB) from those 62 * ones who do not have any deadlines and thus are considered background 63 * tasks. 64 */ 65 #define SCHEDULER_EDF_PRIO_MSB 0x80000000 66 67 /** 68 * @typedef Scheduler_EDF_Queue_state 69 * 70 * This enumeration distiguishes state of a thread with respect to the 71 * ready queue. 72 */ 73 typedef enum { 74 SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY, 75 SCHEDULER_EDF_QUEUE_STATE_YES, 76 SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN 77 } Scheduler_EDF_Queue_state; 78 79 /** 80 * This structure handles EDF specific data of a thread. 81 */ 82 typedef struct { 83 /** 84 * Pointer to corresponding Thread Control Block. 85 */ 86 Thread_Control *thread; 87 /** 88 * Rbtree node related to this thread. 89 */ 90 RBTree_Node Node; 91 /** 92 * State of the thread with respect to ready queue. 93 */ 94 Scheduler_EDF_Queue_state queue_state; 95 } Scheduler_EDF_Per_thread; 96 97 /** 98 * Top of the ready queue. 99 */ 100 extern RBTree_Control _Scheduler_EDF_Ready_queue; 101 102 /** 103 * @brief Scheduler EDF Initialize 104 * 105 * This routine initializes the EDF scheduler. 106 */ 107 void _Scheduler_EDF_Initialize( void ); 108 109 /** 110 * @brief Scheduler EDF Block 111 * 112 * This routine removes @a the_thread from the scheduling decision, 113 * that is, removes it from the ready queue. It performs 114 * any necessary scheduling operations including the selection of 115 * a new heir thread. 116 * 117 * @param[in] the_thread is the thread to be blocked. 118 */ 119 void _Scheduler_EDF_Block( 120 Thread_Control *the_thread 121 ); 122 123 /** 124 * @brief Scheduler EDF Schedule 125 * 126 * This kernel routine sets the heir thread to be the next ready thread 127 * in the rbtree ready queue. 128 */ 129 void _Scheduler_EDF_Schedule( void ); 130 131 /** 132 * @brief Scheduler EDF Allocate 133 * 134 * This routine allocates EDF specific information of @a the_thread. 135 * 136 * @param[in] the_thread is the thread the scheduler is allocating 137 * management memory for. 138 */ 139 void *_Scheduler_EDF_Allocate( 140 Thread_Control *the_thread 141 ); 142 143 /** 144 * @brief Scheduler EDF Free 145 * 146 * This routine frees the EDF specific information of @a the_thread. 147 * 148 * @param[in] the_thread is the thread whose scheduler specific information 149 * will be deallocated. 150 */ 151 void _Scheduler_EDF_Free( 152 Thread_Control *the_thread 153 ); 154 155 /** 156 * @brief Scheduler EDF Update 157 * 158 * This routine updates position in the ready queue of @a the_thread. 159 * 160 * @param[in] the_thread will have its scheduler specific information 161 * structure updated. 162 */ 163 void _Scheduler_EDF_Update( 164 Thread_Control *the_thread 165 ); 166 167 /** 168 * @brief Scheduler EDF Unblock 169 * 170 * This routine adds @a the_thread to the scheduling decision, that is, 171 * adds it to the ready queue and updates any appropriate scheduling 172 * variables, for example the heir thread. 173 * 174 * @param[in] the_thread will be unblocked. 175 */ 176 void _Scheduler_EDF_Unblock( 177 Thread_Control *the_thread 178 ); 179 180 /** 181 * @brief Scheduler EDF Yield 182 * 183 * This routine is invoked when a thread wishes to voluntarily 184 * transfer control of the processor to another thread in the queue with 185 * equal deadline. This does not have to happen very often. 186 * 187 * This routine will remove the running THREAD from the ready queue 188 * and place back. The rbtree ready queue is responsible for FIFO ordering 189 * in such a case. 190 */ 191 void _Scheduler_EDF_Yield( void ); 192 193 /** 194 * @brief Scheduler EDF Enqueue 195 * 196 * This routine puts @a the_thread to the rbtree ready queue. 197 * 198 * @param[in] the_thread will be enqueued to the ready queue. 199 */ 200 void _Scheduler_EDF_Enqueue( 201 Thread_Control *the_thread 202 ); 203 204 /** 205 * @brief Scheduler EDF Enqueue first 206 * 207 * This routine puts @a the_thread to the rbtree ready queue. 208 * For the EDF scheduler this is the same as @a _Scheduler_EDF_Enqueue. 209 * 210 * @param[in] the_thread will be enqueued to the ready queue. 211 */ 212 void _Scheduler_EDF_Enqueue_first( 213 Thread_Control *the_thread 214 ); 215 216 /** 217 * @brief Scheduler EDF Extract 218 * 219 * This routine removes a specific thread from the scheduler's set 220 * of ready threads. 221 * 222 * @param[in] the_thread will be extracted from the ready set. 223 */ 224 void _Scheduler_EDF_Extract( 225 Thread_Control *the_thread 226 ); 227 228 /** 229 * @brief Scheduler EDF Priority compare 230 * 231 * This routine explicitly compares absolute dedlines (priorities) of threads. 232 * In case of EDF scheduling time overflow is taken into account. 233 * 234 * @return >0 for p1 > p2; 0 for p1 == p2; <0 for p1 < p2. 235 */ 236 int _Scheduler_EDF_Priority_compare ( 237 Priority_Control p1, 238 Priority_Control p2 239 ); 240 241 /** 242 * @brief Scheduler EDF Release job 243 * 244 * This routine is called when a new job of task is released. 245 * It is called only from Rate Monotonic manager in the beginning 246 * of new period. 247 * 248 * @param[in] the_thread is the owner of the job. 249 * @param[in] deadline of the new job from now. If equal to 0, 250 * the job was cancelled or deleted, thus a running task 251 * has to be suspended. 252 */ 253 void _Scheduler_EDF_Release_job ( 254 Thread_Control *the_thread, 255 uint32_t deadline 256 ); 257 258 #ifdef __cplusplus 259 } 260 #endif 261 262 /**@}*/ 263 264 #endif 265 /* end of include file */ -
new file cpukit/score/src/scheduleredf.c
diff --git a/cpukit/score/src/scheduleredf.c b/cpukit/score/src/scheduleredf.c new file mode 100644 index 0000000..2aa2d52
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 21 int _Scheduler_EDF_RBTree_compare_function 22 ( 23 RBTree_Node* n1, 24 RBTree_Node* n2 25 ) 26 { 27 Priority_Control value1 = _RBTree_Container_of 28 (n1,Scheduler_EDF_Per_thread,Node)->thread->current_priority; 29 Priority_Control value2 = _RBTree_Container_of 30 (n2,Scheduler_EDF_Per_thread,Node)->thread->current_priority; 31 32 /* 33 * This function compares only numbers for the red-black tree, 34 * but priorities have an opposite sense. 35 */ 36 return (-1)*_Scheduler_Is_priority_higher_than(value1, value2); 37 } 38 39 void _Scheduler_EDF_Initialize(void) 40 { 41 _RBTree_Initialize_empty( 42 &_Scheduler_EDF_Ready_queue, 43 &_Scheduler_EDF_RBTree_compare_function, 44 0 45 ); 46 } 47 48 /* Instantiate any global variables needed by the EDF scheduler */ 49 RBTree_Control _Scheduler_EDF_Ready_queue; -
new file cpukit/score/src/scheduleredfallocate.c
diff --git a/cpukit/score/src/scheduleredfallocate.c b/cpukit/score/src/scheduleredfallocate.c new file mode 100644 index 0000000..6d45583
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 #include <rtems/score/wkspace.h> 21 22 void *_Scheduler_EDF_Allocate( 23 Thread_Control *the_thread 24 ) 25 { 26 void *sched; 27 Scheduler_EDF_Per_thread *schinfo; 28 29 sched = _Workspace_Allocate( sizeof(Scheduler_EDF_Per_thread) ); 30 31 if ( sched ) { 32 the_thread->scheduler_info = sched; 33 schinfo = (Scheduler_EDF_Per_thread *)(the_thread->scheduler_info); 34 schinfo->thread = the_thread; 35 schinfo->queue_state = SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN; 36 } 37 38 return sched; 39 } -
new file cpukit/score/src/scheduleredfblock.c
diff --git a/cpukit/score/src/scheduleredfblock.c b/cpukit/score/src/scheduleredfblock.c new file mode 100644 index 0000000..5923171
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/score/context.h> 18 #include <rtems/score/priority.h> 19 #include <rtems/score/scheduler.h> 20 #include <rtems/score/scheduleredf.h> 21 #include <rtems/score/thread.h> 22 23 void _Scheduler_EDF_Block( 24 Thread_Control *the_thread 25 ) 26 { 27 _Scheduler_EDF_Extract( the_thread ); 28 29 /* TODO: flash critical section? */ 30 31 if ( _Thread_Is_heir( the_thread ) ) 32 _Scheduler_EDF_Schedule(); 33 34 if ( _Thread_Is_executing( the_thread ) ) 35 _Thread_Dispatch_necessary = true; 36 } -
new file cpukit/score/src/scheduleredfenqueue.c
diff --git a/cpukit/score/src/scheduleredfenqueue.c b/cpukit/score/src/scheduleredfenqueue.c new file mode 100644 index 0000000..dc59e26
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 21 void _Scheduler_EDF_Enqueue( 22 Thread_Control *the_thread 23 ) 24 { 25 Scheduler_EDF_Per_thread *sched_info = 26 (Scheduler_EDF_Per_thread*) the_thread->scheduler_info; 27 RBTree_Node *node = &(sched_info->Node); 28 29 _RBTree_Insert( &_Scheduler_EDF_Ready_queue, node ); 30 sched_info->queue_state = SCHEDULER_EDF_QUEUE_STATE_YES; 31 } -
new file cpukit/score/src/scheduleredfenqueuefirst.c
diff --git a/cpukit/score/src/scheduleredfenqueuefirst.c b/cpukit/score/src/scheduleredfenqueuefirst.c new file mode 100644 index 0000000..e8297a1
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduleredf.h> 19 20 void _Scheduler_EDF_Enqueue_first( 21 Thread_Control *the_thread 22 ) 23 { 24 _Scheduler_EDF_Enqueue(the_thread); 25 } -
new file cpukit/score/src/scheduleredfextract.c
diff --git a/cpukit/score/src/scheduleredfextract.c b/cpukit/score/src/scheduleredfextract.c new file mode 100644 index 0000000..019b68e
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/chain.h> 19 #include <rtems/score/scheduleredf.h> 20 21 void _Scheduler_EDF_Extract( 22 Thread_Control *the_thread 23 ) 24 { 25 Scheduler_EDF_Per_thread *sched_info = 26 (Scheduler_EDF_Per_thread*) the_thread->scheduler_info; 27 RBTree_Node *node = &(sched_info->Node); 28 29 _RBTree_Extract( &_Scheduler_EDF_Ready_queue, node ); 30 sched_info->queue_state = SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY; 31 } -
new file cpukit/score/src/scheduleredffree.c
diff --git a/cpukit/score/src/scheduleredffree.c b/cpukit/score/src/scheduleredffree.c new file mode 100644 index 0000000..76667f0
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 #include <rtems/score/wkspace.h> 21 22 void _Scheduler_EDF_Free( 23 Thread_Control *the_thread 24 ) 25 { 26 _Workspace_Free( the_thread->scheduler_info ); 27 } -
new file cpukit/score/src/scheduleredfprioritycompare.c
diff --git a/cpukit/score/src/scheduleredfprioritycompare.c b/cpukit/score/src/scheduleredfprioritycompare.c new file mode 100644 index 0000000..324e44a
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduleredf.h> 19 20 int _Scheduler_EDF_Priority_compare ( 21 Priority_Control p1, 22 Priority_Control p2 23 ) 24 { 25 Watchdog_Interval time = _Watchdog_Ticks_since_boot; 26 27 /* 28 * Reorder priorities to separate deadline driven and background tasks. 29 * 30 * The background tasks have p1 or p2 > SCHEDULER_EDF_PRIO_MSB. 31 * The deadline driven tasks need to have subtracted current time in order 32 * to see which deadline is closer wrt. current time. 33 */ 34 if (!(p1 & SCHEDULER_EDF_PRIO_MSB)) 35 p1 = (p1 - time) & ~SCHEDULER_EDF_PRIO_MSB; 36 if (!(p2 & SCHEDULER_EDF_PRIO_MSB)) 37 p2 = (p2 - time) & ~SCHEDULER_EDF_PRIO_MSB; 38 39 return ((p1<p2) - (p1>p2)); 40 } -
new file cpukit/score/src/scheduleredfreleasejob.c
diff --git a/cpukit/score/src/scheduleredfreleasejob.c b/cpukit/score/src/scheduleredfreleasejob.c new file mode 100644 index 0000000..0bd86e9
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 21 void _Scheduler_EDF_Release_job( 22 Thread_Control *the_thread, 23 uint32_t deadline 24 ) 25 { 26 Priority_Control new_priority; 27 28 if (deadline) { 29 /* Initializing or shifting deadline. */ 30 new_priority = (_Watchdog_Ticks_since_boot + deadline) 31 & ~SCHEDULER_EDF_PRIO_MSB; 32 } 33 else { 34 /* Switch back to background priority. */ 35 new_priority = the_thread->Start.initial_priority; 36 } 37 38 the_thread->real_priority = new_priority; 39 _Thread_Change_priority(the_thread, new_priority, true); 40 } -
new file cpukit/score/src/scheduleredfschedule.c
diff --git a/cpukit/score/src/scheduleredfschedule.c b/cpukit/score/src/scheduleredfschedule.c new file mode 100644 index 0000000..1482be8
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/score/scheduler.h> 18 #include <rtems/score/scheduleredf.h> 19 20 void _Scheduler_EDF_Schedule(void) 21 { 22 RBTree_Node *first_node = 23 _RBTree_Peek(&_Scheduler_EDF_Ready_queue, RBT_LEFT); 24 Scheduler_EDF_Per_thread *sched_info = 25 _RBTree_Container_of(first_node, Scheduler_EDF_Per_thread, Node); 26 27 _Thread_Heir = (Thread_Control *) sched_info->thread; 28 } -
new file cpukit/score/src/scheduleredfunblock.c
diff --git a/cpukit/score/src/scheduleredfunblock.c b/cpukit/score/src/scheduleredfunblock.c new file mode 100644 index 0000000..bca071a
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/score/scheduler.h> 18 #include <rtems/score/scheduleredf.h> 19 20 void _Scheduler_EDF_Unblock( 21 Thread_Control *the_thread 22 ) 23 { 24 _Scheduler_EDF_Enqueue(the_thread); 25 /* TODO: flash critical section? */ 26 27 /* 28 * If the thread that was unblocked is more important than the heir, 29 * then we have a new heir. This may or may not result in a 30 * context switch. 31 * 32 * Normal case: 33 * If the current thread is preemptible, then we need to do 34 * a context switch. 35 * Pseudo-ISR case: 36 * Even if the thread isn't preemptible, if the new heir is 37 * a pseudo-ISR system task, we need to do a context switch. 38 */ 39 if ( _Scheduler_Is_priority_lower_than( 40 _Thread_Heir->current_priority, 41 the_thread->current_priority )) { 42 _Thread_Heir = the_thread; 43 if ( _Thread_Executing->is_preemptible || 44 the_thread->current_priority == 0 ) 45 _Thread_Dispatch_necessary = true; 46 } 47 } -
new file cpukit/score/src/scheduleredfupdate.c
diff --git a/cpukit/score/src/scheduleredfupdate.c b/cpukit/score/src/scheduleredfupdate.c new file mode 100644 index 0000000..a4592d8
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/config.h> 18 #include <rtems/score/priority.h> 19 #include <rtems/score/scheduler.h> 20 #include <rtems/score/scheduleredf.h> 21 #include <rtems/score/thread.h> 22 23 void _Scheduler_EDF_Update( 24 Thread_Control *the_thread 25 ) 26 { 27 Scheduler_EDF_Per_thread *sched_info = 28 (Scheduler_EDF_Per_thread*)the_thread->scheduler_info; 29 RBTree_Node *the_node = &(sched_info->Node); 30 31 if (sched_info->queue_state == SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN) { 32 /* Shifts the priority to the region of background tasks. */ 33 the_thread->Start.initial_priority |= (SCHEDULER_EDF_PRIO_MSB); 34 the_thread->real_priority = the_thread->Start.initial_priority; 35 the_thread->current_priority = the_thread->Start.initial_priority; 36 sched_info->queue_state = SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY; 37 } 38 39 if ( sched_info->queue_state == SCHEDULER_EDF_QUEUE_STATE_YES ) { 40 _RBTree_Extract(&_Scheduler_EDF_Ready_queue, the_node); 41 _RBTree_Insert(&_Scheduler_EDF_Ready_queue, the_node); 42 43 _Scheduler_EDF_Schedule(); 44 if ( _Thread_Executing != _Thread_Heir ) { 45 if ( _Thread_Executing->is_preemptible || 46 the_thread->current_priority == 0 ) 47 _Thread_Dispatch_necessary = true; 48 } 49 } 50 } -
new file cpukit/score/src/scheduleredfyield.c
diff --git a/cpukit/score/src/scheduleredfyield.c b/cpukit/score/src/scheduleredfyield.c new file mode 100644 index 0000000..be1b07a
- + 1 /* 2 * Copyright (C) 2011 Petr Benes. 3 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 4 * 5 * The license and distribution terms for this file may be 6 * found in the file LICENSE in this distribution or at 7 * http://www.rtems.com/license/LICENSE. 8 * 9 * $Id$ 10 */ 11 12 #if HAVE_CONFIG_H 13 #include "config.h" 14 #endif 15 16 #include <rtems/system.h> 17 #include <rtems/score/isr.h> 18 #include <rtems/score/scheduler.h> 19 #include <rtems/score/scheduleredf.h> 20 #include <rtems/score/thread.h> 21 22 void _Scheduler_EDF_Yield(void) 23 { 24 Scheduler_EDF_Per_thread *first_info; 25 RBTree_Node *first_node; 26 ISR_Level level; 27 28 Thread_Control *executing = _Thread_Executing; 29 Scheduler_EDF_Per_thread *executing_info = 30 (Scheduler_EDF_Per_thread *) executing->scheduler_info; 31 RBTree_Node *executing_node = &(executing_info->Node); 32 33 _ISR_Disable( level ); 34 35 if ( !_RBTree_Has_only_one_node(&_Scheduler_EDF_Ready_queue) ) { 36 /* 37 * The RBTree has more than one node, enqueue behind the tasks 38 * with the same priority in case there are such ones. 39 */ 40 _RBTree_Extract( &_Scheduler_EDF_Ready_queue, executing_node ); 41 _RBTree_Insert( &_Scheduler_EDF_Ready_queue, executing_node ); 42 43 _ISR_Flash( level ); 44 45 if ( _Thread_Is_heir( executing ) ) { 46 first_node = _RBTree_Peek( &_Scheduler_EDF_Ready_queue, RBT_LEFT ); 47 first_info = 48 _RBTree_Container_of(first_node, Scheduler_EDF_Per_thread, Node); 49 _Thread_Heir = first_info->thread; 50 } 51 _Thread_Dispatch_necessary = true; 52 } 53 else if ( !_Thread_Is_heir( executing ) ) 54 _Thread_Dispatch_necessary = true; 55 56 _ISR_Enable( level ); 57 }