source: rtems/testsuites/smptests/smpscheduler01/init.c @ 2d36931

4.11
Last change on this file since 2d36931 was 2d36931, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 11, 2014 at 9:03:25 AM

score: Collect scheduler related fields in TCB

Add Thread_Scheduler_control to collect scheduler related fields of the
TCB.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2013 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 <rtems.h>
20#include <rtems/score/threadimpl.h>
21
22#include "tmacros.h"
23
24const char rtems_test_name[] = "SMPSCHEDULER 1";
25
26#define CPU_COUNT 2
27
28#define TASK_COUNT 4
29
30#define FIRST_TASK_PRIORITY 1
31
32#define SECOND_TASK_READY RTEMS_EVENT_0
33
34static rtems_id task_ids[TASK_COUNT];
35
36static void suspend(size_t i)
37{
38  rtems_status_code sc = rtems_task_suspend(task_ids[i]);
39  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
40}
41
42static void resume(size_t i)
43{
44  rtems_status_code sc = rtems_task_resume(task_ids[i]);
45  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
46}
47
48static void task(rtems_task_argument arg)
49{
50  rtems_task_priority task_priority;
51  rtems_status_code sc;
52
53  sc = rtems_task_set_priority(
54    RTEMS_SELF,
55    RTEMS_CURRENT_PRIORITY,
56    &task_priority
57  );
58  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
59
60  if (arg == 1) {
61    sc = rtems_event_send(task_ids[0], SECOND_TASK_READY);
62    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
63  }
64
65  while (true) {
66    /* Do nothing */
67  }
68}
69
70static bool is_per_cpu_state_ok(void)
71{
72  bool ok = true;
73  uint32_t n = rtems_get_processor_count();
74  uint32_t i;
75
76  for (i = 0; i < n; ++i) {
77    const Thread_Control *thread = _Per_CPU_Get_by_index(i)->executing;
78    uint32_t count = 0;
79    uint32_t j;
80
81    for (j = 0; j < n; ++j) {
82      const Per_CPU_Control *cpu = _Per_CPU_Get_by_index(j);
83      const Thread_Control *executing = cpu->executing;
84      const Thread_Control *heir = cpu->heir;
85
86      if (i != j) {
87        count += executing == thread;
88        count += heir == thread;
89      } else {
90        ++count;
91      }
92
93      ok = ok && _Thread_Get_CPU( executing ) == cpu;
94      ok = ok && _Thread_Get_CPU( heir ) == cpu;
95    }
96
97    ok = ok && (count == 1);
98  }
99
100  return ok;
101}
102
103static void test_scheduler_cross(void)
104{
105  bool per_cpu_state_ok;
106
107  _Thread_Disable_dispatch();
108
109  suspend(0);
110  suspend(1);
111  resume(0);
112  resume(1);
113
114  per_cpu_state_ok = is_per_cpu_state_ok();
115
116  _Thread_Enable_dispatch();
117
118  rtems_test_assert(per_cpu_state_ok);
119}
120
121static void test_scheduler_move_heir(void)
122{
123  bool per_cpu_state_ok;
124
125  _Thread_Disable_dispatch();
126
127  suspend(2);
128  suspend(3);
129  suspend(0);
130  resume(2);
131  suspend(1);
132  resume(3);
133  resume(0);
134
135  per_cpu_state_ok = is_per_cpu_state_ok();
136
137  resume(1);
138
139  _Thread_Enable_dispatch();
140
141  rtems_test_assert(per_cpu_state_ok);
142}
143
144static void test(void)
145{
146  rtems_event_set events;
147  rtems_status_code sc;
148  rtems_task_argument task_index;
149
150  task_ids[0] = rtems_task_self();
151
152  for (task_index = 1; task_index < TASK_COUNT; ++task_index) {
153      rtems_id task_id;
154
155      sc = rtems_task_create(
156        rtems_build_name('T', 'A', 'S', 'K'),
157        FIRST_TASK_PRIORITY + task_index,
158        RTEMS_MINIMUM_STACK_SIZE,
159        RTEMS_DEFAULT_MODES,
160        RTEMS_DEFAULT_ATTRIBUTES,
161        &task_id
162      );
163      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
164
165      sc = rtems_task_start(task_id, task, task_index);
166      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
167
168      task_ids[task_index] = task_id;
169  }
170
171  sc = rtems_event_receive(
172    SECOND_TASK_READY,
173    RTEMS_EVENT_ALL | RTEMS_WAIT,
174    RTEMS_NO_TIMEOUT,
175    &events
176  );
177  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
178  rtems_test_assert(events == SECOND_TASK_READY);
179
180  test_scheduler_cross();
181  test_scheduler_move_heir();
182}
183
184static void Init(rtems_task_argument arg)
185{
186  TEST_BEGIN();
187
188  test();
189
190  TEST_END();
191  rtems_test_exit(0);
192}
193
194#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
195#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
196
197#define CONFIGURE_SMP_APPLICATION
198
199#define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT
200
201#define CONFIGURE_MAXIMUM_TASKS TASK_COUNT
202
203#define CONFIGURE_INIT_TASK_PRIORITY FIRST_TASK_PRIORITY
204#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
205#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
206
207#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
208
209#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
210
211#define CONFIGURE_INIT
212
213#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.