source: rtems/testsuites/smptests/smpscheduler04/init.c @ 03c9f24

5
Last change on this file since 03c9f24 was 03c9f24, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 5, 2019 at 6:03:12 AM

rtems: Add rtems_scheduler_get_processor()

Add rtems_scheduler_get_processor() as a replacement for
rtems_get_current_processor(). The rtems_get_current_processor() is a
bit orphaned. Adopt it by the Scheduler Manager. This is in line with
the glibc sched_getcpu() function.

Deprecate rtems_get_current_processor().

Update #3731.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <inttypes.h>
20#include <string.h>
21#include <stdio.h>
22
23#include <rtems.h>
24#include <rtems/libcsupport.h>
25
26#include "tmacros.h"
27
28const char rtems_test_name[] = "SMPSCHEDULER 4";
29
30#define CPU_COUNT 32
31
32#define PRIO_MIGRATION 2
33
34#define PRIO_SCHEDULER 3
35
36typedef struct {
37  rtems_id migration_task;
38  rtems_id scheduler_task;
39  rtems_id scheduler_ids[CPU_COUNT];
40  uint32_t migration_counter RTEMS_ALIGNED(CPU_CACHE_LINE_BYTES);
41  uint32_t scheduler_counter RTEMS_ALIGNED(CPU_CACHE_LINE_BYTES);
42} test_context;
43
44static test_context test_instance;
45
46static void migration_task(rtems_task_argument arg)
47{
48  test_context *ctx = (test_context *) arg;
49  uint32_t cpu_count = rtems_get_processor_count();
50  uint32_t cpu_index = rtems_scheduler_get_processor();
51
52  while (true) {
53    rtems_status_code sc;
54
55    cpu_index = (cpu_index + 1) % cpu_count;
56
57    sc = rtems_task_set_scheduler(
58      RTEMS_SELF,
59      ctx->scheduler_ids[cpu_index],
60      PRIO_MIGRATION
61    );
62
63    if (sc == RTEMS_UNSATISFIED) {
64      continue;
65    }
66
67    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
68    rtems_test_assert(cpu_index == rtems_scheduler_get_processor());
69    ++ctx->migration_counter;
70  }
71}
72
73static void scheduler_task(rtems_task_argument arg)
74{
75  test_context *ctx = (test_context *) arg;
76  uint32_t cpu_count = rtems_get_processor_count();
77  uint32_t cpu_index = rtems_scheduler_get_processor();
78
79  while (true) {
80    rtems_status_code sc;
81
82    cpu_index = (cpu_index - 1) % cpu_count;
83
84    if (cpu_index == 0) {
85      cpu_index = 1;
86    }
87
88    do {
89      sc = rtems_scheduler_remove_processor(
90        ctx->scheduler_ids[cpu_index],
91        cpu_index
92      );
93    } while (sc == RTEMS_RESOURCE_IN_USE);
94
95    sc = rtems_scheduler_add_processor(
96      ctx->scheduler_ids[cpu_index],
97      cpu_index
98    );
99    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
100
101    ++ctx->scheduler_counter;
102  }
103}
104
105static void test(test_context *ctx)
106{
107  rtems_status_code sc;
108  uint32_t i;
109
110  for (i = 0; i < rtems_get_processor_count(); ++i) {
111    sc = rtems_scheduler_ident(i, &ctx->scheduler_ids[i]);
112    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
113  }
114
115  sc = rtems_task_create(
116    rtems_build_name('M', 'I', 'G', 'R'),
117    PRIO_MIGRATION,
118    RTEMS_MINIMUM_STACK_SIZE,
119    RTEMS_DEFAULT_MODES,
120    RTEMS_DEFAULT_ATTRIBUTES,
121    &ctx->migration_task
122  );
123  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
124
125  sc = rtems_task_start(
126    ctx->migration_task,
127    migration_task,
128    (rtems_task_argument) ctx
129  );
130  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
131
132  sc = rtems_task_create(
133    rtems_build_name('S', 'C', 'H', 'D'),
134    PRIO_SCHEDULER,
135    RTEMS_MINIMUM_STACK_SIZE,
136    RTEMS_DEFAULT_MODES,
137    RTEMS_DEFAULT_ATTRIBUTES,
138    &ctx->scheduler_task
139  );
140  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
141
142  sc = rtems_task_start(
143    ctx->scheduler_task,
144    scheduler_task,
145    (rtems_task_argument) ctx
146  );
147  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
148
149  sc = rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second());
150  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
151
152  sc = rtems_task_delete(ctx->migration_task);
153  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
154
155  sc = rtems_task_delete(ctx->scheduler_task);
156  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
157
158  printf(
159    "migration counter = %" PRIu32 "\n"
160    "scheduler counter = %" PRIu32 "\n",
161    ctx->migration_counter,
162    ctx->scheduler_counter
163  );
164}
165
166static void Init(rtems_task_argument arg)
167{
168  rtems_resource_snapshot snapshot;
169
170  TEST_BEGIN();
171  rtems_resource_snapshot_take(&snapshot);
172  test(&test_instance);
173  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
174  TEST_END();
175  rtems_test_exit(0);
176}
177
178#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
179#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
180
181#define CONFIGURE_MAXIMUM_TASKS 3
182
183#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
184
185#define CONFIGURE_SCHEDULER_SIMPLE_SMP
186
187#include <rtems/scheduler.h>
188
189RTEMS_SCHEDULER_SIMPLE_SMP(0);
190RTEMS_SCHEDULER_SIMPLE_SMP(1);
191RTEMS_SCHEDULER_SIMPLE_SMP(2);
192RTEMS_SCHEDULER_SIMPLE_SMP(3);
193RTEMS_SCHEDULER_SIMPLE_SMP(4);
194RTEMS_SCHEDULER_SIMPLE_SMP(5);
195RTEMS_SCHEDULER_SIMPLE_SMP(6);
196RTEMS_SCHEDULER_SIMPLE_SMP(7);
197RTEMS_SCHEDULER_SIMPLE_SMP(8);
198RTEMS_SCHEDULER_SIMPLE_SMP(9);
199RTEMS_SCHEDULER_SIMPLE_SMP(10);
200RTEMS_SCHEDULER_SIMPLE_SMP(11);
201RTEMS_SCHEDULER_SIMPLE_SMP(12);
202RTEMS_SCHEDULER_SIMPLE_SMP(13);
203RTEMS_SCHEDULER_SIMPLE_SMP(14);
204RTEMS_SCHEDULER_SIMPLE_SMP(15);
205RTEMS_SCHEDULER_SIMPLE_SMP(16);
206RTEMS_SCHEDULER_SIMPLE_SMP(17);
207RTEMS_SCHEDULER_SIMPLE_SMP(18);
208RTEMS_SCHEDULER_SIMPLE_SMP(19);
209RTEMS_SCHEDULER_SIMPLE_SMP(20);
210RTEMS_SCHEDULER_SIMPLE_SMP(21);
211RTEMS_SCHEDULER_SIMPLE_SMP(22);
212RTEMS_SCHEDULER_SIMPLE_SMP(23);
213RTEMS_SCHEDULER_SIMPLE_SMP(24);
214RTEMS_SCHEDULER_SIMPLE_SMP(25);
215RTEMS_SCHEDULER_SIMPLE_SMP(26);
216RTEMS_SCHEDULER_SIMPLE_SMP(27);
217RTEMS_SCHEDULER_SIMPLE_SMP(28);
218RTEMS_SCHEDULER_SIMPLE_SMP(29);
219RTEMS_SCHEDULER_SIMPLE_SMP(30);
220RTEMS_SCHEDULER_SIMPLE_SMP(31);
221
222#define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
223  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(0, 0), \
224  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(1, 1), \
225  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(2, 2), \
226  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(3, 3), \
227  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(4, 4), \
228  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(5, 5), \
229  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(6, 6), \
230  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(7, 7), \
231  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(8, 8), \
232  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(9, 9), \
233  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(10, 10), \
234  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(11, 11), \
235  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(12, 12), \
236  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(13, 13), \
237  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(14, 14), \
238  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(15, 15), \
239  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(16, 16), \
240  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(17, 17), \
241  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(18, 18), \
242  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(19, 19), \
243  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(20, 20), \
244  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(21, 21), \
245  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(22, 22), \
246  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(23, 23), \
247  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(24, 24), \
248  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(25, 25), \
249  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(26, 26), \
250  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(27, 27), \
251  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(28, 28), \
252  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(29, 29), \
253  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(30, 30), \
254  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(31, 31)
255
256#define CONFIGURE_SCHEDULER_ASSIGNMENTS \
257  RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \
258  RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
259  RTEMS_SCHEDULER_ASSIGN(2, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
260  RTEMS_SCHEDULER_ASSIGN(3, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
261  RTEMS_SCHEDULER_ASSIGN(4, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
262  RTEMS_SCHEDULER_ASSIGN(5, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
263  RTEMS_SCHEDULER_ASSIGN(6, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
264  RTEMS_SCHEDULER_ASSIGN(7, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
265  RTEMS_SCHEDULER_ASSIGN(8, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
266  RTEMS_SCHEDULER_ASSIGN(9, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
267  RTEMS_SCHEDULER_ASSIGN(10, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
268  RTEMS_SCHEDULER_ASSIGN(11, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
269  RTEMS_SCHEDULER_ASSIGN(12, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
270  RTEMS_SCHEDULER_ASSIGN(13, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
271  RTEMS_SCHEDULER_ASSIGN(14, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
272  RTEMS_SCHEDULER_ASSIGN(15, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
273  RTEMS_SCHEDULER_ASSIGN(16, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
274  RTEMS_SCHEDULER_ASSIGN(17, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
275  RTEMS_SCHEDULER_ASSIGN(18, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
276  RTEMS_SCHEDULER_ASSIGN(19, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
277  RTEMS_SCHEDULER_ASSIGN(20, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
278  RTEMS_SCHEDULER_ASSIGN(21, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
279  RTEMS_SCHEDULER_ASSIGN(22, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
280  RTEMS_SCHEDULER_ASSIGN(23, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
281  RTEMS_SCHEDULER_ASSIGN(24, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
282  RTEMS_SCHEDULER_ASSIGN(25, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
283  RTEMS_SCHEDULER_ASSIGN(26, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
284  RTEMS_SCHEDULER_ASSIGN(27, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
285  RTEMS_SCHEDULER_ASSIGN(28, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
286  RTEMS_SCHEDULER_ASSIGN(29, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
287  RTEMS_SCHEDULER_ASSIGN(30, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
288  RTEMS_SCHEDULER_ASSIGN(31, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL)
289
290#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
291
292#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
293
294#define CONFIGURE_INIT
295
296#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.