From eb02f47b126b56091ffaeaad470a48e2ac6d57b5 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 10 Nov 1999 13:48:27 +0000 Subject: Committed modifications from ITRON Task and Task Dependendent Synchronization Working Group. Included are tests. --- c/src/exec/score/include/rtems/score/Makefile.in | 5 +- c/src/exec/score/include/rtems/score/thread.h | 48 +++++++++++- c/src/exec/score/inline/rtems/score/thread.inl | 18 ----- c/src/exec/score/macros/rtems/score/thread.inl | 9 --- c/src/exec/score/src/Makefile.in | 8 +- c/src/exec/score/src/threadinitialize.c | 1 + c/src/exec/score/src/threadrestart.c | 3 +- c/src/exec/score/src/threadresume.c | 95 ++++++++++++++++++++++++ c/src/exec/score/src/threadrotatequeue.c | 93 +++++++++++++++++++++++ c/src/exec/score/src/threadsuspend.c | 83 +++++++++++++++++++++ 10 files changed, 328 insertions(+), 35 deletions(-) create mode 100644 c/src/exec/score/src/threadresume.c create mode 100644 c/src/exec/score/src/threadrotatequeue.c create mode 100644 c/src/exec/score/src/threadsuspend.c (limited to 'c/src/exec/score') diff --git a/c/src/exec/score/include/rtems/score/Makefile.in b/c/src/exec/score/include/rtems/score/Makefile.in index 7dc33b70a7..42e8a8a055 100644 --- a/c/src/exec/score/include/rtems/score/Makefile.in +++ b/c/src/exec/score/include/rtems/score/Makefile.in @@ -11,6 +11,8 @@ subdir = score/include/rtems/score RTEMS_ROOT = @RTEMS_ROOT@ PROJECT_ROOT = @PROJECT_ROOT@ +HAS_ITRON_API = @HAS_ITRON_API@ + VPATH = @srcdir@ include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg @@ -93,8 +95,7 @@ $(TARGOPTS): @if test "$(HAS_POSIX_API)" = "yes"; then \ echo "#define RTEMS_POSIX_API 1" >>$@; \ fi - echo "SHOULD BE HAS_ITRON_API not RTEMS_HAS_ITRON_API XXX " - @if test "$(RTEMS_HAS_ITRON_API)" = "yes"; then \ + @if test "$(HAS_ITRON_API)" = "yes"; then \ echo "#define RTEMS_ITRON_API 1" >>$@; \ fi @if test "$(RTEMS_USE_NEWLIB)" = "yes"; then \ diff --git a/c/src/exec/score/include/rtems/score/thread.h b/c/src/exec/score/include/rtems/score/thread.h index 26452bffbe..bfc42b6fad 100644 --- a/c/src/exec/score/include/rtems/score/thread.h +++ b/c/src/exec/score/include/rtems/score/thread.h @@ -185,6 +185,7 @@ struct Thread_Control_struct { MP_packet_Prefix *receive_packet; #endif /****************** end of common block ********************/ + unsigned32 suspend_count; boolean is_global; boolean do_post_task_switch_extension; @@ -552,6 +553,20 @@ void _Thread_Tickle_timeslice( void ); void _Thread_Yield_processor( void ); +/* + * _Thread_Rotate_Ready_Queue + * + * DESCRIPTION: + * + * This routine is invoked to rotate the ready queue for the + * given priority. It can be used to yeild the processor + * by rotating the executing threads ready queue. + */ + +void _Thread_Rotate_Ready_Queue( + Priority_Control priority +); + /* * _Thread_Load_environment * @@ -623,12 +638,43 @@ void _Thread_Set_priority( Priority_Control new_priority ); +/* + * _Thread_Suspend + * + * DESCRIPTION: + * + * This routine updates the related suspend fields in the_thread + * control block to indicate the current nested level. + */ + +void _Thread_Suspend( + Thread_Control *the_thread +); + +/* + * _Thread_Resume + * + * DESCRIPTION: + * + * This routine updates the related suspend fields in the_thread + * control block to indicate the current nested level. A force + * parameter of TRUE will force a resume and clear the suspend count. + */ + +void _Thread_Resume( + Thread_Control *the_thread, + boolean force +); + /* * _Thread_Evaluate_mode * * DESCRIPTION: * - * This routine XXX + * This routine evaluates the current scheduling information for the + * system and determines if a context switch is required. This + * is usually called after changing an execution mode such as preemptability + * for a thread. */ boolean _Thread_Evaluate_mode( void ); diff --git a/c/src/exec/score/inline/rtems/score/thread.inl b/c/src/exec/score/inline/rtems/score/thread.inl index eef4532c07..650439e8e6 100644 --- a/c/src/exec/score/inline/rtems/score/thread.inl +++ b/c/src/exec/score/inline/rtems/score/thread.inl @@ -82,24 +82,6 @@ RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing_also_the_heir( void ) return ( _Thread_Executing == _Thread_Heir ); } -/*PAGE - * - * _Thread_Resume - * - * DESCRIPTION: - * - * This routine clears the SUSPENDED state for the_thread. It performs - * any necessary scheduling operations including the selection of - * a new heir thread. - */ - -RTEMS_INLINE_ROUTINE void _Thread_Resume ( - Thread_Control *the_thread -) -{ - _Thread_Clear_state( the_thread, STATES_SUSPENDED ); -} - /*PAGE * * _Thread_Unblock diff --git a/c/src/exec/score/macros/rtems/score/thread.inl b/c/src/exec/score/macros/rtems/score/thread.inl index 96761143b8..415bb0fb8d 100644 --- a/c/src/exec/score/macros/rtems/score/thread.inl +++ b/c/src/exec/score/macros/rtems/score/thread.inl @@ -53,15 +53,6 @@ #define _Thread_Is_executing_also_the_heir() \ ( _Thread_Executing == _Thread_Heir ) -/*PAGE - * - * _Thread_Resume - * - */ - -#define _Thread_Resume( _the_thread ) \ - _Thread_Clear_state( (_the_thread), STATES_SUSPENDED ) - /*PAGE * * _Thread_Unblock diff --git a/c/src/exec/score/src/Makefile.in b/c/src/exec/score/src/Makefile.in index 28ad2ef6a3..99cce9fa76 100644 --- a/c/src/exec/score/src/Makefile.in +++ b/c/src/exec/score/src/Makefile.in @@ -42,10 +42,10 @@ OBJECT_C_PIECES = object objectallocate objectallocatebyindex \ THREAD_C_PIECES = thread threadchangepriority threadclearstate threadclose \ threadcreateidle threaddelayended threaddispatch threadevaluatemode \ threadget threadhandler threadidlebody threadinitialize threadloadenv \ - threadready threadresettimeslice threadrestart threadsetpriority \ - threadsetstate threadsettransient threadstackallocate threadstackfree \ - threadstart threadstartmultitasking threadtickletimeslice \ - threadyieldprocessor + threadready threadresettimeslice threadrestart threadresume \ + threadrotatequeue threadsetpriority threadsetstate threadsettransient \ + threadstackallocate threadstackfree threadstart threadstartmultitasking \ + threadsuspend threadtickletimeslice threadyieldprocessor THREADQ_C_PIECES= threadq threadqdequeue threadqdequeuefifo \ threadqdequeuepriority threadqenqueue threadqenqueuefifo \ diff --git a/c/src/exec/score/src/threadinitialize.c b/c/src/exec/score/src/threadinitialize.c index 28cfa324bc..f294d865bf 100644 --- a/c/src/exec/score/src/threadinitialize.c +++ b/c/src/exec/score/src/threadinitialize.c @@ -153,6 +153,7 @@ boolean _Thread_Initialize( the_thread->current_state = STATES_DORMANT; the_thread->resource_count = 0; + the_thread->suspend_count = 0; the_thread->real_priority = priority; the_thread->Start.initial_priority = priority; the_thread->ticks_executed = 0; diff --git a/c/src/exec/score/src/threadrestart.c b/c/src/exec/score/src/threadrestart.c index 7419514a4f..229dbe2d94 100644 --- a/c/src/exec/score/src/threadrestart.c +++ b/c/src/exec/score/src/threadrestart.c @@ -44,7 +44,8 @@ boolean _Thread_Restart( if ( !_States_Is_dormant( the_thread->current_state ) ) { _Thread_Set_transient( the_thread ); - the_thread->resource_count = 0; + the_thread->resource_count = 0; + the_thread->suspend_count = 0; the_thread->is_preemptible = the_thread->Start.is_preemptible; the_thread->budget_algorithm = the_thread->Start.budget_algorithm; the_thread->budget_callout = the_thread->Start.budget_callout; diff --git a/c/src/exec/score/src/threadresume.c b/c/src/exec/score/src/threadresume.c new file mode 100644 index 0000000000..067dc59610 --- /dev/null +++ b/c/src/exec/score/src/threadresume.c @@ -0,0 +1,95 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Resume + * + * This kernel routine clears the SUSPEND state if the suspend_count + * drops below one. If the force parameter is set the suspend_count + * is forced back to zero. The thread ready chain is adjusted if + * necessary and the Heir thread is set accordingly. + * + * Input parameters: + * the_thread - pointer to thread control block + * force - force the suspend count back to 0 + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * priority map + * select heir + */ + + +void _Thread_Resume( + Thread_Control *the_thread, + boolean force +) +{ + + ISR_Level level; + States_Control current_state; + + _ISR_Disable( level ); + + if ( force == TRUE ) + the_thread->suspend_count = 0; + else + the_thread->suspend_count--; + + if ( the_thread->suspend_count > 0 ) { + _ISR_Enable( level ); + return; + } + + current_state = the_thread->current_state; + if ( current_state & STATES_SUSPENDED ) { + current_state = + the_thread->current_state = _States_Clear(STATES_SUSPENDED, current_state); + + if ( _States_Is_ready( current_state ) ) { + + _Priority_Add_to_bit_map( &the_thread->Priority_map ); + + _Chain_Append_unprotected(the_thread->ready, &the_thread->Object.Node); + + _ISR_Flash( level ); + + if ( the_thread->current_priority < _Thread_Heir->current_priority ) { + _Thread_Heir = the_thread; + if ( _Thread_Executing->is_preemptible || + the_thread->current_priority == 0 ) + _Context_Switch_necessary = TRUE; + } + } + } + + _ISR_Enable( level ); +} diff --git a/c/src/exec/score/src/threadrotatequeue.c b/c/src/exec/score/src/threadrotatequeue.c new file mode 100644 index 0000000000..f7ee9c12f5 --- /dev/null +++ b/c/src/exec/score/src/threadrotatequeue.c @@ -0,0 +1,93 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Rotate_Ready_Queue + * + * This kernel routine will rotate the ready queue. + * remove the running THREAD from the ready chain + * and place it immediatly at the rear of this chain. Reset timeslice + * and yield the processor functions both use this routine, therefore if + * reset is TRUE and this is the only thread on the chain then the + * timeslice counter is reset. The heir THREAD will be updated if the + * running is also the currently the heir. + * + * Input parameters: + * Priority of the queue we wish to modify. + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Rotate_Ready_Queue( + Priority_Control priority +) +{ + ISR_Level level; + Thread_Control *executing; + Chain_Control *ready; + Chain_Node *node; + + ready = &_Thread_Ready_chain[ priority ]; + executing = _Thread_Executing; + + if ( ready == executing->ready ) { + _Thread_Yield_processor(); + return; + } + + _ISR_Disable( level ); + + if ( !_Chain_Is_empty( ready ) ) { + if (!_Chain_Has_only_one_node( ready ) ) { + node = _Chain_Get_first_unprotected( ready ); + _Chain_Append_unprotected( ready, node ); + } + } + + _ISR_Flash( level ); + + if ( _Thread_Heir->ready == ready ) + _Thread_Heir = (Thread_Control *) ready->first; + + if ( executing != _Thread_Heir ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + + + + + + diff --git a/c/src/exec/score/src/threadsuspend.c b/c/src/exec/score/src/threadsuspend.c new file mode 100644 index 0000000000..82363054e5 --- /dev/null +++ b/c/src/exec/score/src/threadsuspend.c @@ -0,0 +1,83 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Suspend + * + * This kernel routine sets the SUSPEND state in the THREAD. The + * THREAD chain and suspend count are adjusted if necessary. + * + * Input parameters: + * the_thread - pointer to thread control block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select map + */ + +void _Thread_Suspend( + Thread_Control *the_thread +) +{ + ISR_Level level; + Chain_Control *ready; + + ready = the_thread->ready; + _ISR_Disable( level ); + the_thread->suspend_count++; + if ( !_States_Is_ready( the_thread->current_state ) ) { + the_thread->current_state = + _States_Set( STATES_SUSPENDED, the_thread->current_state ); + _ISR_Enable( level ); + return; + } + + the_thread->current_state = STATES_SUSPENDED; + + if ( _Chain_Has_only_one_node( ready ) ) { + + _Chain_Initialize_empty( ready ); + _Priority_Remove_from_bit_map( &the_thread->Priority_map ); + + } else + _Chain_Extract_unprotected( &the_thread->Object.Node ); + + _ISR_Flash( level ); + + if ( _Thread_Is_heir( the_thread ) ) + _Thread_Calculate_heir(); + + if ( _Thread_Is_executing( the_thread ) ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} -- cgit v1.2.3