15 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
|
/* remaining to do is to implement some form of round robin scheduling |
|
|
for realtime threads. */ |
|
|
|
|
18 |
#include <rtmk/kern-return.h> |
#include <rtmk/kern-return.h> |
19 |
|
|
20 |
#include "tm.h" |
#include "tm.h" |
195 |
There might not be an old thread, if we are |
There might not be an old thread, if we are |
196 |
the first thread to run on this processor. */ |
the first thread to run on this processor. */ |
197 |
|
|
198 |
|
#if 0 |
199 |
if (old_thread != 0) |
if (old_thread != 0) |
200 |
thread_dispatch (old_thread); |
thread_dispatch (old_thread); |
|
|
|
|
#if 0 |
|
|
trace_printf ("new stack ?"); |
|
201 |
#endif |
#endif |
202 |
|
|
203 |
SPL0 (); |
SPL0 (); |
214 |
thread_invoke (struct thread *old_thread, void (*continuation) (void), |
thread_invoke (struct thread *old_thread, void (*continuation) (void), |
215 |
struct thread *new_thread) |
struct thread *new_thread) |
216 |
{ |
{ |
217 |
|
|
218 |
/* Check if we're invoking the current thread. */ |
/* Check if we're invoking the current thread. */ |
219 |
if (new_thread == old_thread) |
if (new_thread == old_thread) |
220 |
{ |
{ |
227 |
return true; |
return true; |
228 |
} |
} |
229 |
|
|
230 |
|
#if 0 |
231 |
|
trace_printf ("cpu #%d old %p new %p cont %p", |
232 |
|
CPU_CURRENT (), old_thread, new_thread, continuation); |
233 |
|
#endif |
234 |
|
|
235 |
/* Check for stack handoff. */ |
/* Check for stack handoff. */ |
236 |
|
|
237 |
if (continuation != 0) |
if (continuation != 0) |
269 |
{ |
{ |
270 |
if (new_thread->sched_state & THREAD_STATE_SWAPPED) |
if (new_thread->sched_state & THREAD_STATE_SWAPPED) |
271 |
{ |
{ |
|
#if 0 |
|
|
trace_printf ("here! %x", new_thread->sched_state); |
|
|
#endif |
|
|
|
|
272 |
stack_alloc (new_thread, (void (*)()) thread_continue); |
stack_alloc (new_thread, (void (*)()) thread_continue); |
273 |
new_thread->sched_state &= ~THREAD_STATE_SWAPPED; |
new_thread->sched_state &= ~THREAD_STATE_SWAPPED; |
274 |
} |
} |
275 |
|
|
276 |
switch (old_thread->sched_state & ~THREAD_STATE_SWAPPED) |
switch (old_thread->sched_state & ~THREAD_STATE_SWAPPED) |
277 |
{ |
{ |
278 |
case THREAD_STATE_RUN: |
case THREAD_STATE_RUN: |
292 |
void (*new_continuation) () = new_thread->swap_fn; |
void (*new_continuation) () = new_thread->swap_fn; |
293 |
|
|
294 |
new_thread->swap_fn = (void (*)()) 0; |
new_thread->swap_fn = (void (*)()) 0; |
295 |
#if 0 |
|
|
trace_printf ("here"); |
|
|
#endif |
|
296 |
SPL0 (); |
SPL0 (); |
297 |
CALL_CONTINUATION (new_continuation); |
CALL_CONTINUATION (new_continuation); |
298 |
/* NOTREACHED */ |
/* NOTREACHED */ |
573 |
|
|
574 |
if (! thread->blocked_lock) |
if (! thread->blocked_lock) |
575 |
break; |
break; |
576 |
thread = thread->blocked_lock->thread; |
thread = thread->blocked_lock->owner; |
577 |
} |
} |
578 |
|
|
579 |
SPLON (spl); |
SPLON (spl); |
666 |
{ |
{ |
667 |
thread = (*sched_policies[i].ops->select_fn) (&sched_policies[i], |
thread = (*sched_policies[i].ops->select_fn) (&sched_policies[i], |
668 |
processor); |
processor); |
|
#if 0 |
|
|
if (thread) |
|
|
trace_printf ("got thread %p %d", thread, |
|
|
(int) thread->scratch_area [3]); |
|
|
#endif |
|
669 |
if (thread) |
if (thread) |
670 |
return thread; |
return thread; |
671 |
} |
} |
731 |
|
|
732 |
assert ((thread->sched_state & THREAD_SCHED_STATE) == THREAD_STATE_RUN); |
assert ((thread->sched_state & THREAD_SCHED_STATE) == THREAD_STATE_RUN); |
733 |
|
|
734 |
#if NCPUS > 1 |
#if NCPUS > 1 |
735 |
/* First check if we can continue to execute on processor that last |
/* First check if we can continue to execute on processor that last |
736 |
executed thread. */ |
executed thread. */ |
737 |
|
|
744 |
processor->state = PROCESSOR_STATE_DISPATCH; |
processor->state = PROCESSOR_STATE_DISPATCH; |
745 |
|
|
746 |
/* ??? send interrupt to processor. */ |
/* ??? send interrupt to processor. */ |
|
return; |
|
747 |
} |
} |
748 |
} |
} |
749 |
|
|
760 |
processor->state = PROCESSOR_STATE_DISPATCH; |
processor->state = PROCESSOR_STATE_DISPATCH; |
761 |
|
|
762 |
/* ??? send interrupt to processor. */ |
/* ??? send interrupt to processor. */ |
763 |
return; |
|
764 |
} |
} |
765 |
else if (processor->state == PROCESSOR_STATE_RUNNING && |
else if (processor->state == PROCESSOR_STATE_RUNNING && |
766 |
thread->sched_premul > processor->current_thread->sched_premul) |
thread->sched_premul > processor->current_thread->sched_premul) |
767 |
{ |
{ |
768 |
/* ??? send interrupt to processor. */ |
/* ??? send interrupt to processor. */ |
769 |
return; |
|
770 |
} |
} |
771 |
} |
} |
772 |
#endif |
#endif |