1 | /* |
---|
2 | * Copyright (c) 2017 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.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include <rtems/cpuuse.h> |
---|
21 | #include <rtems/printer.h> |
---|
22 | |
---|
23 | #include "tmacros.h" |
---|
24 | |
---|
25 | const char rtems_test_name[] = "SMPSCHEDEDF 1"; |
---|
26 | |
---|
27 | typedef struct { |
---|
28 | uint_fast32_t one_tick_busy; |
---|
29 | rtems_id task[2]; |
---|
30 | } test_context; |
---|
31 | |
---|
32 | static test_context test_instance; |
---|
33 | |
---|
34 | static void t(test_context *ctx, rtems_interval p, uint_fast32_t c) |
---|
35 | { |
---|
36 | rtems_status_code sc; |
---|
37 | rtems_id period; |
---|
38 | rtems_name name; |
---|
39 | uint_fast32_t busy; |
---|
40 | |
---|
41 | sc = rtems_object_get_classic_name(rtems_task_self(), &name); |
---|
42 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
43 | |
---|
44 | sc = rtems_rate_monotonic_create(name, &period); |
---|
45 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
46 | |
---|
47 | busy = (c - 1) * ctx->one_tick_busy + (4 * ctx->one_tick_busy) / 5; |
---|
48 | |
---|
49 | while (true) { |
---|
50 | rtems_test_busy(busy); |
---|
51 | |
---|
52 | sc = rtems_rate_monotonic_period(period, p); |
---|
53 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | static void t1(rtems_task_argument arg) |
---|
58 | { |
---|
59 | test_context *ctx = (test_context *) arg; |
---|
60 | |
---|
61 | t(ctx, 50, 25); |
---|
62 | } |
---|
63 | |
---|
64 | static void t2(rtems_task_argument arg) |
---|
65 | { |
---|
66 | test_context *ctx = (test_context *) arg; |
---|
67 | |
---|
68 | t(ctx, 75, 30); |
---|
69 | } |
---|
70 | |
---|
71 | static void test(test_context *ctx) |
---|
72 | { |
---|
73 | rtems_status_code sc; |
---|
74 | rtems_printer printer; |
---|
75 | |
---|
76 | ctx->one_tick_busy = rtems_test_get_one_tick_busy_count(); |
---|
77 | |
---|
78 | sc = rtems_task_create( |
---|
79 | rtems_build_name('T', '1', ' ', ' '), |
---|
80 | 2, |
---|
81 | RTEMS_MINIMUM_STACK_SIZE, |
---|
82 | RTEMS_DEFAULT_MODES, |
---|
83 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
84 | &ctx->task[0] |
---|
85 | ); |
---|
86 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
87 | |
---|
88 | sc = rtems_task_create( |
---|
89 | rtems_build_name('T', '2', ' ', ' '), |
---|
90 | 2, |
---|
91 | RTEMS_MINIMUM_STACK_SIZE, |
---|
92 | RTEMS_DEFAULT_MODES, |
---|
93 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
94 | &ctx->task[1] |
---|
95 | ); |
---|
96 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
97 | |
---|
98 | sc = rtems_task_wake_after(1); |
---|
99 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
100 | |
---|
101 | sc = rtems_task_start(ctx->task[0], t1, (rtems_task_argument) ctx); |
---|
102 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
103 | |
---|
104 | sc = rtems_task_start(ctx->task[1], t2, (rtems_task_argument) ctx); |
---|
105 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
106 | |
---|
107 | rtems_cpu_usage_reset(); |
---|
108 | |
---|
109 | sc = rtems_task_wake_after(50 * 75); |
---|
110 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
111 | |
---|
112 | sc = rtems_task_suspend(ctx->task[0]); |
---|
113 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
114 | |
---|
115 | sc = rtems_task_suspend(ctx->task[1]); |
---|
116 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
117 | |
---|
118 | rtems_print_printer_printf(&printer); |
---|
119 | rtems_cpu_usage_report_with_plugin(&printer); |
---|
120 | rtems_rate_monotonic_report_statistics_with_plugin(&printer); |
---|
121 | } |
---|
122 | |
---|
123 | static void Init(rtems_task_argument arg) |
---|
124 | { |
---|
125 | test_context *ctx = &test_instance; |
---|
126 | |
---|
127 | TEST_BEGIN(); |
---|
128 | |
---|
129 | test(ctx); |
---|
130 | |
---|
131 | TEST_END(); |
---|
132 | rtems_test_exit(0); |
---|
133 | } |
---|
134 | |
---|
135 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
136 | |
---|
137 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
138 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
139 | |
---|
140 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
141 | #define CONFIGURE_MAXIMUM_PERIODS 2 |
---|
142 | |
---|
143 | #define CONFIGURE_MAXIMUM_PROCESSORS 1 |
---|
144 | |
---|
145 | #define CONFIGURE_SCHEDULER_EDF_SMP |
---|
146 | |
---|
147 | #include <rtems/scheduler.h> |
---|
148 | |
---|
149 | RTEMS_SCHEDULER_CONTEXT_EDF_SMP(a, CONFIGURE_MAXIMUM_PROCESSORS); |
---|
150 | |
---|
151 | #define CONFIGURE_SCHEDULER_CONTROLS \ |
---|
152 | RTEMS_SCHEDULER_CONTROL_EDF_SMP(a, rtems_build_name('E', 'D', 'F', ' ')) |
---|
153 | |
---|
154 | #define CONFIGURE_SMP_SCHEDULER_ASSIGNMENTS \ |
---|
155 | RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY) |
---|
156 | |
---|
157 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
158 | |
---|
159 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
160 | |
---|
161 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
162 | |
---|
163 | #define CONFIGURE_INIT |
---|
164 | |
---|
165 | #include <rtems/confdefs.h> |
---|