summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
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/src
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/src')
-rw-r--r--cpukit/score/src/scheduler.c45
-rw-r--r--cpukit/score/src/schedulerpriority.c66
-rw-r--r--cpukit/score/src/schedulerpriorityblock.c48
-rw-r--r--cpukit/score/src/schedulerpriorityschedule.c48
-rw-r--r--cpukit/score/src/schedulerprioritythreadschedulerallocate.c53
-rw-r--r--cpukit/score/src/schedulerprioritythreadschedulerfree.c46
-rw-r--r--cpukit/score/src/schedulerprioritythreadschedulerupdate.c55
-rw-r--r--cpukit/score/src/schedulerpriorityunblock.c57
-rw-r--r--cpukit/score/src/schedulerpriorityyield.c77
-rw-r--r--cpukit/score/src/thread.c9
-rw-r--r--cpukit/score/src/threadchangepriority.c12
-rw-r--r--cpukit/score/src/threadclearstate.c27
-rw-r--r--cpukit/score/src/threadclose.c6
-rw-r--r--cpukit/score/src/threadinitialize.c8
-rw-r--r--cpukit/score/src/threadready.c15
-rw-r--r--cpukit/score/src/threadresume.c15
-rw-r--r--cpukit/score/src/threadsetpriority.c7
-rw-r--r--cpukit/score/src/threadsetstate.c21
-rw-r--r--cpukit/score/src/threadsettransient.c15
-rw-r--r--cpukit/score/src/threadsuspend.c21
-rw-r--r--cpukit/score/src/threadtickletimeslice.c3
21 files changed, 539 insertions, 115 deletions
diff --git a/cpukit/score/src/scheduler.c b/cpukit/score/src/scheduler.c
new file mode 100644
index 0000000000..9d7424eef6
--- /dev/null
+++ b/cpukit/score/src/scheduler.c
@@ -0,0 +1,45 @@
+/*
+ * Scheduler Handler
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+
+/*
+ * _Scheduler_Handler_initialization
+ *
+ * This routine initializes the scheduler by calling the scheduler_init
+ * function registered in the Configuration Scheduler Table.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Scheduler_Handler_initialization( )
+{
+ Scheduler_Control *the_scheduler = &_Scheduler;
+
+ (*(_Scheduler_Table[Configuration.scheduler_policy].scheduler_init))(
+ the_scheduler
+ );
+}
diff --git a/cpukit/score/src/schedulerpriority.c b/cpukit/score/src/schedulerpriority.c
new file mode 100644
index 0000000000..5e7ad61d9a
--- /dev/null
+++ b/cpukit/score/src/schedulerpriority.c
@@ -0,0 +1,66 @@
+/*
+ * Scheduler Handler
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.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;
+
+/*
+ * _Scheduler_priority_Initialize
+ *
+ * Initializes the scheduler for priority scheduling.
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ *
+ * Output parameters: NONE
+ */
+
+void _Scheduler_priority_Initialize (
+ Scheduler_Control *the_scheduler
+)
+{
+ /* the operations table is a jump table to redirect generic scheduler
+ * function calls to scheduler implementation specific functions. The
+ * main purpose of scheduler initialization is to set up the jump table
+ * for the scheduler. Every scheduler implementation provides its own
+ * scheduler operations table.
+ */
+ the_scheduler->operations.schedule = &_Scheduler_priority_Schedule;
+ the_scheduler->operations.yield = &_Scheduler_priority_Yield;
+ the_scheduler->operations.block = &_Scheduler_priority_Block;
+ the_scheduler->operations.unblock = &_Scheduler_priority_Unblock;
+ the_scheduler->operations.scheduler_allocate =
+ &_Scheduler_priority_Thread_scheduler_allocate;
+ the_scheduler->operations.scheduler_free =
+ &_Scheduler_priority_Thread_scheduler_free;
+ the_scheduler->operations.scheduler_update =
+ &_Scheduler_priority_Thread_scheduler_update;
+
+ _Scheduler_priority_Ready_queue_initialize( the_scheduler );
+ _Priority_bit_map_Handler_initialization( );
+}
diff --git a/cpukit/score/src/schedulerpriorityblock.c b/cpukit/score/src/schedulerpriorityblock.c
new file mode 100644
index 0000000000..cc137e64f5
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityblock.c
@@ -0,0 +1,48 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ *
+ * 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/schedulerpriority.h>
+#include <rtems/score/thread.h>
+
+/*
+ * _Scheduler_priority_Block
+ *
+ * This kernel routine removes the_thread from scheduling decisions based
+ * on simple queue extraction.
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ */
+
+void _Scheduler_priority_Block(
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Block_body(the_scheduler, the_thread);
+}
diff --git a/cpukit/score/src/schedulerpriorityschedule.c b/cpukit/score/src/schedulerpriorityschedule.c
new file mode 100644
index 0000000000..10c46652ef
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityschedule.c
@@ -0,0 +1,48 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ *
+ * 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/schedulerpriority.h>
+#include <rtems/score/thread.h>
+
+/*
+ * _Scheduler_priority_Schedule
+ *
+ * This kernel routine implements scheduling decision logic for priority-based
+ * scheduling.
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ */
+
+void _Scheduler_priority_Schedule(
+ Scheduler_Control *the_scheduler
+)
+{
+ _Scheduler_priority_Schedule_body( the_scheduler );
+}
diff --git a/cpukit/score/src/schedulerprioritythreadschedulerallocate.c b/cpukit/score/src/schedulerprioritythreadschedulerallocate.c
new file mode 100644
index 0000000000..21595ff778
--- /dev/null
+++ b/cpukit/score/src/schedulerprioritythreadschedulerallocate.c
@@ -0,0 +1,53 @@
+/*
+ * Scheduler Handler
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Scheduler_priority_Thread_scheduler_allocate
+ *
+ * Allocates @a the_thread->scheduler
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters:
+ * Returns pointer to allocated space.
+ */
+
+void* _Scheduler_priority_Thread_scheduler_allocate (
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+)
+{
+ void *sched;
+
+ sched = _Workspace_Allocate( sizeof(Scheduler_priority_Per_thread) );
+
+ the_thread->scheduler.priority = (Scheduler_priority_Per_thread*) sched;
+
+ return sched;
+}
diff --git a/cpukit/score/src/schedulerprioritythreadschedulerfree.c b/cpukit/score/src/schedulerprioritythreadschedulerfree.c
new file mode 100644
index 0000000000..78226b5fb3
--- /dev/null
+++ b/cpukit/score/src/schedulerprioritythreadschedulerfree.c
@@ -0,0 +1,46 @@
+/*
+ * Scheduler Handler
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Scheduler_priority_Thread_scheduler_free
+ *
+ * Frees @a the_thread->scheduler
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters: NONE
+ */
+
+void _Scheduler_priority_Thread_scheduler_free (
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+)
+{
+ _Workspace_Free( the_thread->scheduler.priority );
+}
diff --git a/cpukit/score/src/schedulerprioritythreadschedulerupdate.c b/cpukit/score/src/schedulerprioritythreadschedulerupdate.c
new file mode 100644
index 0000000000..c4c7e815ce
--- /dev/null
+++ b/cpukit/score/src/schedulerprioritythreadschedulerupdate.c
@@ -0,0 +1,55 @@
+/*
+ * Scheduler Handler
+ *
+ * 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$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/prioritybitmap.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+
+/*
+ * _Scheduler_priority_Thread_scheduler_update
+ *
+ * Updates @a the_thread->scheduler
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters: NONE
+ */
+
+void _Scheduler_priority_Thread_scheduler_update (
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+)
+{
+ Chain_Control *rq = the_scheduler->ready_queues.Priority;
+ the_thread->scheduler.priority->ready_chain = &rq[
+ the_thread->current_priority
+ ];
+
+ _Priority_bit_map_Initialize_information(
+ &the_thread->scheduler.priority->Priority_map,
+ the_thread->current_priority
+ );
+}
diff --git a/cpukit/score/src/schedulerpriorityunblock.c b/cpukit/score/src/schedulerpriorityunblock.c
new file mode 100644
index 0000000000..9030c0a137
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityunblock.c
@@ -0,0 +1,57 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ *
+ * 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/apiext.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/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Scheduler_priority_Unblock
+ *
+ * This kernel routine readies the requested thread according to the queuing
+ * discipline. A new heir thread may be selected.
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ * the_thread - pointer to thread control block
+ *
+ * Output parameters: NONE
+ *
+ * NOTE: This routine uses the "blocking" heir selection mechanism.
+ * This ensures the correct heir after a thread restart.
+ *
+ * INTERRUPT LATENCY:
+ */
+
+void _Scheduler_priority_Unblock (
+ Scheduler_Control *the_scheduler,
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Unblock_body(the_scheduler, the_thread);
+}
diff --git a/cpukit/score/src/schedulerpriorityyield.c b/cpukit/score/src/schedulerpriorityyield.c
new file mode 100644
index 0000000000..1a13a4e318
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityyield.c
@@ -0,0 +1,77 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ *
+ * 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/apiext.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/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Scheduler_priority_Yield
+ *
+ * This kernel routine will remove the running THREAD from the ready queue
+ * and place it immediately 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 queue then the
+ * timeslice counter is reset. The heir THREAD will be updated if the
+ * running is also the currently the heir.
+ *
+ * Input parameters:
+ * the_scheduler - pointer to scheduler control
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * ready chain
+ * select heir
+ */
+
+void _Scheduler_priority_Yield(
+ Scheduler_Control *the_scheduler
+)
+{
+ ISR_Level level;
+ Thread_Control *executing;
+ Chain_Control *ready;
+
+ executing = _Thread_Executing;
+ ready = executing->scheduler.priority->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 *) ready->first;
+ _Thread_Dispatch_necessary = true;
+ }
+ else if ( !_Thread_Is_heir( executing ) )
+ _Thread_Dispatch_necessary = true;
+
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c
index f0891373f6..bf8e8939e7 100644
--- a/cpukit/score/src/thread.c
+++ b/cpukit/score/src/thread.c
@@ -24,6 +24,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -45,7 +46,6 @@
void _Thread_Handler_initialization(void)
{
- uint32_t index;
uint32_t ticks_per_timeslice;
uint32_t maximum_extensions;
#if defined(RTEMS_MULTIPROCESSING)
@@ -80,13 +80,6 @@ void _Thread_Handler_initialization(void)
_Thread_Ticks_per_timeslice = ticks_per_timeslice;
- _Thread_Ready_chain = (Chain_Control *) _Workspace_Allocate_or_fatal_error(
- (PRIORITY_MAXIMUM + 1) * sizeof(Chain_Control)
- );
-
- for ( index=0; index <= PRIORITY_MAXIMUM ; index++ )
- _Chain_Initialize_empty( &_Thread_Ready_chain[ index ] );
-
#if defined(RTEMS_MULTIPROCESSING)
_Thread_MP_Handler_initialization( maximum_proxies );
#endif
diff --git a/cpukit/score/src/threadchangepriority.c b/cpukit/score/src/threadchangepriority.c
index 58f5eb5fd3..7b46f799c7 100644
--- a/cpukit/score/src/threadchangepriority.c
+++ b/cpukit/score/src/threadchangepriority.c
@@ -23,6 +23,8 @@
#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/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -117,14 +119,16 @@ void _Thread_Change_priority(
* We now know the thread will be in the READY state when we remove
* the TRANSIENT state. So we have to place it on the appropriate
* Ready Queue with interrupts off.
+ *
+ * FIXME: hard-coded for priority scheduling. Might be ok since this
+ * function is specific to priority scheduling?
*/
the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
- _Priority_bit_map_Add( &the_thread->Priority_map );
if ( prepend_it )
- _Chain_Prepend_unprotected( the_thread->ready, &the_thread->Object.Node );
+ _Scheduler_priority_Ready_queue_enqueue_first( the_thread );
else
- _Chain_Append_unprotected( the_thread->ready, &the_thread->Object.Node );
+ _Scheduler_priority_Ready_queue_enqueue( the_thread );
}
_ISR_Flash( level );
@@ -133,7 +137,7 @@ void _Thread_Change_priority(
* We altered the set of thread priorities. So let's figure out
* who is the heir and if we need to switch to them.
*/
- _Thread_Calculate_heir();
+ _Scheduler_Schedule(&_Scheduler);
if ( !_Thread_Is_executing_also_the_heir() &&
_Thread_Executing->is_preemptible )
diff --git a/cpukit/score/src/threadclearstate.c b/cpukit/score/src/threadclearstate.c
index c5ab03497a..c3a9083197 100644
--- a/cpukit/score/src/threadclearstate.c
+++ b/cpukit/score/src/threadclearstate.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -66,31 +67,7 @@ void _Thread_Clear_state(
the_thread->current_state = _States_Clear( state, current_state );
if ( _States_Is_ready( current_state ) ) {
-
- _Priority_bit_map_Add( &the_thread->Priority_map );
-
- _Chain_Append_unprotected(the_thread->ready, &the_thread->Object.Node);
-
- _ISR_Flash( level );
-
- /*
- * 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_Unblock( &_Scheduler, the_thread);
}
}
_ISR_Enable( level );
diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c
index 51db06f56c..5098f0fbc4 100644
--- a/cpukit/score/src/threadclose.c
+++ b/cpukit/score/src/threadclose.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -86,6 +87,11 @@ void _Thread_Close(
}
/*
+ * Free the per-thread scheduling information.
+ */
+ _Scheduler_Thread_scheduler_free( &_Scheduler, the_thread );
+
+ /*
* The thread might have been FP. So deal with that.
*/
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 4afdbcb821..eda6f6bb5a 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -60,6 +61,7 @@ bool _Thread_Initialize(
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
void *fp_area;
#endif
+ void *sched = NULL;
void *extensions_area;
bool extension_status;
int i;
@@ -192,6 +194,9 @@ bool _Thread_Initialize(
the_thread->resource_count = 0;
the_thread->real_priority = priority;
the_thread->Start.initial_priority = priority;
+ sched =_Scheduler_Thread_scheduler_allocate( &_Scheduler, the_thread );
+ if ( !sched )
+ goto failed;
_Thread_Set_priority( the_thread, priority );
/*
@@ -235,6 +240,9 @@ failed:
(void) _Workspace_Free( fp_area );
#endif
+ if ( sched )
+ (void) _Workspace_Free( sched );
+
_Thread_Stack_Free( the_thread );
return false;
diff --git a/cpukit/score/src/threadready.c b/cpukit/score/src/threadready.c
index 3daa6506bd..f0e006503c 100644
--- a/cpukit/score/src/threadready.c
+++ b/cpukit/score/src/threadready.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -55,24 +56,12 @@ void _Thread_Ready(
)
{
ISR_Level level;
- Thread_Control *heir;
_ISR_Disable( level );
the_thread->current_state = STATES_READY;
- _Priority_bit_map_Add( &the_thread->Priority_map );
-
- _Chain_Append_unprotected( the_thread->ready, &the_thread->Object.Node );
-
- _ISR_Flash( level );
-
- _Thread_Calculate_heir();
-
- heir = _Thread_Heir;
-
- if ( !_Thread_Is_executing( heir ) && _Thread_Executing->is_preemptible )
- _Thread_Dispatch_necessary = true;
+ _Scheduler_Unblock( &_Scheduler, the_thread );
_ISR_Enable( level );
}
diff --git a/cpukit/score/src/threadresume.c b/cpukit/score/src/threadresume.c
index c82466d3b3..1997c3c293 100644
--- a/cpukit/score/src/threadresume.c
+++ b/cpukit/score/src/threadresume.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -68,19 +69,7 @@ void _Thread_Resume(
the_thread->current_state = _States_Clear(STATES_SUSPENDED, current_state);
if ( _States_Is_ready( current_state ) ) {
-
- _Priority_bit_map_Add( &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 )
- _Thread_Dispatch_necessary = true;
- }
+ _Scheduler_Unblock( &_Scheduler, the_thread );
}
}
diff --git a/cpukit/score/src/threadsetpriority.c b/cpukit/score/src/threadsetpriority.c
index cfe069d4ae..b55de24b43 100644
--- a/cpukit/score/src/threadsetpriority.c
+++ b/cpukit/score/src/threadsetpriority.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -50,10 +51,6 @@ void _Thread_Set_priority(
)
{
the_thread->current_priority = new_priority;
- the_thread->ready = &_Thread_Ready_chain[ new_priority ];
- _Priority_bit_map_Initialize_information(
- &the_thread->Priority_map,
- new_priority
- );
+ _Scheduler_Thread_scheduler_update(&_Scheduler, the_thread);
}
diff --git a/cpukit/score/src/threadsetstate.c b/cpukit/score/src/threadsetstate.c
index 2edd3bb70d..73a71b70e2 100644
--- a/cpukit/score/src/threadsetstate.c
+++ b/cpukit/score/src/threadsetstate.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -54,9 +55,7 @@ void _Thread_Set_state(
)
{
ISR_Level level;
- Chain_Control *ready;
-
- ready = the_thread->ready;
+
_ISR_Disable( level );
if ( !_States_Is_ready( the_thread->current_state ) ) {
the_thread->current_state =
@@ -67,21 +66,7 @@ void _Thread_Set_state(
the_thread->current_state = state;
- if ( _Chain_Has_only_one_node( ready ) ) {
-
- _Chain_Initialize_empty( ready );
- _Priority_bit_map_Remove( &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 ) )
- _Thread_Dispatch_necessary = true;
+ _Scheduler_Block( &_Scheduler, the_thread);
_ISR_Enable( level );
}
diff --git a/cpukit/score/src/threadsettransient.c b/cpukit/score/src/threadsettransient.c
index 36f60a6077..ce697f2d02 100644
--- a/cpukit/score/src/threadsettransient.c
+++ b/cpukit/score/src/threadsettransient.c
@@ -23,6 +23,8 @@
#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/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -54,22 +56,15 @@ void _Thread_Set_transient(
{
ISR_Level level;
uint32_t old_state;
- Chain_Control *ready;
-
- ready = the_thread->ready;
+
_ISR_Disable( level );
old_state = the_thread->current_state;
the_thread->current_state = _States_Set( STATES_TRANSIENT, old_state );
+ /* FIXME: need to check which scheduler to use? */
if ( _States_Is_ready( old_state ) ) {
- if ( _Chain_Has_only_one_node( ready ) ) {
-
- _Chain_Initialize_empty( ready );
- _Priority_bit_map_Remove( &the_thread->Priority_map );
-
- } else
- _Chain_Extract_unprotected( &the_thread->Object.Node );
+ _Scheduler_priority_Ready_queue_extract( the_thread);
}
_ISR_Enable( level );
diff --git a/cpukit/score/src/threadsuspend.c b/cpukit/score/src/threadsuspend.c
index 8cb2796691..8b4a631e5f 100644
--- a/cpukit/score/src/threadsuspend.c
+++ b/cpukit/score/src/threadsuspend.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -52,9 +53,7 @@ void _Thread_Suspend(
)
{
ISR_Level level;
- Chain_Control *ready;
-
- ready = the_thread->ready;
+
_ISR_Disable( level );
if ( !_States_Is_ready( the_thread->current_state ) ) {
the_thread->current_state =
@@ -65,21 +64,7 @@ void _Thread_Suspend(
the_thread->current_state = STATES_SUSPENDED;
- if ( _Chain_Has_only_one_node( ready ) ) {
-
- _Chain_Initialize_empty( ready );
- _Priority_bit_map_Remove( &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 ) )
- _Thread_Dispatch_necessary = true;
+ _Scheduler_Block(&_Scheduler, the_thread);
_ISR_Enable( level );
}
diff --git a/cpukit/score/src/threadtickletimeslice.c b/cpukit/score/src/threadtickletimeslice.c
index b05305650a..951339cb42 100644
--- a/cpukit/score/src/threadtickletimeslice.c
+++ b/cpukit/score/src/threadtickletimeslice.c
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
#include <rtems/score/states.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/thread.h>
@@ -89,7 +90,7 @@ void _Thread_Tickle_timeslice( void )
* currently executing thread is placed at the rear of the
* FIFO for this priority and a new heir is selected.
*/
- _Thread_Yield_processor();
+ _Scheduler_Yield( );
executing->cpu_time_budget = _Thread_Ticks_per_timeslice;
}
break;