File indexing completed on 2025-05-11 08:24:44
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 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <rtems/score/percpu.h>
0033 #include <rtems/score/smpimpl.h>
0034 #include <rtems/score/smpbarrier.h>
0035 #include <rtems.h>
0036 #include <rtems/sysinit.h>
0037
0038 #include <tmacros.h>
0039
0040 const char rtems_test_name[] = "SMPSTART 1";
0041
0042 typedef struct {
0043 const rtems_tcb *main_tcb;
0044 SMP_barrier_Control barrier;
0045 Per_CPU_Job job;
0046 } test_context;
0047
0048 static test_context test_instance;
0049
0050 static void barrier(test_context *ctx)
0051 {
0052 SMP_barrier_State bs;
0053
0054 _SMP_barrier_State_initialize(&bs);
0055 _SMP_barrier_Wait(&ctx->barrier, &bs, 2);
0056 }
0057
0058 static void prepare_second_cpu(void *arg)
0059 {
0060 test_context *ctx;
0061 Per_CPU_Control *cpu_self;
0062
0063 ctx = arg;
0064 cpu_self = _Per_CPU_Get();
0065
0066 barrier(ctx);
0067
0068 while (cpu_self->heir != ctx->main_tcb) {
0069 RTEMS_COMPILER_MEMORY_BARRIER();
0070 }
0071 }
0072
0073 static const Per_CPU_Job_context job_context = {
0074 .handler = prepare_second_cpu,
0075 .arg = &test_instance
0076 };
0077
0078 static void submit_job(void)
0079 {
0080 test_context *ctx;
0081
0082 ctx = &test_instance;
0083 _SMP_barrier_Control_initialize(&ctx->barrier);
0084 ctx->job.context = &job_context;
0085
0086 _Per_CPU_Submit_job(_Per_CPU_Get_by_index(1), &ctx->job);
0087 }
0088
0089 RTEMS_SYSINIT_ITEM(
0090 submit_job,
0091 RTEMS_SYSINIT_LAST,
0092 RTEMS_SYSINIT_ORDER_MIDDLE
0093 );
0094
0095 static void test(void)
0096 {
0097 test_context *ctx;
0098 rtems_status_code sc;
0099 rtems_id id;
0100
0101 ctx = &test_instance;
0102 ctx->main_tcb = _Thread_Get_executing();
0103
0104 barrier(ctx);
0105
0106 sc = rtems_scheduler_ident_by_processor(1, &id);
0107 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0108
0109 sc = rtems_task_set_scheduler(RTEMS_SELF, id, 1);
0110 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0111
0112 rtems_test_assert(rtems_scheduler_get_processor() == 1);
0113 rtems_test_assert(_ISR_Get_level() == 0);
0114 }
0115
0116 static void Init(rtems_task_argument arg)
0117 {
0118 TEST_BEGIN();
0119
0120 test();
0121
0122 TEST_END();
0123 rtems_test_exit(0);
0124 }
0125
0126 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0127 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0128
0129 #define CONFIGURE_MAXIMUM_PROCESSORS 2
0130
0131 #define CONFIGURE_SCHEDULER_EDF_SMP
0132
0133 #include <rtems/scheduler.h>
0134
0135 RTEMS_SCHEDULER_EDF_SMP(a);
0136
0137 RTEMS_SCHEDULER_EDF_SMP(b);
0138
0139 #define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
0140 RTEMS_SCHEDULER_TABLE_EDF_SMP(a, rtems_build_name('A', ' ', ' ', ' ')), \
0141 RTEMS_SCHEDULER_TABLE_EDF_SMP(b, rtems_build_name('B', ' ', ' ', ' '))
0142
0143 #define CONFIGURE_SCHEDULER_ASSIGNMENTS \
0144 RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \
0145 RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY)
0146
0147 #define CONFIGURE_MAXIMUM_TASKS 1
0148
0149 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0150
0151 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0152
0153 #define CONFIGURE_INIT
0154
0155 #include <rtems/confdefs.h>