forked from Imagelibrary/rtems
score: Move per-processor job data structures
This enables re-use for other purposes, e.g. replacement for SMP_MESSAGE_TEST.
This commit is contained in:
@@ -77,8 +77,6 @@ struct _Thread_Control;
|
|||||||
|
|
||||||
struct Scheduler_Context;
|
struct Scheduler_Context;
|
||||||
|
|
||||||
struct Per_CPU_Job;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup PerCPU RTEMS Per CPU Information
|
* @defgroup PerCPU RTEMS Per CPU Information
|
||||||
*
|
*
|
||||||
@@ -175,6 +173,61 @@ typedef enum {
|
|||||||
PER_CPU_STATE_SHUTDOWN
|
PER_CPU_STATE_SHUTDOWN
|
||||||
} Per_CPU_State;
|
} Per_CPU_State;
|
||||||
|
|
||||||
|
typedef void ( *Per_CPU_Job_handler )( void *arg );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Context for per-processor jobs.
|
||||||
|
*
|
||||||
|
* This is separate from Per_CPU_Job to save stack memory in
|
||||||
|
* _SMP_Multicast_action().
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
/**
|
||||||
|
* @brief The job handler.
|
||||||
|
*/
|
||||||
|
Per_CPU_Job_handler handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The job handler argument.
|
||||||
|
*/
|
||||||
|
void *arg;
|
||||||
|
} Per_CPU_Job_context;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value for the Per_CPU_Job::done member to indicate that a job is done
|
||||||
|
* (handler was called on the target processor). Must not be a valid pointer
|
||||||
|
* value since it overlaps with the Per_CPU_Job::next member.
|
||||||
|
*/
|
||||||
|
#define PER_CPU_JOB_DONE 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A per-processor job.
|
||||||
|
*
|
||||||
|
* This structure must be as small as possible due to stack space constraints
|
||||||
|
* in _SMP_Multicast_action().
|
||||||
|
*/
|
||||||
|
typedef struct Per_CPU_Job {
|
||||||
|
union {
|
||||||
|
/**
|
||||||
|
* @brief The next job in the corresponding per-processor job list.
|
||||||
|
*/
|
||||||
|
struct Per_CPU_Job *next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indication if the job is done.
|
||||||
|
*
|
||||||
|
* A job is done if this member has the value PER_CPU_JOB_DONE. This
|
||||||
|
* assumes that PER_CPU_JOB_DONE is not a valid pointer value.
|
||||||
|
*/
|
||||||
|
Atomic_Ulong done;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Pointer to the job context to get the handler and argument.
|
||||||
|
*/
|
||||||
|
const Per_CPU_Job_context *context;
|
||||||
|
} Per_CPU_Job;
|
||||||
|
|
||||||
#endif /* defined( RTEMS_SMP ) */
|
#endif /* defined( RTEMS_SMP ) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,7 +369,7 @@ typedef struct Per_CPU_Control {
|
|||||||
uint32_t isr_nest_level;
|
uint32_t isr_nest_level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Indicetes if an ISR thread dispatch is disabled.
|
* @brief Indicates if an ISR thread dispatch is disabled.
|
||||||
*
|
*
|
||||||
* This flag is context switched with each thread. It indicates that this
|
* This flag is context switched with each thread. It indicates that this
|
||||||
* thread has an interrupt stack frame on its stack. By using this flag, we
|
* thread has an interrupt stack frame on its stack. By using this flag, we
|
||||||
|
|||||||
@@ -32,62 +32,6 @@
|
|||||||
#include <rtems/score/smpimpl.h>
|
#include <rtems/score/smpimpl.h>
|
||||||
#include <rtems/score/assert.h>
|
#include <rtems/score/assert.h>
|
||||||
|
|
||||||
typedef struct Per_CPU_Job Per_CPU_Job;
|
|
||||||
|
|
||||||
typedef struct Per_CPU_Jobs Per_CPU_Jobs;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Value for the Per_CPU_Job::done member to indicate that a job is done
|
|
||||||
* (handler was called on the target processor). Must not be a valid pointer
|
|
||||||
* value since it overlaps with the Per_CPU_Job::next member.
|
|
||||||
*/
|
|
||||||
#define PER_CPU_JOB_DONE 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief A per-processor job.
|
|
||||||
*/
|
|
||||||
struct Per_CPU_Job {
|
|
||||||
union {
|
|
||||||
/**
|
|
||||||
* @brief The next job in the corresponding per-processor job list.
|
|
||||||
*/
|
|
||||||
Per_CPU_Job *next;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Indication if the job is done.
|
|
||||||
*
|
|
||||||
* A job is done if this member has the value PER_CPU_JOB_DONE. This
|
|
||||||
* assumes that PER_CPU_JOB_DONE is not a valid pointer value.
|
|
||||||
*/
|
|
||||||
Atomic_Ulong done;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Back pointer to the jobs to get the handler and argument.
|
|
||||||
*/
|
|
||||||
Per_CPU_Jobs *jobs;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief A collection of jobs, one for each processor.
|
|
||||||
*/
|
|
||||||
struct Per_CPU_Jobs {
|
|
||||||
/**
|
|
||||||
* @brief The job handler.
|
|
||||||
*/
|
|
||||||
SMP_Action_handler handler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The job handler argument.
|
|
||||||
*/
|
|
||||||
void *arg;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief One job for each potential processor.
|
|
||||||
*/
|
|
||||||
Per_CPU_Job Jobs[ CPU_MAXIMUM_PROCESSORS ];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define _Per_CPU_Jobs_ISR_disable_and_acquire( cpu, lock_context ) \
|
#define _Per_CPU_Jobs_ISR_disable_and_acquire( cpu, lock_context ) \
|
||||||
_ISR_lock_ISR_disable_and_acquire( &( cpu )->Jobs.Lock, lock_context )
|
_ISR_lock_ISR_disable_and_acquire( &( cpu )->Jobs.Lock, lock_context )
|
||||||
|
|
||||||
@@ -102,13 +46,13 @@ void _Per_CPU_Perform_jobs( Per_CPU_Control *cpu )
|
|||||||
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
||||||
|
|
||||||
while ( ( job = cpu->Jobs.head ) != NULL ) {
|
while ( ( job = cpu->Jobs.head ) != NULL ) {
|
||||||
Per_CPU_Jobs *jobs;
|
const Per_CPU_Job_context *context;
|
||||||
|
|
||||||
cpu->Jobs.head = job->next;
|
cpu->Jobs.head = job->next;
|
||||||
_Per_CPU_Jobs_release_and_ISR_enable( cpu, &lock_context );
|
_Per_CPU_Jobs_release_and_ISR_enable( cpu, &lock_context );
|
||||||
|
|
||||||
jobs = job->jobs;
|
context = job->context;
|
||||||
( *jobs->handler )( jobs->arg );
|
( *context->handler )( context->arg );
|
||||||
_Atomic_Store_ulong( &job->done, PER_CPU_JOB_DONE, ATOMIC_ORDER_RELEASE );
|
_Atomic_Store_ulong( &job->done, PER_CPU_JOB_DONE, ATOMIC_ORDER_RELEASE );
|
||||||
|
|
||||||
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
||||||
@@ -138,9 +82,14 @@ static void _Per_CPU_Try_perform_jobs( Per_CPU_Control *cpu_self )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Per_CPU_Job_context Context;
|
||||||
|
Per_CPU_Job Jobs[ CPU_MAXIMUM_PROCESSORS ];
|
||||||
|
} SMP_Multicast_jobs;
|
||||||
|
|
||||||
static void _SMP_Issue_action_jobs(
|
static void _SMP_Issue_action_jobs(
|
||||||
const Processor_mask *targets,
|
const Processor_mask *targets,
|
||||||
Per_CPU_Jobs *jobs,
|
SMP_Multicast_jobs *jobs,
|
||||||
uint32_t cpu_max
|
uint32_t cpu_max
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -155,7 +104,7 @@ static void _SMP_Issue_action_jobs(
|
|||||||
job = &jobs->Jobs[ cpu_index ];
|
job = &jobs->Jobs[ cpu_index ];
|
||||||
_Atomic_Store_ulong( &job->done, 0, ATOMIC_ORDER_RELAXED );
|
_Atomic_Store_ulong( &job->done, 0, ATOMIC_ORDER_RELAXED );
|
||||||
_Assert( job->next == NULL );
|
_Assert( job->next == NULL );
|
||||||
job->jobs = jobs;
|
job->context = &jobs->Context;
|
||||||
|
|
||||||
cpu = _Per_CPU_Get_by_index( cpu_index );
|
cpu = _Per_CPU_Get_by_index( cpu_index );
|
||||||
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
_Per_CPU_Jobs_ISR_disable_and_acquire( cpu, &lock_context );
|
||||||
@@ -176,7 +125,7 @@ static void _SMP_Issue_action_jobs(
|
|||||||
|
|
||||||
static void _SMP_Wait_for_action_jobs(
|
static void _SMP_Wait_for_action_jobs(
|
||||||
const Processor_mask *targets,
|
const Processor_mask *targets,
|
||||||
const Per_CPU_Jobs *jobs,
|
const SMP_Multicast_jobs *jobs,
|
||||||
uint32_t cpu_max
|
uint32_t cpu_max
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -223,14 +172,14 @@ void _SMP_Multicast_action(
|
|||||||
void *arg
|
void *arg
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Per_CPU_Jobs jobs;
|
SMP_Multicast_jobs jobs;
|
||||||
uint32_t cpu_max;
|
uint32_t cpu_max;
|
||||||
|
|
||||||
cpu_max = _SMP_Get_processor_maximum();
|
cpu_max = _SMP_Get_processor_maximum();
|
||||||
_Assert( cpu_max <= CPU_MAXIMUM_PROCESSORS );
|
_Assert( cpu_max <= RTEMS_ARRAY_SIZE( jobs.Jobs ) );
|
||||||
|
|
||||||
jobs.handler = handler;
|
jobs.Context.handler = handler;
|
||||||
jobs.arg = arg;
|
jobs.Context.arg = arg;
|
||||||
|
|
||||||
_SMP_Issue_action_jobs( targets, &jobs, cpu_max );
|
_SMP_Issue_action_jobs( targets, &jobs, cpu_max );
|
||||||
_SMP_Wait_for_action_jobs( targets, &jobs, cpu_max );
|
_SMP_Wait_for_action_jobs( targets, &jobs, cpu_max );
|
||||||
|
|||||||
Reference in New Issue
Block a user