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

5
Last change on this file since 03c9f24 was 03c9f24, checked in by Sebastian Huber <sebastian.huber@…>, on 04/05/19 at 06:03:12

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: 4.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
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#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include "test_support.h"
16
17const char rtems_test_name[] = "SMP 7";
18
19volatile bool TaskRan = false;
20volatile bool TSRFired = false;
21rtems_id      Semaphore;
22
23rtems_task Init(
24  rtems_task_argument argument
25);
26
27rtems_task Test_task(
28  rtems_task_argument argument
29);
30
31static void success(void)
32{
33  TEST_END( );
34  rtems_test_exit( 0 );
35}
36
37rtems_task Test_task(
38  rtems_task_argument argument
39)
40{
41  uint32_t          cpu_num;
42  rtems_status_code sc;
43  char              name[5];
44  char             *p;
45
46  /* Get the task name */
47  p = rtems_object_get_name( RTEMS_SELF, 5, name );
48  rtems_test_assert( p != NULL );
49
50   /* Get the CPU Number */
51  cpu_num = rtems_scheduler_get_processor();
52
53  /* Print that the task is up and running. */
54  locked_printf(" CPU %" PRIu32 " runnng Task %s and blocking\n", cpu_num, name);
55
56  sc = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
57  directive_failed( sc,"obtain in test task");
58
59  if ( !TSRFired )
60    locked_printf( "*** ERROR TSR DID NOT FIRE BUT TEST TASK AWAKE***" );
61
62  TaskRan = true;
63
64  /* Print that the task is up and running. */
65  locked_printf(
66    " CPU %" PRIu32 " running Task %s after semaphore release\n",
67    cpu_num,
68    name
69  );
70
71  rtems_task_exit();
72}
73
74
75static rtems_timer_service_routine TimerMethod(
76  rtems_id  timer,
77  void     *arg
78)
79{
80  /*
81   * Set flag and release the semaphore, allowing the blocked tasks to start.
82   */
83  TSRFired = true;
84
85  rtems_semaphore_release( Semaphore );
86}
87
88rtems_task Init(
89  rtems_task_argument argument
90)
91{
92  int                cpu_num;
93  rtems_id           id;
94  rtems_status_code  status;
95  rtems_interval     per_second;
96  rtems_interval     then;
97  rtems_id           Timer;
98
99  locked_print_initialize();
100  TEST_BEGIN();
101
102  if ( rtems_get_processor_count() == 1 ) {
103    success();
104  }
105
106  /* Create/verify semaphore */
107  status = rtems_semaphore_create(
108    rtems_build_name ('S', 'E', 'M', '1'),
109    1,
110    RTEMS_LOCAL                   |
111    RTEMS_SIMPLE_BINARY_SEMAPHORE |
112    RTEMS_PRIORITY,
113    1,
114    &Semaphore
115  );
116  directive_failed( status, "rtems_semaphore_create" );
117
118  /* Lock semaphore */
119  status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
120  directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
121
122  /* Create and Start test task. */
123  status = rtems_task_create(
124    rtems_build_name( 'T', 'A', '1', ' ' ),
125    1,
126    RTEMS_MINIMUM_STACK_SIZE,
127    RTEMS_DEFAULT_MODES,
128    RTEMS_DEFAULT_ATTRIBUTES,
129    &id
130  );
131  directive_failed( status, "task create" );
132
133  cpu_num = rtems_scheduler_get_processor();
134  locked_printf(" CPU %d start task TA1\n", cpu_num );
135  status = rtems_task_start( id, Test_task, 1 );
136  directive_failed( status, "task start" );
137
138  /* Create and start TSR */
139  locked_printf(" CPU %d create and start timer\n", cpu_num );
140  status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer);
141  directive_failed( status, "rtems_timer_create" );
142
143  per_second = rtems_clock_get_ticks_per_second();
144  status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL );
145  directive_failed( status, "rtems_timer_fire_after");
146
147  /*
148   *  Wait long enough that TSR should have fired.
149   *
150   *  Spin so CPU 0 is consumed.  This forces task to run on CPU 1.
151   */
152  then = rtems_clock_get_ticks_since_boot() + 4 * per_second;
153  while (1) {
154    if ( rtems_clock_get_ticks_since_boot() > then )
155      break;
156    if ( TSRFired && TaskRan )
157      break;
158  };
159
160  /* Validate the timer fired and that the task ran */
161  if ( !TSRFired )
162    locked_printf( "*** ERROR TSR DID NOT FIRE ***" );
163
164  if ( !TaskRan ) {
165    locked_printf( "*** ERROR TASK DID NOT RUN ***" );
166    rtems_test_exit(0);
167  }
168
169  /* End the program */
170  success();
171}
172
173/* configuration information */
174
175#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
176#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
177
178#define CONFIGURE_MAXIMUM_PROCESSORS   2
179#define CONFIGURE_MAXIMUM_TIMERS           1
180
181#define CONFIGURE_MAXIMUM_TASKS            2
182#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
183
184#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
185#define CONFIGURE_MAXIMUM_SEMAPHORES       2
186
187#define CONFIGURE_INIT
188
189#include <rtems/confdefs.h>
190/* end of file */
Note: See TracBrowser for help on using the repository browser.