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