Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:44

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (C) 2022 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
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>