summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-11-24 15:51:28 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-11-24 15:51:28 +0000
commit0faa9dad0768f0291cb44d8d0dcb74fd3f362cc2 (patch)
tree5fdf3fb63a7b901897891cf25b3958c9a750ed69 /cpukit/score/include
parentRemove duplicate entry. (diff)
downloadrtems-0faa9dad0768f0291cb44d8d0dcb74fd3f362cc2.tar.bz2
2010-11-24 Gedare Bloom <giddyup44@yahoo.com>
PR 1647/cpukit * posix/src/nanosleep.c, posix/src/sched_yield.c, rtems/src/taskwakeafter.c, sapi/include/confdefs.h, sapi/include/rtems/config.h, sapi/src/exinit.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/prioritybitmap.h, score/include/rtems/score/thread.h, score/inline/rtems/score/thread.inl, score/src/thread.c, score/src/threadchangepriority.c, score/src/threadclearstate.c, score/src/threadclose.c, score/src/threadinitialize.c, score/src/threadready.c, score/src/threadresume.c, score/src/threadsetpriority.c, score/src/threadsetstate.c, score/src/threadsettransient.c, score/src/threadsuspend.c, score/src/threadtickletimeslice.c: Refactor scheduler out of thread handler to facilitate alternate scheduler implementations. * score/src/threadyieldprocessor.c: Removed. * score/src/schedulerprioritythreadschedulerupdate.c, score/src/schedulerprioritythreadschedulerfree.c, score/src/schedulerpriorityblock.c, score/src/scheduler.c, score/src/schedulerprioritythreadschedulerallocate.c, score/src/schedulerpriorityunblock.c, score/src/schedulerpriority.c, score/src/schedulerpriorityyield.c, score/include/rtems/score/schedulerpriority.h, score/include/rtems/score/scheduler.h, score/inline/rtems/score/scheduler.inl, score/inline/rtems/score/schedulerpriority.inl: New files.
Diffstat (limited to 'cpukit/score/include')
-rw-r--r--cpukit/score/include/rtems/score/prioritybitmap.h11
-rw-r--r--cpukit/score/include/rtems/score/scheduler.h156
-rw-r--r--cpukit/score/include/rtems/score/schedulerpriority.h117
-rw-r--r--cpukit/score/include/rtems/score/thread.h23
4 files changed, 283 insertions, 24 deletions
diff --git a/cpukit/score/include/rtems/score/prioritybitmap.h b/cpukit/score/include/rtems/score/prioritybitmap.h
index cd712952b2..bba5b428b6 100644
--- a/cpukit/score/include/rtems/score/prioritybitmap.h
+++ b/cpukit/score/include/rtems/score/prioritybitmap.h
@@ -37,18 +37,17 @@ extern "C" {
#include <rtems/score/priority.h>
+
/*
- * TODO:
- * These should only be instantiated if using the bit map handler. The
- * logical place for this is in confdefs.h when a scheduler that uses the
- * bit map handler is configured.
+ * The Priority_bit_map_Control variables are instantiated only
+ * if using the bit map handler.
*/
/**
* Each sixteen bit entry in this array is associated with one of
* the sixteen entries in the Priority Bit map.
*/
-SCORE_EXTERN volatile Priority_bit_map_Control _Priority_Major_bit_map;
+extern volatile Priority_bit_map_Control _Priority_Major_bit_map;
/** Each bit in the Priority Bitmap indicates whether or not there are
* threads ready at a particular priority. The mapping of
@@ -56,7 +55,7 @@ SCORE_EXTERN volatile Priority_bit_map_Control _Priority_Major_bit_map;
* dependent as is the value of each bit used to indicate that
* threads are ready at that priority.
*/
-SCORE_EXTERN Priority_bit_map_Control
+extern Priority_bit_map_Control
_Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
/*
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
new file mode 100644
index 0000000000..b0ac20917c
--- /dev/null
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -0,0 +1,156 @@
+/**
+ * @file rtems/score/scheduler.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the scheduler.
+ */
+
+/*
+ * Copyright (C) 2010 Gedare Bloom.
+ *
+ * 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$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULER_H
+#define _RTEMS_SCORE_SCHEDULER_H
+
+/**
+ * @defgroup ScoreScheduler Scheduler Handler
+ *
+ * This handler encapsulates functionality related to managing sets of threads
+ * that are ready for execution.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/percpu.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/prioritybitmap.h>
+
+/*
+ * These defines are used to set the scheduler_policy value. The values
+ * must correspond directly with the order of the fields in the scheduler
+ * table (Scheduler_Table_t), because the Configuration.scheduler_policy
+ * field is used to index the scheduler table.
+ */
+#define _Scheduler_USER (0)
+#define _Scheduler_PRIORITY (1)
+
+typedef struct Scheduler_Control_struct Scheduler_Control;
+
+/*
+ * The Scheduler_Table_t type defines the scheduler initialization table,
+ * which is set up by confdefs.h based on the user's choice of scheduler
+ * policy.
+ */
+typedef struct {
+ void ( *scheduler_init )( Scheduler_Control * );
+} Scheduler_Table_t;
+
+/* instantiated and initialized in confdefs.h */
+extern const Scheduler_Table_t _Scheduler_Table[];
+
+/**
+ * The following Scheduler_Per_thread_xxx structures are used to
+ * hold per-thread data used by the scheduler. Thread_Control->scheduler is a
+ * union of pointers, one for each of the following structures. The
+ * scheduler->xxx field points to an instantion of one of these structures,
+ * which is allocated from the workspace during _Thread_Start.
+ */
+
+/**
+ * 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;
+
+/**
+ * function jump table that holds pointers to the functions that
+ * implement specific schedulers.
+ */
+typedef struct {
+ /** Implements the scheduling decision logic (policy). */
+ void ( *schedule ) ( Scheduler_Control * );
+
+ /** Voluntarily yields the processor per the scheduling policy. */
+ void ( *yield ) ( Scheduler_Control * );
+
+ /** Removes the given thread from scheduling decisions. */
+ void ( *block ) ( Scheduler_Control *, Thread_Control * );
+
+ /** Adds the given thread to scheduling decisions. */
+ void ( *unblock ) ( Scheduler_Control *, Thread_Control * );
+
+ /** allocates the scheduler field of the given thread */
+ void * ( *scheduler_allocate ) ( Scheduler_Control *, Thread_Control * );
+
+ /** frees the scheduler field of the given thread */
+ void ( *scheduler_free ) ( Scheduler_Control *, Thread_Control * );
+
+ /** updates the scheduler field of the given thread -- primarily used
+ * when changing the thread's priority. */
+ void ( *scheduler_update ) ( Scheduler_Control *, Thread_Control * );
+} Scheduler_Operations;
+
+/**
+ * This is the structure used to manage the scheduler.
+ */
+struct Scheduler_Control_struct {
+ /**
+ * This union contains the pointer to the data structure used to manage
+ * the ready set of tasks. The pointer varies based upon the type of
+ * ready queue required by the scheduler.
+ */
+ union {
+ /**
+ * This is the set of lists (an array of Chain_Control) for
+ * priority scheduling.
+ */
+ Chain_Control *Priority;
+
+ } ready_queues;
+
+ /** The jump table for scheduler-specific functions */
+ Scheduler_Operations operations;
+};
+
+/**
+ * The _Scheduler holds the structures used to manage the
+ * scheduler.
+ *
+ * @note Can we make this per-cpu? then _Scheduler will be a macro.
+ */
+SCORE_EXTERN Scheduler_Control _Scheduler;
+
+/**
+ * This routine initializes the scheduler to the policy chosen by the user
+ * through confdefs, or to the priority scheduler with ready chains by
+ * default.
+ */
+void _Scheduler_Handler_initialization( void );
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/scheduler.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
new file mode 100644
index 0000000000..54c999f058
--- /dev/null
+++ b/cpukit/score/include/rtems/score/schedulerpriority.h
@@ -0,0 +1,117 @@
+/**
+ * @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.
+ *
+ * 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$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULERPRIORITY_H
+#define _RTEMS_SCORE_SCHEDULERPRIORITY_H
+
+/**
+ * @addtogroup ScoreScheduler
+ *
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/chain.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/percpu.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/wkspace.h>
+
+/**
+ * This routine initializes the priority scheduler.
+ */
+void _Scheduler_priority_Initialize(
+ Scheduler_Control *the_scheduler
+);
+
+/**
+ * This routine removes @a the_thread from the scheduling decision,
+ * that is, removes it from the ready queue. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+void _Scheduler_priority_Block(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+);
+
+/**
+ * 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(
+ Scheduler_Control *the_scheduler
+);
+
+/**
+ * This routine allocates @a the_thread->scheduler.
+ */
+void * _Scheduler_priority_Thread_scheduler_allocate(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine frees @a the_thread->scheduler.
+ */
+void _Scheduler_priority_Thread_scheduler_free(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine updates @a the_thread->scheduler based on @a the_scheduler
+ * structures and thread state
+ */
+void _Scheduler_priority_Thread_scheduler_update(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine adds @a the_thread to the scheduling decision,
+ * that is, adds it to the ready queue and
+ * updates any appropriate scheduling variables, for example the heir thread.
+ */
+void _Scheduler_priority_Unblock(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine is invoked when a thread wishes to voluntarily
+ * transfer control of the processor to another thread in the queue.
+ */
+void _Scheduler_priority_Yield(
+ Scheduler_Control *the_scheduler
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/schedulerpriority.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 9565458bb8..370d5491a3 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -70,7 +70,7 @@ extern "C" {
#endif
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
-#include <rtems/score/prioritybitmap.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/stack.h>
#include <rtems/score/states.h>
#include <rtems/score/tod.h>
@@ -390,10 +390,10 @@ struct Thread_Control_struct {
* since it was created.
*/
Thread_CPU_usage_t cpu_time_used;
- /** This field points to the Ready FIFO for this priority. */
- Chain_Control *ready;
- /** This field contains precalculated priority map indices. */
- Priority_bit_map_Information Priority_map;
+ /** This union holds per-thread data for the scheduler and ready queue. */
+ union {
+ Scheduler_priority_Per_thread *priority;
+ } scheduler;
/** This field contains information about the starting state of
* this thread.
*/
@@ -456,12 +456,6 @@ SCORE_EXTERN uint32_t _Thread_Maximum_extensions;
SCORE_EXTERN uint32_t _Thread_Ticks_per_timeslice;
/**
- * The following points to the array of FIFOs used to manage the
- * set of ready threads.
- */
-SCORE_EXTERN Chain_Control *_Thread_Ready_chain;
-
-/**
* The following points to the thread whose floating point
* context is currently loaded.
*/
@@ -654,13 +648,6 @@ void _Thread_Set_transient(
void _Thread_Tickle_timeslice( void );
/**
- * This routine is invoked when a thread wishes to voluntarily
- * transfer control of the processor to another thread of equal
- * or greater priority.
- */
-void _Thread_Yield_processor( void );
-
-/**
* This routine initializes the context of the_thread to its
* appropriate starting state.
*/