File indexing completed on 2025-05-11 08:24:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040
0041 #include "tx-support.h"
0042
0043 #include <rtems/sysinit.h>
0044 #include <rtems/score/chainimpl.h>
0045 #include <rtems/score/percpu.h>
0046 #include <rtems/score/threadimpl.h>
0047
0048 #include <rtems/test.h>
0049
0050 #if defined(RTEMS_SMP)
0051 typedef struct {
0052 void ( *handler )( void * );
0053 void *arg;
0054 Scheduler_Context scheduler_context;
0055 Scheduler_Node scheduler_node;
0056 Thread_Control thread;
0057 } PreemptionInterventionContext;
0058
0059 static PreemptionInterventionContext preemption_intervention_instance;
0060
0061 static bool PreemptionInterventionAskForHelp(
0062 const Scheduler_Control *scheduler,
0063 Thread_Control *thread,
0064 Scheduler_Node *node
0065 )
0066 {
0067 PreemptionInterventionContext *ctx;
0068 void ( *handler )( void * );
0069 void *arg;
0070
0071 (void) scheduler;
0072 (void) thread;
0073 (void) node;
0074
0075 ctx = &preemption_intervention_instance;
0076 handler = ctx->handler;
0077 arg = ctx->arg;
0078 ctx->handler = NULL;
0079 ctx->arg = NULL;
0080 ( *handler )( arg );
0081
0082 return true;
0083 }
0084
0085 static const Scheduler_Control preemption_intervention_scheduler = {
0086 .context = &preemption_intervention_instance.scheduler_context,
0087 .Operations = {
0088 .ask_for_help = PreemptionInterventionAskForHelp
0089 }
0090 };
0091
0092 static void PreemptionInterventionInitialize( void )
0093 {
0094 PreemptionInterventionContext *ctx;
0095
0096 ctx = &preemption_intervention_instance;
0097
0098 _Chain_Initialize_node( &ctx->thread.Scheduler.Help_node );
0099 _Thread_queue_Initialize(
0100 &ctx->thread.Join_queue,
0101 "Preemption Intervention"
0102 );
0103 _ISR_lock_Initialize(
0104 &ctx->scheduler_context.Lock,
0105 "Preemption Intervention"
0106 );
0107 _Scheduler_Node_do_initialize(
0108 &preemption_intervention_scheduler,
0109 &ctx->scheduler_node,
0110 &ctx->thread,
0111 0
0112 );
0113 _Chain_Initialize_one(
0114 &ctx->thread.Scheduler.Scheduler_nodes,
0115 &ctx->scheduler_node.Thread.Scheduler_node.Chain
0116 );
0117 }
0118
0119 RTEMS_SYSINIT_ITEM(
0120 PreemptionInterventionInitialize,
0121 RTEMS_SYSINIT_DEVICE_DRIVERS,
0122 RTEMS_SYSINIT_ORDER_MIDDLE
0123 );
0124 #endif
0125
0126 void SetPreemptionIntervention(
0127 struct Per_CPU_Control *cpu,
0128 void ( *handler )( void * ),
0129 void *arg
0130 )
0131 {
0132 #if defined(RTEMS_SMP)
0133 PreemptionInterventionContext *ctx;
0134 rtems_interrupt_level level;
0135 ISR_lock_Context lock_context;
0136
0137 ctx = &preemption_intervention_instance;
0138 T_quiet_assert_null( ctx->handler );
0139 ctx->handler = handler;
0140 ctx->arg = arg;
0141
0142 rtems_interrupt_local_disable( level );
0143 _Per_CPU_Acquire( cpu, &lock_context );
0144 _Chain_Append_unprotected(
0145 &cpu->Threads_in_need_for_help,
0146 &ctx->thread.Scheduler.Help_node
0147 );
0148 _Per_CPU_Release( cpu, &lock_context );
0149 rtems_interrupt_local_enable( level );
0150 #else
0151 (void) cpu;
0152 (void) handler;
0153 (void) arg;
0154 #endif
0155 }