]> rtime.felk.cvut.cz Git - rtems-pluggable-edf.git/commitdiff
EDF project completely shuffled
authorPetr Benes <benesp16@fel.cvut.cz>
Wed, 30 Mar 2011 13:25:08 +0000 (15:25 +0200)
committerPetr Benes <benesp16@fel.cvut.cz>
Wed, 30 Mar 2011 13:25:08 +0000 (15:25 +0200)
The pluggable EDF scheduled has been moved to a separate directory
as an independent library linkable with another programs.

14 files changed:
rtems-omk-template/Makefile.omk
rtems-omk-template/appfoo/Makefile.omk
rtems-omk-template/appfoo/scheduler_priority.c [deleted file]
rtems-omk-template/appfoo/system.h
rtems-omk-template/appfoo/task_1.c
rtems-omk-template/appfoo/task_2.c
rtems-omk-template/config.omk [new file with mode: 0644]
rtems-omk-template/edf/Makefile [new file with mode: 0644]
rtems-omk-template/edf/Makefile.omk [new file with mode: 0644]
rtems-omk-template/edf/edf_types.h [new file with mode: 0644]
rtems-omk-template/edf/rbtree.c [moved from rtems-omk-template/appfoo/rbtree.c with 100% similarity]
rtems-omk-template/edf/rbtree.h [moved from rtems-omk-template/appfoo/rbtree.h with 100% similarity]
rtems-omk-template/edf/scheduler_edf.c [new file with mode: 0644]
rtems-omk-template/edf/scheduler_edf.h [moved from rtems-omk-template/appfoo/scheduler_priority.h with 50% similarity]

index 98ad3fc0c455413ff7c7b6008cdb0a7daf0f5c35..484a7d19ebffc1fc337c6e9fcedb659172f4fdc2 100644 (file)
@@ -1,2 +1,2 @@
-SUBDIRS = system_opt libbar appfoo 
+SUBDIRS = system_opt libbar appfoo edf
 
index ed000fec8dd322b6358633f5d900319556c3593a..b2bd1f9ff710be38d7ce63e39656b2d22e8912d7 100644 (file)
@@ -5,11 +5,13 @@ bin_PROGRAMS = appfoo
 
 #lib_LIBRARIES = 
 
-#include_HEADERS = 
+include_HEADERS = ../edf/scheduler_edf.h ../edf/edf_types.h ../edf/rbtree.h
 
-appfoo_SOURCES += init.c task_1.c task_2.c scheduler_edf.c scheduler_priority.c rbtree.c
+appfoo_SOURCES += init.c task_1.c task_2.c
 
 #appfoo_EMBEDTARFILES = rootfs
 
 lib_LOADLIBES += bar
 
+appfoo_LIBS = edf
+
diff --git a/rtems-omk-template/appfoo/scheduler_priority.c b/rtems-omk-template/appfoo/scheduler_priority.c
deleted file mode 100644 (file)
index d2a0c88..0000000
+++ /dev/null
@@ -1,393 +0,0 @@
-// =====================================================================================
-// =====================================================================================
-// =====================================================================================
-
-/*
- *  Scheduler Priority Handler / Allocate
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityallocate.c,v 1.1 2011/02/18 15:12:43 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-#include <rtems/score/wkspace.h>
-
-void* _Scheduler_priority_Allocate (
-  Thread_Control        *the_thread
-)
-{
-  void *sched;
-
-  sched = _Workspace_Allocate( sizeof(Scheduler_priority_Per_thread) );
-
-  the_thread->scheduler_info = (Scheduler_priority_Per_thread*) sched;
-
-  return sched;
-}
-/*
- *  Scheduler Handler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityblock.c,v 1.4 2011/02/18 15:12:43 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/context.h>
-#include <rtems/score/interr.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/object.h>
-#include <rtems/score/priority.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-#include <rtems/score/thread.h>
-
-void _Scheduler_priority_Block(
-  Thread_Control   *the_thread
-)
-{
-  _Scheduler_priority_Ready_queue_extract( the_thread );
-
-  /* TODO: flash critical section? */
-
-  if ( _Thread_Is_heir( the_thread ) )
-     _Scheduler_priority_Schedule_body();
-
-  if ( _Thread_Is_executing( the_thread ) )
-    _Thread_Dispatch_necessary = true;
-
-}
-/*
- *  Scheduler Handler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriority.c,v 1.5 2011/02/28 00:10:38 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/prioritybitmap.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-
-/* Instantiate any global variables needed by the priority scheduler */
-volatile Priority_bit_map_Control _Priority_Major_bit_map;
-
-Priority_bit_map_Control          _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
-
-void _Scheduler_priority_Initialize(void)
-{
-  _Scheduler_priority_Ready_queue_initialize();
-  _Priority_bit_map_Handler_initialization();
-}
-/*
- *  COPYRIGHT (c) 2011.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityenqueue.c,v 1.1 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-
-void _Scheduler_priority_Enqueue( 
-  Thread_Control      *the_thread
-)
-{
-   _Scheduler_priority_Ready_queue_enqueue( the_thread );
-}
-/*
- *  COPYRIGHT (c) 2011.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityenqueuefirst.c,v 1.1 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/schedulerpriority.h>
-
-void _Scheduler_priority_Enqueue_first( 
-  Thread_Control      *the_thread
-)
-{
-  _Scheduler_priority_Ready_queue_enqueue_first( the_thread );
-}
-
-/*  Scheduler Simple Handler / Extract
- *
- *  COPYRIGHT (c) 2011.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityextract.c,v 1.2 2011/02/28 00:10:38 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/schedulerpriority.h>
-
-void _Scheduler_priority_Extract( 
-  Thread_Control      *the_thread
-)
-{
-  _Scheduler_priority_Ready_queue_extract( the_thread );
-}
-/*
- *  Scheduler Handler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityfree.c,v 1.1 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-#include <rtems/score/wkspace.h>
-
-void _Scheduler_priority_Free (
-  Thread_Control    *the_thread
-)
-{
-  _Workspace_Free( the_thread->scheduler_info );
-}
-/*
- *  Scheduler Handler / Scheduler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityschedule.c,v 1.4 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-
-void _Scheduler_priority_Schedule(void)
-{
-  _Scheduler_priority_Schedule_body();
-}
-/*
- *  Scheduler Handler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityunblock.c,v 1.4 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-
-void _Scheduler_priority_Unblock (
-  Thread_Control          *the_thread
-)
-{
-  _Scheduler_priority_Ready_queue_enqueue(the_thread);
-
-  /* TODO: flash critical section? */
-
-  /*
-   *  If the thread that was unblocked is more important than the heir,
-   *  then we have a new heir.  This may or may not result in a
-   *  context switch.
-   *
-   *  Normal case:
-   *    If the current thread is preemptible, then we need to do
-   *    a context switch.
-   *  Pseudo-ISR case:
-   *    Even if the thread isn't preemptible, if the new heir is
-   *    a pseudo-ISR system task, we need to do a context switch.
-   */
-  if ( the_thread->current_priority < _Thread_Heir->current_priority ) {
-    _Thread_Heir = the_thread;
-    if ( _Thread_Executing->is_preemptible ||
-        the_thread->current_priority == 0 )
-      _Thread_Dispatch_necessary = true;
-  }
-}
-/*
- *  Scheduler Handler
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityupdate.c,v 1.2 2011/02/28 00:10:38 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/priority.h>
-#include <rtems/score/prioritybitmap.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-#include <rtems/score/thread.h>
-
-void _Scheduler_priority_Update(
-  Thread_Control    *the_thread
-)
-{
-  Scheduler_priority_Per_thread *sched_info;
-  Chain_Control                 *rq;
-
-  sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
-  rq         = (Chain_Control *) _Scheduler.information;
-
-  sched_info->ready_chain = &rq[ the_thread->current_priority ];
-
-  _Priority_bit_map_Initialize_information( 
-    &sched_info->Priority_map, 
-    the_thread->current_priority 
-  );
-}
-/*
- *  Scheduler Priority Handler / Yield
- *
- *  Copyright (C) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriorityyield.c,v 1.6 2011/02/18 15:12:44 joel Exp $
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/schedulerpriority.h>
-#include <rtems/score/thread.h>
-
-/*
- *  INTERRUPT LATENCY:
- *    ready chain
- *    select heir
- */
-
-void _Scheduler_priority_Yield(void)
-{
-  Scheduler_priority_Per_thread *sched_info;
-  ISR_Level                      level;
-  Thread_Control                *executing;
-  Chain_Control                 *ready;
-
-  executing  = _Thread_Executing;
-  sched_info = (Scheduler_priority_Per_thread *) executing->scheduler_info;
-  ready      = sched_info->ready_chain;
-  _ISR_Disable( level );
-    if ( !_Chain_Has_only_one_node( ready ) ) {
-      _Chain_Extract_unprotected( &executing->Object.Node );
-      _Chain_Append_unprotected( ready, &executing->Object.Node );
-
-      _ISR_Flash( level );
-
-      if ( _Thread_Is_heir( executing ) )
-        _Thread_Heir = (Thread_Control *) _Chain_First( ready );
-      _Thread_Dispatch_necessary = true;
-    }
-    else if ( !_Thread_Is_heir( executing ) )
-      _Thread_Dispatch_necessary = true;
-
-  _ISR_Enable( level );
-}
index bccc673bfb04f2fb9d822c18d96136ef634981b8..71f9d3655eb4d9963b6e077926b2f6f126d7e5e6 100644 (file)
@@ -81,24 +81,19 @@ rtems_task Init(
  *    - CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER - per task memory
  */
                 
-// to enable our own scheduler
+/// Enable yur own scheduler
 #define CONFIGURE_SCHEDULER_USER
 
 /**
- *  Entry points for a edf Scheduler.
+ *  EDF scheduler configuration.
  */
-#define CONFIGURE_SCHEDULER_USER_ENTRY_POINTS 
-// EDF
-#include "scheduler_edf.h"
-#include "rbtree.h"
-#define SCHEDULER_ENTRY_POINTS SCHEDULER_EDF_ENTRY_POINTS
-       // Priority
-       //#include "scheduler_priority.h"
-       //#define SCHEDULER_ENTRY_POINTS SCHEDULER_PRIORITY_ENTRY_POINTS
-
-#define CONFIGURE_MEMORY_FOR_SCHEDULER (_Configure_From_workspace(sizeof(EDF_Chain_Control)))
-#define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (_Configure_From_workspace(sizeof(RBT_Node)))
-
+#ifdef CONFIGURE_SCHEDULER_USER
+       #define CONFIGURE_SCHEDULER_USER_ENTRY_POINTS 
+       #include "scheduler_edf.h"
+       #define SCHEDULER_ENTRY_POINTS SCHEDULER_EDF_ENTRY_POINTS
+       #define CONFIGURE_MEMORY_FOR_SCHEDULER (_Configure_From_workspace(sizeof(EDF_Chain_Control)))
+       #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (_Configure_From_workspace(sizeof(RBT_Node)))
+#endif
 
 
 
index ffd6fa24ca624a824d271c7636c4d0bacbacd4c2..ea67f7f97d40df37284376644816f60b1b8f4d64 100644 (file)
@@ -13,11 +13,14 @@ rtems_task Task_1(
   rtems_task_argument argument
 )
 {
+  int i, s;    
   rtems_status_code status;
   printf("*** Starting up Task_1 ***\n");
 
   while(1){
     printf("Task_1 woken\n");
+    for (i = 0; i < 10000; i++)
+      s = i+i;
     status = rtems_task_wake_after( TICKS_PER_SECOND );
     check_rtems_status( status, 0, "rtems_task_wake_after" );
   }
index 160ff6c9e50147542590e1145b3284f33bc0e1d4..ea8b3911f5ae2f9ba4c34ed73c3543be375f026e 100644 (file)
@@ -13,8 +13,7 @@ rtems_task Task_2(
   rtems_task_argument argument
 )
 {
-  int i;
-  int s;
+  int i, s;
   rtems_status_code status;
   printf("*** Starting up Task_2 ***\n");
 
diff --git a/rtems-omk-template/config.omk b/rtems-omk-template/config.omk
new file mode 100644 (file)
index 0000000..d57fc65
--- /dev/null
@@ -0,0 +1,3 @@
+#RTEMS_MAKEFILE_PATH=/home/petr/git/rtems/b-rtems-icecube/powerpc-rtems4.10/icecube
+RTEMS_MAKEFILE_PATH=/home/petr/git/rtems/b-rtems-i386/i386-rtems4.11/pc386
+  
\ No newline at end of file
diff --git a/rtems-omk-template/edf/Makefile b/rtems-omk-template/edf/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/rtems-omk-template/edf/Makefile.omk b/rtems-omk-template/edf/Makefile.omk
new file mode 100644 (file)
index 0000000..bef333c
--- /dev/null
@@ -0,0 +1,13 @@
+#default_CONFIG += CONFIG_OC_BUILD4RTEMS=y
+#default_CONFIG += CONFIG_OC_GDBSTUB=n
+
+lib_LIBRARIES = edf
+
+#include_HEADERS = 
+
+edf_SOURCES += scheduler_edf.c rbtree.c
+
+#appfoo_EMBEDTARFILES = rootfs
+
+#lib_LOADLIBES += bar
+
diff --git a/rtems-omk-template/edf/edf_types.h b/rtems-omk-template/edf/edf_types.h
new file mode 100644 (file)
index 0000000..e30080e
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __EDF_TYPES_h
+#define __EDF_TYPES_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/types.h>
+#include <rtems/score/thread.h>
+
+
+typedef uint32_t Deadline_Control;
+
+#define ABS_DEADLINE_MAXIMUM 0xffffffff
+
+typedef enum node_color_struct { N_RED, N_BLACK } Node_Color;
+typedef Thread_Control EDF_Node;
+
+typedef struct {
+       EDF_Node   *root;   // root of tree
+       EDF_Node   *first;  // first task in queue
+} EDF_Chain_Control; 
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__EDF_TYPES_h*/
diff --git a/rtems-omk-template/edf/scheduler_edf.c b/rtems-omk-template/edf/scheduler_edf.c
new file mode 100644 (file)
index 0000000..76eb478
--- /dev/null
@@ -0,0 +1,137 @@
+#include "scheduler_edf.h"
+#include "rbtree.h"
+#include <stdio.h>
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/percpu.h>
+
+
+
+void _Scheduler_edf_Initialize(void) {
+       // initialize the RB tree
+       _Thread_Ready_EDF_chain.root = NULL;
+       _Thread_Ready_EDF_chain.first = NULL;
+       _Thread_Heir = NULL;
+       _Thread_Executing = NULL;
+}
+
+void _Scheduler_edf_Block(  Thread_Control    *the_thread ) {
+       _Scheduler_edf_Extract(the_thread);
+       
+       /* TODO: flash critical section? */
+
+       if ( _Thread_Is_heir( the_thread ) )
+               _Scheduler_edf_Schedule();
+
+       if ( _Thread_Is_executing( the_thread ) )
+               _Thread_Dispatch_necessary = true;      
+}
+
+void _Scheduler_edf_Schedule(void) {
+       // set the heir
+       _Thread_Heir = (Thread_Control *) _Thread_Ready_EDF_chain.first;
+}
+
+void * _Scheduler_edf_Allocate(  Thread_Control      *the_thread) {
+       void * sched;
+       RBT_Node *schinfo;
+       sched = _Workspace_Allocate (sizeof(RBT_Node));
+       the_thread->scheduler_info = (RBT_Node *) sched;
+       
+       schinfo = (RBT_Node *)(the_thread->scheduler_info);
+       schinfo->rel_deadline = the_thread->real_priority;
+       schinfo->abs_deadline = 0;
+       schinfo->left = NULL;
+       schinfo->right = NULL;
+       schinfo->parent = NULL;
+       schinfo->ready_chain = &_Thread_Ready_EDF_chain;
+       
+       return sched;
+}
+
+void _Scheduler_edf_Free(  Thread_Control      *the_thread) {
+       _Workspace_Free (the_thread->scheduler_info);
+}
+
+void _Scheduler_edf_Update(  Thread_Control      *the_thread) {
+       // after a priority changes, just extract and insert again
+       //in case it is in the tree
+//     EDF_Chain_Control* chain = ((RBT_Node*)the_thread->scheduler_info)->ready_chain;
+//     _RBT_Extract(chain, the_thread); 
+//     _RBT_Insert(chain, the_thread); // preserve the abs_deadline
+}
+
+void _Scheduler_edf_Unblock(  Thread_Control    *the_thread ) {
+       _Scheduler_edf_Enqueue(the_thread);
+       /* TODO: flash critical section? */
+
+       /*
+       *  If the thread that was unblocked is more important than the heir,
+       *  then we have a new heir.  This may or may not result in a
+       *  context switch.
+       *
+       *  Normal case:
+       *    If the current thread is preemptible, then we need to do
+       *    a context switch.
+       *  Pseudo-ISR case:
+       *    Even if the thread isn't preemptible, if the new heir is
+       *    a pseudo-ISR system task, we need to do a context switch.
+       */
+       if ( the_thread->current_priority < _Thread_Heir->current_priority ) {
+               _Thread_Heir = the_thread;
+               if ( _Thread_Executing->is_preemptible || the_thread->current_priority == 0 )
+                       _Thread_Dispatch_necessary = true;      
+       }
+}
+
+void _Scheduler_edf_Yield( void ) {
+       RBT_Node *sched_info;
+       ISR_Level                      level;
+       Thread_Control                *executing;
+       EDF_Chain_Control                 *ready;
+
+       executing  = _Thread_Executing;
+       sched_info = (RBT_Node *) executing->scheduler_info;
+       ready      = sched_info->ready_chain;
+       _ISR_Disable( level );
+       if ( !_RBT_Has_only_one_node( ready ) ) {
+               _RBT_Extract(ready,executing); 
+               _RBT_Insert(ready,executing); // preserve the abs_deadline
+
+               _ISR_Flash( level );
+
+               if ( _Thread_Is_heir( executing ) )
+                       _Thread_Heir = (Thread_Control *) ready->first;
+               _Thread_Dispatch_necessary = TRUE;
+       }
+       else if ( !_Thread_Is_heir( executing ) )
+               _Thread_Dispatch_necessary = TRUE;
+
+       _ISR_Enable( level );
+       
+}
+
+void _Scheduler_edf_Enqueue(  Thread_Control    *the_thread) {
+       RBT_Node *node = (RBT_Node*)the_thread->scheduler_info;
+       EDF_Chain_Control *chain = node->ready_chain;
+       //FIXME: instead of this hack for idle task, make up a general rule
+       if (node->rel_deadline == 255) 
+               node->abs_deadline = ABS_DEADLINE_MAXIMUM;      
+       else
+               node->abs_deadline = _Watchdog_Ticks_since_boot + node->rel_deadline;
+       _RBT_Insert(chain,the_thread);
+
+}
+
+void _Scheduler_edf_Enqueue_first(  Thread_Control    *the_thread) {
+       // FIXME: force first position
+       _Scheduler_edf_Enqueue(the_thread);
+}
+
+void _Scheduler_edf_Extract(  Thread_Control     *the_thread) {
+       EDF_Chain_Control* chain = ((RBT_Node*)the_thread->scheduler_info)->ready_chain;
+       _RBT_Extract(chain,the_thread);
+}
+
similarity index 50%
rename from rtems-omk-template/appfoo/scheduler_priority.h
rename to rtems-omk-template/edf/scheduler_edf.h
index 3a75deee1e8a982c358867c5dcefeff5a076b743..02e4d2a3b339e4685c17b55334db4eff9f8730ec 100644 (file)
@@ -1,71 +1,36 @@
-/**
- *  @file  rtems/score/schedulerpriority.h
- *
- *  This include file contains all the constants and structures associated
- *  with the manipulation of threads for the priority-based scheduler.
- */
-
-/*
- *  Copryight (c) 2010 Gedare Bloom.
- *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id: schedulerpriority.h,v 1.8 2011/03/08 19:27:35 joel Exp $
- */
+#ifndef _SCHEDULER_EDF_H
+#define _SCHEDULER_EDF_H
 
-#ifndef _RTEMS_SCORE_SCHEDULERPRIORITY_H
-#define _RTEMS_SCORE_SCHEDULERPRIORITY_H
-
-#include <rtems/score/chain.h>
-#include <rtems/score/priority.h>
 #include <rtems/score/scheduler.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include "edf_types.h"
+#include "rbtree.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+// keeps the ready queue for EDF
+EDF_Chain_Control _Thread_Ready_EDF_chain;
 
-/**
- *  @addtogroup ScoreScheduler
- *
- */
-/**@{*/
+#define SCHEDULER_EDF_ENTRY_POINTS \
+       { \
+       _Scheduler_edf_Initialize,    /* initialize entry point */ \
+       _Scheduler_edf_Schedule,      /* schedule entry point */ \
+       _Scheduler_edf_Yield,         /* yield entry point */ \
+       _Scheduler_edf_Block,         /* block entry point */ \
+       _Scheduler_edf_Unblock,       /* unblock entry point */ \
+       _Scheduler_edf_Allocate,      /* allocate entry point */ \
+       _Scheduler_edf_Free,          /* free entry point */ \
+       _Scheduler_edf_Update,        /* update entry point */ \
+       _Scheduler_edf_Enqueue,       /* enqueue entry point */ \
+       _Scheduler_edf_Enqueue_first, /* enqueue_first entry point */ \
+       _Scheduler_edf_Extract        /* extract entry point */ \
+       }
 
-/**
- *  Entry points for the Deterministic Priority Based Scheduler.
- */
-#define SCHEDULER_PRIORITY_ENTRY_POINTS \
-  { \
-    _Scheduler_priority_Initialize,    /* initialize entry point */ \
-    _Scheduler_priority_Schedule,      /* schedule entry point */ \
-    _Scheduler_priority_Yield,         /* yield entry point */ \
-    _Scheduler_priority_Block,         /* block entry point */ \
-    _Scheduler_priority_Unblock,       /* unblock entry point */ \
-    _Scheduler_priority_Allocate,      /* allocate entry point */ \
-    _Scheduler_priority_Free,          /* free entry point */ \
-    _Scheduler_priority_Update,        /* update entry point */ \
-    _Scheduler_priority_Enqueue,       /* enqueue entry point */ \
-    _Scheduler_priority_Enqueue_first, /* enqueue_first entry point */ \
-    _Scheduler_priority_Extract        /* extract entry point */ \
-  }
-
-/**
- * Per-thread data related to the _Scheduler_PRIORITY scheduling policy.
- */
-typedef struct {
-  /** This field points to the Ready FIFO for this thread's priority. */
-  Chain_Control                        *ready_chain;
 
-  /** This field contains precalculated priority map indices. */
-  Priority_bit_map_Information          Priority_map;
-} Scheduler_priority_Per_thread;
 
 /**
  * This routine initializes the priority scheduler.
  */
-void _Scheduler_priority_Initialize(void);
+void _Scheduler_edf_Initialize(void);
 
 /**
  *  This routine removes @a the_thread from the scheduling decision, 
@@ -75,7 +40,7 @@ void _Scheduler_priority_Initialize(void);
  *
  *  @param[in] the_thread is the thread to be blocked
  */
-void _Scheduler_priority_Block( 
+void _Scheduler_edf_Block( 
   Thread_Control    *the_thread 
 );
 
@@ -83,7 +48,7 @@ void _Scheduler_priority_Block(
  *  This kernel routine sets the heir thread to be the next ready thread 
  *  by invoking the_scheduler->ready_queue->operations->first().
  */
-void _Scheduler_priority_Schedule(void);
+void _Scheduler_edf_Schedule(void);
 
 /**
  *  This routine allocates @a the_thread->scheduler.
@@ -91,7 +56,7 @@ void _Scheduler_priority_Schedule(void);
  *  @param[in] the_thread is the thread the scheduler is allocating
  *             management memory for
  */
-void * _Scheduler_priority_Allocate(
+void * _Scheduler_edf_Allocate(
   Thread_Control      *the_thread
 );
 
@@ -101,7 +66,7 @@ void * _Scheduler_priority_Allocate(
  *  @param[in] the_thread is the thread whose scheduler specific information
  *             will be deallocated.
  */
-void _Scheduler_priority_Free(
+void _Scheduler_edf_Free(
   Thread_Control      *the_thread
 );
 
@@ -112,7 +77,7 @@ void _Scheduler_priority_Free(
  *  @param[in] the_thread will have its scheduler specific information
  *             structure updated.
  */
-void _Scheduler_priority_Update(
+void _Scheduler_edf_Update(
   Thread_Control      *the_thread
 );
 
@@ -123,7 +88,7 @@ void _Scheduler_priority_Update(
  *
  *  @param[in] the_thread will be unblocked
  */
-void _Scheduler_priority_Unblock(
+void _Scheduler_edf_Unblock(
   Thread_Control    *the_thread 
 );
 
@@ -138,14 +103,14 @@ void _Scheduler_priority_Unblock(
  *  timeslice counter is reset.  The heir THREAD will be updated if the
  *  running is also the currently the heir.
  */
-void _Scheduler_priority_Yield( void );
+void _Scheduler_edf_Yield( void );
 
 /**
  *  This routine puts @a the_thread on to the priority-based ready queue.
  *
  *  @param[in] the_thread will be enqueued at the TAIL of its priority.
  */
-void _Scheduler_priority_Enqueue(
+void _Scheduler_edf_Enqueue(
   Thread_Control    *the_thread
 );
 
@@ -156,7 +121,7 @@ void _Scheduler_priority_Enqueue(
  *
  *  @param[in] the_thread will be enqueued at the HEAD of its priority.
  */
-void _Scheduler_priority_Enqueue_first(
+void _Scheduler_edf_Enqueue_first(
   Thread_Control    *the_thread
 );
 
@@ -166,29 +131,10 @@ void _Scheduler_priority_Enqueue_first(
  *
  *  @param[in] the_thread will be extracted from the ready set.
  */
-void _Scheduler_priority_Extract(
+void _Scheduler_edf_Extract(
   Thread_Control     *the_thread
 );
 
-/**
- *  This is the major bit map.
- */
-extern volatile Priority_bit_map_Control _Priority_Major_bit_map;
-
-/**
- *  This is the minor bit map.
- */
-extern Priority_bit_map_Control _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
-
-#ifndef __RTEMS_APPLICATION__
-#include <rtems/score/schedulerpriority.inl>
-#endif
-
-#ifdef __cplusplus
-}
-#endif
 
-/**@}*/
 
-#endif
-/* end of include file */
+#endif /*_SCHEDULER_EDF_H*/
\ No newline at end of file