1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "tmacros.h" |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/profiling.h> |
---|
23 | |
---|
24 | #define CPU_COUNT 32 |
---|
25 | |
---|
26 | #define WORKER_COUNT (3 * CPU_COUNT) |
---|
27 | |
---|
28 | struct { |
---|
29 | rtems_id sema_prio_inherit; |
---|
30 | rtems_id sema_prio_ceiling; |
---|
31 | } test_context; |
---|
32 | |
---|
33 | static uint32_t simple_random(uint32_t v) |
---|
34 | { |
---|
35 | v *= 1664525; |
---|
36 | v += 1013904223; |
---|
37 | |
---|
38 | return v; |
---|
39 | } |
---|
40 | |
---|
41 | static void worker_task(rtems_task_argument arg) |
---|
42 | { |
---|
43 | uint32_t v = arg; |
---|
44 | |
---|
45 | while (true) { |
---|
46 | rtems_status_code sc; |
---|
47 | rtems_id id; |
---|
48 | |
---|
49 | v = simple_random(v); |
---|
50 | |
---|
51 | if ((v & 0x80000000) != 0) { |
---|
52 | id = test_context.sema_prio_inherit; |
---|
53 | } else { |
---|
54 | id = test_context.sema_prio_ceiling; |
---|
55 | } |
---|
56 | |
---|
57 | sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
58 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
59 | |
---|
60 | sc = rtems_task_wake_after(1); |
---|
61 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
62 | |
---|
63 | sc = rtems_semaphore_release(id); |
---|
64 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | static void test(void) |
---|
69 | { |
---|
70 | uint32_t i; |
---|
71 | rtems_status_code sc; |
---|
72 | rtems_id id; |
---|
73 | |
---|
74 | sc = rtems_semaphore_create( |
---|
75 | rtems_build_name('I', 'N', 'H', 'R'), |
---|
76 | 1, |
---|
77 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY, |
---|
78 | 0, |
---|
79 | &test_context.sema_prio_inherit |
---|
80 | ); |
---|
81 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
82 | |
---|
83 | sc = rtems_semaphore_create( |
---|
84 | rtems_build_name('C', 'E', 'I', 'L'), |
---|
85 | 1, |
---|
86 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING, |
---|
87 | 2, |
---|
88 | &test_context.sema_prio_ceiling |
---|
89 | ); |
---|
90 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
91 | |
---|
92 | for (i = 0; i < WORKER_COUNT; ++i) { |
---|
93 | sc = rtems_task_create( |
---|
94 | rtems_build_name('W', 'O', 'R', 'K'), |
---|
95 | 3 + i, |
---|
96 | RTEMS_MINIMUM_STACK_SIZE, |
---|
97 | RTEMS_DEFAULT_MODES, |
---|
98 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
99 | &id |
---|
100 | ); |
---|
101 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
102 | |
---|
103 | sc = rtems_task_start(id, worker_task, i); |
---|
104 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
105 | } |
---|
106 | |
---|
107 | sc = rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second()); |
---|
108 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
109 | |
---|
110 | rtems_profiling_report_xml("SMPLOAD 1", rtems_printf_plugin, NULL, 1, " "); |
---|
111 | } |
---|
112 | |
---|
113 | static void Init(rtems_task_argument arg) |
---|
114 | { |
---|
115 | puts("\n\n*** TEST SMPLOAD 1 ***"); |
---|
116 | |
---|
117 | test(); |
---|
118 | |
---|
119 | puts("*** END OF TEST SMPLOAD 1 ***"); |
---|
120 | |
---|
121 | rtems_test_exit(0); |
---|
122 | } |
---|
123 | |
---|
124 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
125 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
126 | |
---|
127 | #define CONFIGURE_SMP_APPLICATION |
---|
128 | |
---|
129 | #define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT |
---|
130 | |
---|
131 | #define CONFIGURE_MAXIMUM_TASKS (1 + WORKER_COUNT) |
---|
132 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
133 | |
---|
134 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
135 | |
---|
136 | #define CONFIGURE_INIT |
---|
137 | |
---|
138 | #include <rtems/confdefs.h> |
---|