1 | /* |
---|
2 | * COPYRIGHT (c) 2014. |
---|
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 | /* |
---|
11 | * Test to walk the affinity of the init task across all the cores. |
---|
12 | */ |
---|
13 | |
---|
14 | #ifdef HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems.h> |
---|
19 | |
---|
20 | #include "tmacros.h" |
---|
21 | |
---|
22 | const char rtems_test_name[] = "SMPSCHEDAFFINITY 3"; |
---|
23 | |
---|
24 | #define NUM_CPUS 4 |
---|
25 | #define TASK_COUNT NUM_CPUS |
---|
26 | |
---|
27 | static void test_delay(int ticks) |
---|
28 | { |
---|
29 | rtems_interval start, stop; |
---|
30 | start = rtems_clock_get_ticks_since_boot(); |
---|
31 | do { |
---|
32 | stop = rtems_clock_get_ticks_since_boot(); |
---|
33 | } while ( (stop - start) < ticks ); |
---|
34 | } |
---|
35 | |
---|
36 | static void test(void) |
---|
37 | { |
---|
38 | rtems_status_code sc; |
---|
39 | rtems_id id; |
---|
40 | uint32_t cpu_count; |
---|
41 | int cpu; |
---|
42 | int i; |
---|
43 | cpu_set_t cpuset; |
---|
44 | |
---|
45 | /* Get the number of processors that we are using. */ |
---|
46 | cpu_count = rtems_get_processor_count(); |
---|
47 | |
---|
48 | id = rtems_task_self(); |
---|
49 | |
---|
50 | /* |
---|
51 | * The Init task comes up on the maximum core so start at |
---|
52 | * that core and walk the affinity down to core 0. |
---|
53 | */ |
---|
54 | for( i=cpu_count-1; i >= 0; i--) { |
---|
55 | |
---|
56 | /* Move the affinity to the current core - 1 */ |
---|
57 | CPU_ZERO(&cpuset); |
---|
58 | CPU_SET(i, &cpuset); |
---|
59 | printf("Set Affinity for cpu %d\n", i); |
---|
60 | sc = rtems_task_set_affinity( id, sizeof(cpuset), &cpuset ); |
---|
61 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
62 | |
---|
63 | /* Wait 100 clock ticks */ |
---|
64 | test_delay(100); |
---|
65 | |
---|
66 | /* Check the cpu the Init task is running on */ |
---|
67 | cpu = rtems_get_current_processor(); |
---|
68 | printf("On cpu %d\n", cpu); |
---|
69 | rtems_test_assert(cpu == i); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | static void Init(rtems_task_argument arg) |
---|
74 | { |
---|
75 | TEST_BEGIN(); |
---|
76 | |
---|
77 | test(); |
---|
78 | |
---|
79 | TEST_END(); |
---|
80 | rtems_test_exit(0); |
---|
81 | } |
---|
82 | |
---|
83 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
84 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
85 | |
---|
86 | #define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP |
---|
87 | |
---|
88 | #define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS |
---|
89 | |
---|
90 | #define CONFIGURE_MAXIMUM_TASKS TASK_COUNT |
---|
91 | |
---|
92 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
93 | |
---|
94 | #define CONFIGURE_INIT_TASK_PRIORITY 8 |
---|
95 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
96 | |
---|
97 | #define CONFIGURE_INIT |
---|
98 | |
---|
99 | #include <rtems/confdefs.h> |
---|