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