Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2017 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 "tmacros.h"
0033 
0034 #include <rtems.h>
0035 
0036 const char rtems_test_name[] = "SMPSCHEDEDF 3";
0037 
0038 #define CPU_COUNT 32
0039 
0040 #define TASK_COUNT (3 * CPU_COUNT)
0041 
0042 typedef struct {
0043   rtems_id task_ids[TASK_COUNT];
0044 } test_context;
0045 
0046 static test_context test_instance;
0047 
0048 static void wait_task(rtems_task_argument arg)
0049 {
0050   (void) arg;
0051 
0052   while (true) {
0053     rtems_status_code sc;
0054 
0055     sc = rtems_task_wake_after(1);
0056     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0057   }
0058 }
0059 
0060 static uint32_t simple_random(uint32_t v)
0061 {
0062   v *= 1664525;
0063   v += 1013904223;
0064   return v;
0065 }
0066 
0067 static void affinity_task(rtems_task_argument arg)
0068 {
0069   uint32_t v;
0070   uint32_t n;
0071 
0072   v = (uint32_t) arg;
0073   n = rtems_scheduler_get_processor_maximum();
0074 
0075   while (true) {
0076     rtems_status_code sc;
0077     cpu_set_t set;
0078 
0079     CPU_ZERO(&set);
0080     CPU_SET((v >> 13) % n, &set);
0081     v = simple_random(v);
0082 
0083     sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(set), &set);
0084     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0085   }
0086 }
0087 
0088 static void create_and_start_task(
0089   test_context *ctx,
0090   rtems_task_entry entry,
0091   size_t i,
0092   size_t j
0093 )
0094 {
0095   rtems_status_code sc;
0096 
0097   j = j * CPU_COUNT + i;
0098 
0099   sc = rtems_task_create(
0100     rtems_build_name('E', 'D', 'F', ' '),
0101     i + 2,
0102     RTEMS_MINIMUM_STACK_SIZE,
0103     RTEMS_DEFAULT_MODES,
0104     RTEMS_DEFAULT_ATTRIBUTES,
0105     &ctx->task_ids[j]
0106   );
0107   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0108 
0109   sc = rtems_task_start(ctx->task_ids[j], entry, j);
0110   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0111 }
0112 
0113 static void delete_task(
0114   test_context *ctx,
0115   size_t i,
0116   size_t j
0117 )
0118 {
0119   rtems_status_code sc;
0120 
0121   j = j * CPU_COUNT + i;
0122 
0123   sc = rtems_task_delete(ctx->task_ids[j]);
0124   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0125 }
0126 
0127 static void test(test_context *ctx)
0128 {
0129   rtems_status_code sc;
0130   size_t i;
0131 
0132   for (i = 0; i < CPU_COUNT; ++i) {
0133     create_and_start_task(ctx, wait_task, i, 0);
0134     create_and_start_task(ctx, affinity_task, i, 1);
0135     create_and_start_task(ctx, affinity_task, i, 2);
0136   }
0137 
0138   sc = rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second());
0139   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0140 
0141   for (i = 0; i < CPU_COUNT; ++i) {
0142     delete_task(ctx, i, 0);
0143     delete_task(ctx, i, 1);
0144     delete_task(ctx, i, 2);
0145   }
0146 }
0147 
0148 static void Init(rtems_task_argument arg)
0149 {
0150   TEST_BEGIN();
0151   test(&test_instance);
0152   TEST_END();
0153   rtems_test_exit(0);
0154 }
0155 
0156 #define CONFIGURE_MICROSECONDS_PER_TICK 1000
0157 
0158 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0159 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0160 
0161 #define CONFIGURE_MAXIMUM_TASKS (1 + TASK_COUNT)
0162 
0163 #define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
0164 
0165 #define CONFIGURE_SCHEDULER_EDF_SMP
0166 
0167 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0168 
0169 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0170 
0171 #define CONFIGURE_INIT
0172 
0173 #include <rtems/confdefs.h>