summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-16 16:32:22 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-16 16:32:22 +0000
commit0118ed65ea96db1032771620fc5fb1c1290f9d47 (patch)
tree30a21550f5c2fc753634491040113fce235a3b5c /cpukit/score/src
parent2011-03-16 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-0118ed65ea96db1032771620fc5fb1c1290f9d47.tar.bz2
2011-03-16 Jennifer Averett <jennifer.averett@OARcorp.com>
PR 1743/cpu * sapi/include/confdefs.h, score/Makefile.am, score/preinstall.am: Add Simple Priority Scheduler as complement to existing Deterministic Priority Scheduler. This scheduler serves both as an example and as a lighter weight implementation for smaller systems. * score/include/rtems/score/schedulersimple.h, score/inline/rtems/score/schedulersimple.inl, score/src/schedulersimple.c, score/src/schedulersimpleblock.c, score/src/schedulersimpleenqueue.c, score/src/schedulersimpleenqueuefirst.c, score/src/schedulersimpleextract.c, score/src/schedulersimplereadyqueueenqueue.c, score/src/schedulersimplereadyqueueenqueuefirst.c, score/src/schedulersimpleschedule.c, score/src/schedulersimpleunblock.c, score/src/schedulersimpleyield.c: New files.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/schedulersimple.c84
-rw-r--r--cpukit/score/src/schedulersimpleblock.c39
-rw-r--r--cpukit/score/src/schedulersimpleenqueue.c29
-rw-r--r--cpukit/score/src/schedulersimpleenqueuefirst.c28
-rw-r--r--cpukit/score/src/schedulersimpleextract.c28
-rw-r--r--cpukit/score/src/schedulersimplereadyqueueenqueue.c48
-rw-r--r--cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c52
-rw-r--r--cpukit/score/src/schedulersimpleschedule.c34
-rw-r--r--cpukit/score/src/schedulersimpleunblock.c47
-rw-r--r--cpukit/score/src/schedulersimpleyield.c42
10 files changed, 431 insertions, 0 deletions
diff --git a/cpukit/score/src/schedulersimple.c b/cpukit/score/src/schedulersimple.c
new file mode 100644
index 0000000000..7a7ed944f4
--- /dev/null
+++ b/cpukit/score/src/schedulersimple.c
@@ -0,0 +1,84 @@
+/*
+ * Scheduler Simple Handler / Initialize
+ * Scheduler Simple Handler / Allocate (Empty Routine)
+ * Scheduler Simple Handler / Update (Empty Routine)
+ * Scheduler Simple Handler / Free (Empty Routine)
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulersimple.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule allocate
+ *
+ * Note: returns a non-zero value, or else thread initialize thinks the
+ * allocation failed.
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void * _Scheduler_simple_Allocate(
+ Thread_Control *the_thread
+)
+{
+ return (void*)-1; /* maybe pick an appropriate poison value */
+}
+
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule update
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void _Scheduler_simple_Update(
+ Thread_Control *the_thread
+)
+{
+}
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule free
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void _Scheduler_simple_Free(
+ Thread_Control *the_thread
+)
+{
+}
+
+/**
+ * This routine initializes the simple scheduler.
+ */
+void _Scheduler_simple_Initialize ( void )
+{
+ void *f;
+
+ /*
+ * Initialize Ready Queue
+ */
+
+ /* allocate ready queue structures */
+ f = _Workspace_Allocate_or_fatal_error( sizeof(Chain_Control) );
+ _Scheduler.information = f;
+
+ /* initialize ready queue structure */
+ _Chain_Initialize_empty( (Chain_Control *)f );
+}
diff --git a/cpukit/score/src/schedulersimpleblock.c b/cpukit/score/src/schedulersimpleblock.c
new file mode 100644
index 0000000000..212f4f10bf
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleblock.c
@@ -0,0 +1,39 @@
+/*
+ * Scheduler Simple Handler / Block
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#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/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Block(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Extract(the_thread);
+
+ if ( _Thread_Is_heir( the_thread ) )
+ _Scheduler_simple_Schedule();
+
+ if ( _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+}
diff --git a/cpukit/score/src/schedulersimpleenqueue.c b/cpukit/score/src/schedulersimpleenqueue.c
new file mode 100644
index 0000000000..8e5e6381c5
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleenqueue.c
@@ -0,0 +1,29 @@
+/*
+ * Schedule Simple Handler / Enqueue
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue( the_thread );
+}
diff --git a/cpukit/score/src/schedulersimpleenqueuefirst.c b/cpukit/score/src/schedulersimpleenqueuefirst.c
new file mode 100644
index 0000000000..d6fd7dda98
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleenqueuefirst.c
@@ -0,0 +1,28 @@
+/*
+ * Schedule Simple Handler / Enqueue First
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue_first( the_thread );
+}
diff --git a/cpukit/score/src/schedulersimpleextract.c b/cpukit/score/src/schedulersimpleextract.c
new file mode 100644
index 0000000000..208fcb55bd
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleextract.c
@@ -0,0 +1,28 @@
+/*
+ * Schedule 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Extract(
+ Thread_Control *the_thread
+)
+{
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimplereadyqueueenqueue.c b/cpukit/score/src/schedulersimplereadyqueueenqueue.c
new file mode 100644
index 0000000000..788f94b20b
--- /dev/null
+++ b/cpukit/score/src/schedulersimplereadyqueueenqueue.c
@@ -0,0 +1,48 @@
+/*
+ * Schedule Simple Handler / Ready Queue Enqueue
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Ready_queue_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ Chain_Control *ready;
+ Chain_Node *the_node;
+ Thread_Control *current;
+
+ ready = (Chain_Control *)_Scheduler.information;
+ the_node = _Chain_First( ready );
+ current = (Thread_Control *)ready;
+
+ for ( ; !_Chain_Is_tail( ready, the_node ) ; the_node = the_node->next ) {
+ current = (Thread_Control *) the_node;
+
+ /* break when AT END OR PAST our priority */
+ if ( the_thread->current_priority < current->current_priority ) {
+ current = (Thread_Control *)current->Object.Node.previous;
+ break;
+ }
+ }
+
+ /* enqueue */
+ _Chain_Insert_unprotected( (Chain_Node *)current, &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c b/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c
new file mode 100644
index 0000000000..dee0bbd116
--- /dev/null
+++ b/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c
@@ -0,0 +1,52 @@
+/*
+ * Schedule Simple Handler / Ready Queue Enqueue First
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Ready_queue_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ Chain_Control *ready;
+ Chain_Node *the_node;
+ Thread_Control *current;
+
+ ready = (Chain_Control *)_Scheduler.information;
+ current = (Thread_Control *)ready;
+
+ /*
+ * Do NOT need to check for end of chain because there is always
+ * at least one task on the ready chain -- the IDLE task. It can
+ * never block, should never attempt to obtain a semaphore or mutex,
+ * and thus will always be there.
+ */
+ for ( the_node = _Chain_First(ready) ; ; the_node = the_node->next ) {
+ current = (Thread_Control *) the_node;
+
+ /* break when AT HEAD OF (or PAST) our priority */
+ if ( the_thread->current_priority <= current->current_priority ) {
+ current = (Thread_Control *)current->Object.Node.previous;
+ break;
+ }
+ }
+
+ /* enqueue */
+ _Chain_Insert_unprotected( (Chain_Node *)current, &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimpleschedule.c b/cpukit/score/src/schedulersimpleschedule.c
new file mode 100644
index 0000000000..354e61f705
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleschedule.c
@@ -0,0 +1,34 @@
+/*
+ * Scheduler Simple Handler / Schedule
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#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/percpu.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Schedule(void)
+{
+ _Thread_Heir = (Thread_Control *) _Chain_First(
+ (Chain_Control *) _Scheduler.information
+ );
+}
diff --git a/cpukit/score/src/schedulersimpleunblock.c b/cpukit/score/src/schedulersimpleunblock.c
new file mode 100644
index 0000000000..5be5c16ad9
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleunblock.c
@@ -0,0 +1,47 @@
+/*
+ * Scheduler Simple Handler / Unblock
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/schedulersimple.h>
+#include <rtems/score/thread.h>
+
+void _Scheduler_simple_Unblock(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue(the_thread);
+
+ /*
+ * 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;
+ }
+}
diff --git a/cpukit/score/src/schedulersimpleyield.c b/cpukit/score/src/schedulersimpleyield.c
new file mode 100644
index 0000000000..61e80db7e2
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleyield.c
@@ -0,0 +1,42 @@
+/*
+ * Scheduler Simple Handler / Yield
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#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/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Yield( void )
+{
+ ISR_Level level;
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+ _ISR_Disable( level );
+
+ _Scheduler_simple_Ready_queue_Requeue(&_Scheduler, executing);
+
+ _ISR_Flash( level );
+
+ _Scheduler_simple_Schedule();
+
+ if ( !_Thread_Is_heir( executing ) )
+ _Thread_Dispatch_necessary = true;
+
+ _ISR_Enable( level );
+}