forked from Imagelibrary/rtems
score: Add and use thread get/set CPU functions
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <rtems/cpuuse.h>
|
#include <rtems/cpuuse.h>
|
||||||
#include <rtems/score/objectimpl.h>
|
#include <rtems/score/objectimpl.h>
|
||||||
|
#include <rtems/score/threadimpl.h>
|
||||||
#include <rtems/score/todimpl.h>
|
#include <rtems/score/todimpl.h>
|
||||||
#include <rtems/score/watchdogimpl.h>
|
#include <rtems/score/watchdogimpl.h>
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@
|
|||||||
#else
|
#else
|
||||||
/* FIXME: Locking */
|
/* FIXME: Locking */
|
||||||
if ( the_thread->is_executing ) {
|
if ( the_thread->is_executing ) {
|
||||||
*time_of_context_switch = the_thread->cpu->time_of_last_context_switch;
|
*time_of_context_switch =
|
||||||
|
_Thread_Get_CPU( the_thread )->time_of_last_context_switch;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ static inline void _Scheduler_SMP_Allocate_processor(
|
|||||||
Thread_Control *victim
|
Thread_Control *victim
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Per_CPU_Control *cpu_of_scheduled = scheduled->cpu;
|
Per_CPU_Control *cpu_of_scheduled = _Thread_Get_CPU( scheduled );
|
||||||
Per_CPU_Control *cpu_of_victim = victim->cpu;
|
Per_CPU_Control *cpu_of_victim = _Thread_Get_CPU( victim );
|
||||||
Thread_Control *heir;
|
Thread_Control *heir;
|
||||||
|
|
||||||
scheduled->is_scheduled = true;
|
scheduled->is_scheduled = true;
|
||||||
@@ -88,7 +88,7 @@ static inline void _Scheduler_SMP_Allocate_processor(
|
|||||||
if ( heir != victim ) {
|
if ( heir != victim ) {
|
||||||
const Per_CPU_Control *cpu_of_executing = _Per_CPU_Get();
|
const Per_CPU_Control *cpu_of_executing = _Per_CPU_Get();
|
||||||
|
|
||||||
heir->cpu = cpu_of_victim;
|
_Thread_Set_CPU( heir, cpu_of_victim );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: Here we need atomic store operations with a relaxed memory order.
|
* FIXME: Here we need atomic store operations with a relaxed memory order.
|
||||||
|
|||||||
@@ -432,6 +432,32 @@ void _Thread_blocking_operation_Cancel(
|
|||||||
ISR_Level level
|
ISR_Level level
|
||||||
);
|
);
|
||||||
|
|
||||||
|
RTEMS_INLINE_ROUTINE Per_CPU_Control *_Thread_Get_CPU(
|
||||||
|
const Thread_Control *thread
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if defined(RTEMS_SMP)
|
||||||
|
return thread->cpu;
|
||||||
|
#else
|
||||||
|
(void) thread;
|
||||||
|
|
||||||
|
return _Per_CPU_Get();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
RTEMS_INLINE_ROUTINE void _Thread_Set_CPU(
|
||||||
|
Thread_Control *thread,
|
||||||
|
Per_CPU_Control *cpu
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if defined(RTEMS_SMP)
|
||||||
|
thread->cpu = cpu;
|
||||||
|
#else
|
||||||
|
(void) thread;
|
||||||
|
(void) cpu;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function returns true if the_thread is the currently executing
|
* This function returns true if the_thread is the currently executing
|
||||||
* thread, and false otherwise.
|
* thread, and false otherwise.
|
||||||
@@ -584,7 +610,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Signal_notification( Thread_Control *thread )
|
|||||||
#if defined(RTEMS_SMP)
|
#if defined(RTEMS_SMP)
|
||||||
if ( thread->is_executing ) {
|
if ( thread->is_executing ) {
|
||||||
const Per_CPU_Control *cpu_of_executing = _Per_CPU_Get();
|
const Per_CPU_Control *cpu_of_executing = _Per_CPU_Get();
|
||||||
Per_CPU_Control *cpu_of_thread = thread->cpu;
|
Per_CPU_Control *cpu_of_thread = _Thread_Get_CPU( thread );
|
||||||
|
|
||||||
if ( cpu_of_executing != cpu_of_thread ) {
|
if ( cpu_of_executing != cpu_of_thread ) {
|
||||||
cpu_of_thread->dispatch_necessary = true;
|
cpu_of_thread->dispatch_necessary = true;
|
||||||
|
|||||||
@@ -35,6 +35,6 @@ void _Scheduler_SMP_Start_idle(
|
|||||||
Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
|
Scheduler_SMP_Control *self = _Scheduler_SMP_Instance();
|
||||||
|
|
||||||
thread->is_scheduled = true;
|
thread->is_scheduled = true;
|
||||||
thread->cpu = cpu;
|
_Thread_Set_CPU( thread, cpu );
|
||||||
_Chain_Append_unprotected( &self->scheduled, &thread->Object.Node );
|
_Chain_Append_unprotected( &self->scheduled, &thread->Object.Node );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,15 +205,15 @@ bool _Thread_Initialize(
|
|||||||
the_thread->is_scheduled = false;
|
the_thread->is_scheduled = false;
|
||||||
the_thread->is_in_the_air = false;
|
the_thread->is_in_the_air = false;
|
||||||
the_thread->is_executing = false;
|
the_thread->is_executing = false;
|
||||||
|
|
||||||
/* Initialize the cpu field for the non-SMP schedulers */
|
|
||||||
the_thread->cpu = _Per_CPU_Get_by_index( 0 );
|
|
||||||
#if __RTEMS_HAVE_SYS_CPUSET_H__
|
#if __RTEMS_HAVE_SYS_CPUSET_H__
|
||||||
the_thread->affinity = *(_CPU_set_Default());
|
the_thread->affinity = *(_CPU_set_Default());
|
||||||
the_thread->affinity.set = &the_thread->affinity.preallocated;
|
the_thread->affinity.set = &the_thread->affinity.preallocated;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Initialize the CPU for the non-SMP schedulers */
|
||||||
|
_Thread_Set_CPU( the_thread, _Per_CPU_Get_by_index( 0 ) );
|
||||||
|
|
||||||
the_thread->current_state = STATES_DORMANT;
|
the_thread->current_state = STATES_DORMANT;
|
||||||
the_thread->Wait.queue = NULL;
|
the_thread->Wait.queue = NULL;
|
||||||
the_thread->resource_count = 0;
|
the_thread->resource_count = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user