source: rtems/testsuites/smptests/smpschedaffinity01/init.c @ 91f39a5

5
Last change on this file since 91f39a5 was 91f39a5, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/18 at 09:56:25

smptests: Fix format warnings

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 2014.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10/*
11 * Start 4 tasks with affinity for each of the 4 cpus.
12 * Allow tasks to set their actual cpu value and delete themselves.
13 * Verify the actual cpu values match the expected cpu values.
14 *
15 * Init task is at a lower priority 8 and the threads
16 * with affinity are at priority 4, so the affinity task
17 * on the core init is running on will preempt it.
18 *
19 * Test tasks run and delete themselves.
20 * Init task never blocks.
21 */
22
23#ifdef HAVE_CONFIG_H
24  #include "config.h"
25#endif
26
27#include <rtems.h>
28
29#include "tmacros.h"
30
31const char rtems_test_name[] = "SMPSCHEDAFFINITY 1";
32
33#define NUM_CPUS   4
34#define TASK_COUNT 5
35
36struct task_data_t {
37  rtems_id   id;
38  int        expected_cpu;
39  cpu_set_t  cpuset;
40  bool       ran;
41  int        actual_cpu;
42};
43
44static struct task_data_t task_data[NUM_CPUS] = {
45  {0x0, 2, {{0x4}}, false, -1},
46  {0x0, 0, {{0x1}}, false, -1},
47  {0x0, 3, {{0x8}}, false, -1},
48  {0x0, 1, {{0x2}}, false, -1}
49};
50 
51/*
52 * Spin loop to allow tasks to delay without yeilding the
53 * processor.
54 */
55static void test_delay(int ticks)
56{
57  rtems_interval start, stop;
58  start = rtems_clock_get_ticks_since_boot();
59  do {
60    stop = rtems_clock_get_ticks_since_boot();
61  } while ( (stop - start) < ticks );
62}
63
64static void task(rtems_task_argument arg)
65{
66  uint32_t cpu;
67  cpu_set_t cpuset;
68
69  cpu = rtems_get_current_processor();
70
71  rtems_task_get_affinity( rtems_task_self(), sizeof(cpuset), &cpuset );
72
73  task_data[arg].ran = true;
74  task_data[arg].actual_cpu = cpu;
75
76  rtems_task_delete( RTEMS_SELF );
77}
78
79static void test(void)
80{
81  rtems_status_code   sc;
82  rtems_task_argument i;
83  size_t              size;
84  uint32_t            cpu_count;
85
86  /* Get the number of processors that we are using. */
87  cpu_count = rtems_get_processor_count();
88 
89  size = sizeof(cpu_set_t);
90
91  /* Create and start tasks on each cpu with the appropriate affinity. */
92  for (i = 0; i < NUM_CPUS; i++) {
93
94      /* Skip if this cpu doesn't exist, don't create task */
95      if ( task_data[i].expected_cpu >= cpu_count ) {
96        printf(
97          "Skipping TA0%" PRIdrtems_task_argument
98            " because on a core we do not have\n",
99          i
100        );
101        continue;
102      }
103
104      sc = rtems_task_create(
105        rtems_build_name('T', 'A', '0', '0'+i),
106        4,
107        RTEMS_MINIMUM_STACK_SIZE,
108        RTEMS_DEFAULT_MODES,
109        RTEMS_DEFAULT_ATTRIBUTES,
110        &task_data[ i ].id
111      );
112      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
113
114      printf(
115        "Set TA%" PRIdrtems_task_argument " affinity to cpu %d\n",
116        i,
117        task_data[i].expected_cpu
118      );
119      sc = rtems_task_set_affinity( task_data[ i ].id, size, &task_data[i].cpuset );
120      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
121
122      printf(
123        "Start TA%" PRIdrtems_task_argument " on cpu %d\n",
124        i,
125        task_data[i].expected_cpu
126      );
127      sc = rtems_task_start( task_data[ i ].id, task, i );
128      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
129  }
130
131  /* spin for 100 ticks */
132  test_delay(100);
133
134  printf("Verify Tasks Ran\n");
135  for (i = 0; i < NUM_CPUS; i++) {
136
137    /* Skip if this cpu doesn't exist, task doesn't exist */
138    if ( task_data[i].expected_cpu >= cpu_count ) {
139      printf(
140        "Skipping TA0%" PRIdrtems_task_argument
141          " because on a core we do not have\n",
142        i
143      );
144      continue;
145    }
146
147    /* print the expected and actual values */
148    printf(
149      "TA0%" PRIdrtems_task_argument ": ran=%d expected=%d actual=%d\n",
150      i,
151      task_data[i].ran,
152      task_data[i].expected_cpu,
153      task_data[i].actual_cpu
154    );
155
156    /*  Abort test if values are not as expected */
157    rtems_test_assert( task_data[i].ran == true );
158    rtems_test_assert( task_data[i].expected_cpu == task_data[i].actual_cpu );
159  }
160}
161
162static void Init(rtems_task_argument arg)
163{
164  TEST_BEGIN();
165
166  test();
167
168  TEST_END();
169  rtems_test_exit(0);
170}
171
172#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
173#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
174
175#define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
176
177#define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS
178
179#define CONFIGURE_MAXIMUM_TASKS          TASK_COUNT
180
181#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
182
183  #define CONFIGURE_INIT_TASK_PRIORITY      8
184#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
185
186#define CONFIGURE_INIT
187
188#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.