source: rtems/testsuites/smptests/smpcapture01/init.c @ 3c50c328

5
Last change on this file since 3c50c328 was c9aba80, checked in by Sebastian Huber <sebastian.huber@…>, on 02/01/18 at 14:11:41

smpcapture01: Fix configuration

  • Property mode set to 100644
File size: 6.8 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 * The init task UT1 should start on cpu 3 and has priority:affinity set
12 * 7:{2,3} The test creates 4 more tasks TA1 - TA4
13 * with priorty:affinity sets 8:{2,3}, 5:{0,1}, 6:{0,3}, and 9:{1}.
14 * This should result in cpu:task  0:TA3, 1:TA2, 2:TA1, 3:UT1 with
15 * TA4 waiting on a cpu.
16 *
17 * The test then raises the priority of TA4 to 4, resulting
18 * in the following cpu:task 0:TA2, 1:TA4, 2:UT1, 3:TA3 with
19 * TA1 waiting on a CPU.  The tasks are then terminated.
20 *
21 * The capture engine is set up read and report the results.
22 */
23
24#ifdef HAVE_CONFIG_H
25  #include "config.h"
26#endif
27
28#include <rtems.h>
29#include <rtems/captureimpl.h>
30
31#include "tmacros.h"
32
33const char rtems_test_name[] = "SMPCAPTURE 1";
34
35#define NUM_CPUS   4
36#define TASK_COUNT 5
37
38struct task_data_t {
39  rtems_id            id;
40  cpu_set_t           cpuset;
41  rtems_task_priority priority;
42  bool                ran;
43  int                 expected_cpu;
44  int                 actual_cpu;
45  int                 migrate_cpu;
46};
47
48static struct task_data_t task_data[TASK_COUNT] = {
49  {0x0, {{0xc}}, 7, false,  3, -1,  2},
50  {0x0, {{0xf}}, 8, false,  2, -1, -1},
51  {0x0, {{0x3}}, 5, false,  1, -1,  0},
52  {0x0, {{0x9}}, 6, false,  0, -1,  3},
53  {0x0, {{0x2}}, 9, false, -1, -1,  1}
54};
55
56rtems_id           task_sem;
57
58/*
59 * Spin loop to allow tasks to delay without yeilding the
60 * processor.
61 */
62static void test_delay(int ticks)
63{
64  rtems_interval start, stop;
65  start = rtems_clock_get_ticks_since_boot();
66  do {
67    stop = rtems_clock_get_ticks_since_boot();
68  } while ( (stop - start) < ticks );
69}
70
71static void task(rtems_task_argument arg)
72{
73  rtems_status_code   sc;
74
75  while (true) {
76    sc = rtems_semaphore_obtain (task_sem, RTEMS_NO_WAIT, 0);
77    if (sc == RTEMS_SUCCESSFUL) {
78      task_data[arg].ran = true;
79      task_data[arg].actual_cpu = rtems_get_current_processor();
80      rtems_semaphore_release(task_sem);
81      test_delay(1);
82    }
83  }
84}
85
86static void set_init_task(void)
87{
88  while( rtems_semaphore_obtain (task_sem, RTEMS_NO_WAIT, 0) != RTEMS_SUCCESSFUL );
89
90  /* Set Init task data */
91  task_data[0].ran = true;
92  task_data[0].actual_cpu = rtems_get_current_processor();
93
94  rtems_semaphore_release(task_sem);
95}
96
97static void test(void)
98{
99  rtems_status_code   sc;
100  rtems_task_argument i;
101  size_t              size;
102  uint32_t            cpu_count;
103  rtems_task_priority priority;
104
105  /* Get the number of processors that we are using. */
106  cpu_count = rtems_get_processor_count();
107  if (cpu_count != 4) {
108    printf("Test requires a minimum of 4 cores\n");
109    return;
110  }
111
112  size = sizeof(cpu_set_t);
113  task_data[0].id = rtems_task_self();
114
115  sc = rtems_semaphore_create(
116    rtems_build_name('S', 'E', 'M', '0'),
117    1,                                               /* initial count = 1 */
118    RTEMS_LOCAL                   |
119    RTEMS_SIMPLE_BINARY_SEMAPHORE |
120    RTEMS_NO_INHERIT_PRIORITY     |
121    RTEMS_NO_PRIORITY_CEILING     |
122    RTEMS_FIFO,
123    0,
124    &task_sem
125  );
126  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
127
128  sc = rtems_task_set_affinity(
129    task_data[ 0 ].id,
130    size,
131    &task_data[0].cpuset
132  );
133  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
134
135
136  /* Create and start tasks on each cpu with the appropriate affinity. */
137  for (i = 1; i < TASK_COUNT; i++) {
138
139      sc = rtems_task_create(
140        rtems_build_name('T', 'A', '0', '0'+i),
141        task_data[ i ].priority,
142        RTEMS_MINIMUM_STACK_SIZE,
143        RTEMS_DEFAULT_MODES,
144        RTEMS_DEFAULT_ATTRIBUTES,
145        &task_data[ i ].id
146      );
147      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
148
149      sc = rtems_task_set_affinity(
150        task_data[ i ].id,
151        size,
152        &task_data[i].cpuset
153      );
154      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
155
156      sc = rtems_task_start( task_data[ i ].id, task, i );
157      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
158  }
159
160  /* spin for 10 ticks */
161  test_delay(10);
162
163  set_init_task();
164
165  i = TASK_COUNT - 1;
166  task_data[ i ].priority = 4;
167  sc = rtems_task_set_priority(
168    task_data[ i ].id,
169    task_data[ i ].priority,
170    &priority
171  );
172  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
173
174  test_delay(10);
175
176  while( rtems_semaphore_obtain (task_sem, RTEMS_NO_WAIT, 0) != RTEMS_SUCCESSFUL );
177  for (i = 0; i < TASK_COUNT; i++) {
178    task_data[ i ].expected_cpu = task_data[ i ].migrate_cpu;
179    task_data[ i ].actual_cpu = -1;
180    task_data[ i ].ran = false;
181  }
182  rtems_semaphore_release(task_sem);
183  test_delay(10);
184  set_init_task();
185
186  for (i = 1; i < TASK_COUNT; i++) {
187    sc = rtems_task_delete( task_data[ i ].id );
188    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
189  }
190  test_delay(25);
191}
192
193static void Init(rtems_task_argument arg)
194{
195  rtems_status_code   sc;
196  rtems_name          to_name = rtems_build_name('I', 'D', 'L', 'E');;
197  uint32_t            i;
198
199  TEST_BEGIN();
200
201  sc = rtems_capture_open (5000, NULL);
202  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
203
204  sc = rtems_capture_watch_ceiling (0);
205  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
206
207  sc = rtems_capture_watch_floor (20);
208  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
209
210  sc = rtems_capture_watch_global (true);
211  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
212
213  sc = rtems_capture_set_trigger (
214    0,
215    0,
216    to_name,
217    0,
218    rtems_capture_from_any,
219    rtems_capture_switch
220  );
221  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
222
223  for (i = 1; i < TASK_COUNT; i++) {
224     to_name = rtems_build_name('T', 'A', '0', '0'+i);
225     sc = rtems_capture_set_trigger (
226      0,
227      0,
228      to_name,
229      0,
230      rtems_capture_from_any,
231      rtems_capture_switch
232    );
233  }
234
235  sc = rtems_capture_set_control (true);
236  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
237
238  test();
239
240  sc = rtems_capture_set_control (false);
241  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
242
243  rtems_capture_print_trace_records ( 22, false );
244  rtems_capture_print_trace_records ( 22, false );
245  rtems_capture_print_trace_records ( 22, false );
246
247  TEST_END();
248  rtems_test_exit(0);
249}
250
251#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
252#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
253
254#define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
255
256#define CONFIGURE_MAXIMUM_SEMAPHORES 1
257
258#define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS
259
260#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
261
262#define CONFIGURE_INIT_TASK_PRIORITY       7
263#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
264
265#define TASK_ALLOCATION_SIZE     (5)
266#define CONFIGURE_MAXIMUM_TASKS  rtems_resource_unlimited(TASK_ALLOCATION_SIZE)
267#define CONFIGURE_EXTRA_TASK_STACKS (75 * RTEMS_MINIMUM_STACK_SIZE)
268
269#define CONFIGURE_MAXIMUM_USER_EXTENSIONS (5)
270
271#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
272
273#define CONFIGURE_INIT
274
275#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.