From 0118ed65ea96db1032771620fc5fb1c1290f9d47 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 16 Mar 2011 16:32:22 +0000 Subject: 2011-03-16 Jennifer Averett 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. --- cpukit/ChangeLog | 19 ++ cpukit/sapi/include/confdefs.h | 20 ++- cpukit/score/Makefile.am | 14 ++ cpukit/score/include/rtems/score/schedulersimple.h | 199 +++++++++++++++++++++ .../score/inline/rtems/score/schedulersimple.inl | 53 ++++++ cpukit/score/preinstall.am | 8 + cpukit/score/src/schedulersimple.c | 84 +++++++++ cpukit/score/src/schedulersimpleblock.c | 39 ++++ cpukit/score/src/schedulersimpleenqueue.c | 29 +++ cpukit/score/src/schedulersimpleenqueuefirst.c | 28 +++ cpukit/score/src/schedulersimpleextract.c | 28 +++ .../score/src/schedulersimplereadyqueueenqueue.c | 48 +++++ .../src/schedulersimplereadyqueueenqueuefirst.c | 52 ++++++ cpukit/score/src/schedulersimpleschedule.c | 34 ++++ cpukit/score/src/schedulersimpleunblock.c | 47 +++++ cpukit/score/src/schedulersimpleyield.c | 42 +++++ 16 files changed, 743 insertions(+), 1 deletion(-) create mode 100644 cpukit/score/include/rtems/score/schedulersimple.h create mode 100644 cpukit/score/inline/rtems/score/schedulersimple.inl create mode 100644 cpukit/score/src/schedulersimple.c create mode 100644 cpukit/score/src/schedulersimpleblock.c create mode 100644 cpukit/score/src/schedulersimpleenqueue.c create mode 100644 cpukit/score/src/schedulersimpleenqueuefirst.c create mode 100644 cpukit/score/src/schedulersimpleextract.c create mode 100644 cpukit/score/src/schedulersimplereadyqueueenqueue.c create mode 100644 cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c create mode 100644 cpukit/score/src/schedulersimpleschedule.c create mode 100644 cpukit/score/src/schedulersimpleunblock.c create mode 100644 cpukit/score/src/schedulersimpleyield.c diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 5cc1e2a092..df9b122955 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,22 @@ +2011-03-16 Jennifer Averett + + 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. + 2011-03-16 Joel Sherrill * score/src/threadyieldprocessor.c: Removed. File is no longer diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index f7ce50ec76..d194fed1bc 100644 --- a/cpukit/sapi/include/confdefs.h +++ b/cpukit/sapi/include/confdefs.h @@ -556,6 +556,7 @@ rtems_fs_init_functions_t rtems_fs_init_helper = * scheduling policy to use. The supported configurations are: * CONFIGURE_SCHEDULER_USER - user provided scheduler * CONFIGURE_SCHEDULER_PRIORITY - Deterministic Priority Scheduler + * CONFIGURE_SCHEDULER_SIMPLE - Light-weight Priority Scheduler * * If no configuration is specified by the application, then * CONFIGURE_SCHEDULER_PRIORITY is assumed to be the default. @@ -575,7 +576,8 @@ rtems_fs_init_functions_t rtems_fs_init_helper = /* If no scheduler is specified, the priority scheduler is default. */ #if !defined(CONFIGURE_SCHEDULER_USER) && \ - !defined(CONFIGURE_SCHEDULER_PRIORITY) + !defined(CONFIGURE_SCHEDULER_PRIORITY) && \ + !defined(CONFIGURE_SCHEDULER_SIMPLE) #define CONFIGURE_SCHEDULER_PRIORITY #endif @@ -597,6 +599,22 @@ rtems_fs_init_functions_t rtems_fs_init_helper = _Configure_From_workspace(sizeof(Scheduler_priority_Per_thread)) ) #endif +/* + * If the Simple Priority Scheduler is selected, then configure for it. + */ +#if defined(CONFIGURE_SCHEDULER_SIMPLE) + #include + #define SCHEDULER_ENTRY_POINTS SCHEDULER_SIMPLE_ENTRY_POINTS + + /** + * define the memory used by the simple scheduler + */ + #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \ + _Configure_From_workspace( sizeof(Chain_Control) ) \ + ) + #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (0) +#endif + /* * Set up the scheduler entry points table. The scheduling code uses * this code to know which scheduler is configured by the user. diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 8476bb42f1..bdd8e510d9 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -27,6 +27,7 @@ include_rtems_score_HEADERS = include/rtems/score/address.h \ include/rtems/score/object.h include/rtems/score/percpu.h \ include/rtems/score/priority.h include/rtems/score/prioritybitmap.h \ include/rtems/score/scheduler.h include/rtems/score/schedulerpriority.h \ + include/rtems/score/schedulersimple.h \ include/rtems/score/stack.h include/rtems/score/states.h \ include/rtems/score/sysstate.h include/rtems/score/thread.h \ include/rtems/score/threadq.h include/rtems/score/threadsync.h \ @@ -56,6 +57,7 @@ include_rtems_score_HEADERS += inline/rtems/score/address.inl \ inline/rtems/score/isr.inl inline/rtems/score/object.inl \ inline/rtems/score/priority.inl inline/rtems/score/prioritybitmap.inl \ inline/rtems/score/scheduler.inl inline/rtems/score/schedulerpriority.inl \ + inline/rtems/score/schedulersimple.inl \ inline/rtems/score/stack.inl inline/rtems/score/states.inl \ inline/rtems/score/sysstate.inl inline/rtems/score/thread.inl \ inline/rtems/score/threadq.inl inline/rtems/score/tod.inl \ @@ -155,6 +157,18 @@ libscore_a_SOURCES += src/schedulerpriority.c \ src/schedulerpriorityupdate.c \ src/schedulerpriorityyield.c +## SCHEDULERSIMPLE_C_FILES +libscore_a_SOURCES += src/schedulersimple.c \ + src/schedulersimpleblock.c \ + src/schedulersimpleenqueue.c \ + src/schedulersimpleenqueuefirst.c \ + src/schedulersimpleextract.c \ + src/schedulersimplereadyqueueenqueue.c \ + src/schedulersimplereadyqueueenqueuefirst.c \ + src/schedulersimpleschedule.c \ + src/schedulersimpleunblock.c \ + src/schedulersimpleyield.c + ## PROTECTED_HEAP_C_FILES libscore_a_SOURCES += src/pheapallocate.c \ src/pheapextend.c src/pheapfree.c src/pheapgetsize.c \ diff --git a/cpukit/score/include/rtems/score/schedulersimple.h b/cpukit/score/include/rtems/score/schedulersimple.h new file mode 100644 index 0000000000..ea060ea59c --- /dev/null +++ b/cpukit/score/include/rtems/score/schedulersimple.h @@ -0,0 +1,199 @@ +/** + * @file rtems/score/schedulersimple.h + * + * This include file contains all the constants and structures associated + * with the manipulation of threads on a simple-priority-based ready queue. + * + * + * 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$ + */ + +#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_H +#define _RTEMS_SCORE_SCHEDULERSIMPLE_H + +/** + * @addtogroup ScoreScheduler + * + */ +/**@{*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * Entry points for Scheduler Simple + */ +#define SCHEDULER_SIMPLE_ENTRY_POINTS \ + { \ + _Scheduler_simple_Initialize, /* initialize entry point */ \ + _Scheduler_simple_Schedule, /* schedule entry point */ \ + _Scheduler_simple_Yield, /* yield entry point */ \ + _Scheduler_simple_Block, /* block entry point */ \ + _Scheduler_simple_Unblock, /* unblock entry point */ \ + _Scheduler_simple_Allocate, /* allocate entry point */ \ + _Scheduler_simple_Free, /* free entry point */ \ + _Scheduler_simple_Update, /* update entry point */ \ + _Scheduler_simple_Enqueue, /* enqueue entry point */ \ + _Scheduler_simple_Enqueue_first, /* enqueue_first entry point */ \ + _Scheduler_simple_Extract /* extract entry point */ \ + } + +/** + * This routine initializes the simple scheduler. + */ +void _Scheduler_simple_Initialize( void ); + +/** + * This routine sets the heir thread to be the next ready thread + * on the ready queue by getting the first node in the scheduler + * information. + */ +void _Scheduler_simple_Schedule( void ); + +/** + * This routine is invoked when a thread wishes to voluntarily + * transfer control of the processor to another thread in the queue. + * It will remove the running THREAD from the scheduler.informaiton + * (where the ready queue is stored) and place it immediately at the + * between the last entry of its priority and the next priority thread. + * Reset timeslice and yield the processor functions both use this routine, + * therefore if reset is true and this is the only thread on the queue then + * the timeslice counter is reset. The heir THREAD will be updated if the + * running is also the currently the heir. +*/ +void _Scheduler_simple_Yield( void ); + +/** + * 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. + * + * @param[in] the_thread is the thread that is to be blocked + */ +void _Scheduler_simple_Block( + 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. + * + * @param[in] the_thread is the thread that is to be unblocked + */ +void _Scheduler_simple_Unblock( + Thread_Control *the_thread +); + +/** + * This routine removes a specific thread from the specified + * simple-based ready queue. + * + * @param[in] the_thread is the thread to be blocked + */ +void _Scheduler_simple_Extract( + Thread_Control *the_thread +); + +/** + * This routine puts @a the_thread on to the ready queue. + * + * @param[in] the_thread is the thread to be blocked + */ +void _Scheduler_simple_Enqueue( + Thread_Control *the_thread +); + +/** + * This routine puts @a the_thread to the head of the ready queue. + * The thread will be the first thread at its priority level. + * + * @param[in] the_thread is the thread to be blocked + */ +void _Scheduler_simple_Enqueue_first( + Thread_Control *the_thread +); + +/** + * This routine is a place holder for any memeory allocation needed + * by the scheduler. For the simple scheduler the routine is an empty + * place holder. + * + * @param[in] the_thread is the thread the scheduler is allocating + * management memory for + * + * @return this routine returns -1 since this is just an empty placeholder + * and the return value may be defined differently by each scheduler. + */ +void *_Scheduler_simple_Allocate( + Thread_Control *the_thread +); + +/** + * This routine does nothing, and is used as a stub for Schedule update + * + * The overhead of a function call will still be imposed. + * + * @param[in] the_thread is the thread to be blocked + */ +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. + * + * @param[in] the_thread is the thread to be blocked + */ +void _Scheduler_simple_Free( + Thread_Control *the_thread +); + +/** + * _Scheduler_simple_Ready_queue_Enqueue + * + * This routine puts @a the_thread on the ready queue + * at the end of its priority group. + * + * @param[in] the_thread - pointer to a thread control block + */ +void _Scheduler_simple_Ready_queue_Enqueue( + Thread_Control *the_thread +); + +/** + * _Scheduler_simple_Ready_queue_Enqueue_first + * + * This routine puts @a the_thread on to the ready queue + * at the beginning of its priority group. + * + * @param[in] the_thread - pointer to a thread control block + */ +void _Scheduler_simple_Ready_queue_Enqueue_first( + Thread_Control *the_thread +); + +#ifndef __RTEMS_APPLICATION__ +#include +#endif + +#ifdef __cplusplus +} +#endif + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/schedulersimple.inl b/cpukit/score/inline/rtems/score/schedulersimple.inl new file mode 100644 index 0000000000..0996efc896 --- /dev/null +++ b/cpukit/score/inline/rtems/score/schedulersimple.inl @@ -0,0 +1,53 @@ +/** + * @file rtems/score/schedulersimple.inl + * + * This inline file contains all of the inlined routines associated with + * the manipulation of the priority-based scheduling structures. + */ + +/* + * 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$ + */ + +#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_H +# error "Never use directly; include instead." +#endif + +#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_INL +#define _RTEMS_SCORE_SCHEDULERSIMPLE_INL + +#include + +/** + * @addtogroup ScoreScheduler + * @{ + */ + +/** + * This routine puts @a the_thread on to the ready queue. + * + * @param[in] the_ready_queue is a pointer to the ready queue head + * @param[in] the_thread is the thread to be blocked + */ +RTEMS_INLINE_ROUTINE void _Scheduler_simple_Ready_queue_Requeue( + Scheduler_Control *the_ready_queue, + Thread_Control *the_thread +) +{ + /* extract */ + _Chain_Extract_unprotected( &the_thread->Object.Node ); + + /* enqueue */ + _Scheduler_simple_Ready_queue_Enqueue( the_thread ); +} + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am index 65f28c4a85..e188eb7fe1 100644 --- a/cpukit/score/preinstall.am +++ b/cpukit/score/preinstall.am @@ -119,6 +119,10 @@ $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h: include/rtems/score/schedule $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h +$(PROJECT_INCLUDE)/rtems/score/schedulersimple.h: include/rtems/score/schedulersimple.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h + $(PROJECT_INCLUDE)/rtems/score/stack.h: include/rtems/score/stack.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/stack.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/stack.h @@ -261,6 +265,10 @@ $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl: inline/rtems/score/schedul $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl +$(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl: inline/rtems/score/schedulersimple.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl + $(PROJECT_INCLUDE)/rtems/score/stack.inl: inline/rtems/score/stack.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/stack.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/stack.inl 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 +#include +#include +#include +#include +#include +#include + +/** + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include + +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 +#include +#include +#include + +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 +#include +#include +#include + +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 +#include +#include +#include +#include + +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 +#include +#include +#include + +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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 +#include +#include +#include + +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 +#include +#include +#include +#include + +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 ); +} -- cgit v1.2.3