source: rtems/testsuites/smptests/smp04/init.c @ edde99b

4.115
Last change on this file since edde99b was edde99b, checked in by Sebastian Huber <sebastian.huber@…>, on 06/14/13 at 12:26:34

score: Rename rtems_smp_get_number_of_processors()

Rename in rtems_smp_get_processor_count(). Always provide
<rtems/score/smp.h> and <rtems/rtems/smp.h>. Add
_SMP_Get_processor_count(). This function will be a compile time
constant defined to be one on uni-processor configurations. This allows
iterations over all processors without overhead on uni-processor
configurations.

  • Property mode set to 100644
File size: 3.2 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.com/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17#include <stdio.h>
18
19
20void Loop() {
21  volatile int i;
22
23  for (i=0; i<500000; i++);
24}
25
26rtems_task Test_task(
27  rtems_task_argument task_index
28)
29{
30  int               cpu_num;
31
32  cpu_num = bsp_smp_processor_id();
33  locked_printf("  CPU %d running task TA%" PRIu32 "\n", cpu_num, task_index );
34  Loop();
35  TaskRan[task_index] = true;
36
37  while(1);
38}
39
40rtems_task Init(
41  rtems_task_argument argument
42)
43{
44  int               i;
45  char              ch;
46  rtems_id          id;
47  rtems_status_code status;
48  bool              allDone;
49  int               cpu_num;
50
51  Loop();
52  locked_print_initialize();
53  locked_printf( "\n\n***  SMP04 TEST ***\n" );
54
55  /* Display which cpu is running this init thread. */
56  cpu_num = bsp_smp_processor_id();
57  locked_printf("  CPU %d running task Init\n", cpu_num );
58
59  /* Set all Tasks to not ran except for the init task */
60  TaskRan[0] = true;
61  for ( i=1; i <= rtems_smp_get_processor_count() ; i++ )
62    TaskRan[i] = false;
63 
64
65  /*
66   * For each processor create and start a task alternating
67   * between  RTEMS_PREEMPT and RTEMS_NO_PREEMPT.
68   */
69  for ( i=1; i < rtems_smp_get_processor_count() ; i++ ){
70
71    /* Create and start tasks for each CPU */
72    ch = '0' + i;
73    locked_printf(
74      "Create a TA%c a %s task\n",
75      ch,
76      ((i%2) ? "RTEMS_PREEMPT" : "RTEMS_NO_PREEMPT" )
77    );
78
79    status = rtems_task_create(
80      rtems_build_name( 'T', 'A', ch, ' ' ),
81      CONFIGURE_INIT_TASK_PRIORITY +
82        (2*rtems_smp_get_processor_count()) - (2*i),
83      RTEMS_MINIMUM_STACK_SIZE,
84      ((i%2) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT),
85      RTEMS_DEFAULT_ATTRIBUTES,
86      &id
87    );
88
89    locked_printf(
90      "Start TA%c a %s task\n",
91      ch,
92      ((i%2) ? "RTEMS_PREEMPT" : "RTEMS_NO_PREEMPT" )
93    );
94    status = rtems_task_start( id, Test_task, i );
95
96    /*
97     * Force a wait on the task to run in order to synchronize on
98     * simulated systems.
99     */   
100    while (TaskRan[i] == false)
101      ;
102  }
103
104  /*
105   * Create and start one more task.  This task
106   * should preempt the longest running PREEMPTABLE
107   * task and run on that cpu.
108   */
109  ch = '0' + rtems_smp_get_processor_count() ;
110  locked_printf(
111    "Create a TA%c a %s task\n",
112    ch,
113    "RTEMS_PREEMPT" 
114  );
115  status = rtems_task_create(
116    rtems_build_name( 'T', 'A', ch, ' ' ),
117    3,
118    RTEMS_MINIMUM_STACK_SIZE,
119    RTEMS_PREEMPT,
120    RTEMS_DEFAULT_ATTRIBUTES,
121    &id
122  );
123  locked_printf(
124    "Start TA%c a %s task\n",
125    ch,
126    "RTEMS_PREEMPT"
127  );
128  status = rtems_task_start(
129    id,
130    Test_task,
131    rtems_smp_get_processor_count()
132  );
133 
134  /*
135   * Wait on the all tasks to run
136   */
137  while (1) {
138    allDone = true;
139    for ( i=1; i<=rtems_smp_get_processor_count() ; i++ ) {
140      if (TaskRan[i] == false)
141        allDone = false;
142    }
143    if (allDone) {
144      Loop();
145      locked_printf( "*** END OF TEST SMP04 ***\n" );
146      rtems_test_exit( 0 );
147    }
148  }
149}
Note: See TracBrowser for help on using the repository browser.