1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH & Co. KG
enabled-by: true
functional-type: action
links:
- role: requirement-refinement
uid: group
post-conditions:
- name: HomeSchedulerState
states:
- name: Blocked
test-code: |
T_true( ctx->is_idle_after_yield );
T_eq_u32( ctx->cpu_after_yield, 1 );
text: |
The thread shall be blocked in its ${/glossary/scheduler-home:/term}.
- name: Scheduled
test-code: |
T_false( ctx->is_idle_before_yield );
T_false( ctx->is_idle_after_yield );
T_eq_u32( GetCounter( ctx ), 0 );
T_eq_u32( ctx->cpu_after_yield, 0 );
text: |
The thread shall be scheduled in its ${/glossary/scheduler-home:/term}.
- name: Ready
test-code: |
T_eq_u32( GetCounter( ctx ), 1 );
text: |
The thread shall be ready in its ${/glossary/scheduler-home:/term}.
- name: Idle
test-code: |
T_true( ctx->is_idle_before_yield );
T_true( ctx->is_idle_after_yield );
T_eq_u32( GetCounter( ctx ), 0 );
T_eq_u32( ctx->cpu_after_yield, 1 );
text: |
An idle thread shall execute on behalf of the thread in its
${/glossary/scheduler-home:/term}.
test-epilogue: null
test-prologue: null
- name: AskForHelp
states:
- name: 'Yes'
test-code: |
event = TQGetNextAskForHelp( &ctx->tq_ctx, &index );
T_eq_ptr( event->thread, ctx->tq_ctx.runner_tcb );
event = TQGetNextAskForHelp( &ctx->tq_ctx, &index );
T_eq_ptr( event->thread, ctx->tq_ctx.runner_tcb );
event = TQGetNextAskForHelp( &ctx->tq_ctx, &index );
T_eq_ptr( event, &T_scheduler_event_null );
text: |
The thread shall ask all its ${/glossary/scheduler-eligible:/term} for
help.
- name: 'No'
test-code: |
event = TQGetNextAskForHelp( &ctx->tq_ctx, &index );
T_eq_ptr( event, &T_scheduler_event_null );
text: |
The thread shall not ask for help.
test-epilogue: null
test-prologue: |
size_t index;
const T_scheduler_event *event;
index = 0;
pre-conditions:
- name: EligibleScheduler
states:
- name: Home
test-code: |
ctx->has_helping = false;
text: |
While the only ${/glossary/scheduler-eligible:/term} of the thread is the
${/glossary/scheduler-home:/term}.
- name: Helping
test-code: |
ctx->has_helping = true;
text: |
While the thread has at least one ${/glossary/scheduler-helping:/term}.
test-epilogue: null
test-prologue: null
- name: UsedScheduler
states:
- name: Home
test-code: |
ctx->use_helping = false;
text: |
While the thread is scheduled on the ${/glossary/scheduler-home:/term}.
- name: Helping
test-code: |
ctx->use_helping = true;
text: |
While the thread is scheduled on a ${/glossary/scheduler-helping:/term}.
test-epilogue: null
test-prologue: null
- name: HomeSchedulerState
states:
- name: Blocked
test-code: |
ctx->ready = false;
text: |
The thread shall be blocked in its ${/glossary/scheduler-home:/term}.
- name: Scheduled
test-code: |
ctx->ready = false;
text: |
The thread shall be scheduled in its ${/glossary/scheduler-home:/term}.
- name: Ready
test-code: |
ctx->ready = true;
text: |
The thread shall be ready in its ${/glossary/scheduler-home:/term}.
test-epilogue: null
test-prologue: null
- name: Sticky
states:
- name: 'Yes'
test-code: |
ctx->sticky = true;
text: |
While the thread is sticky.
- name: 'No'
test-code: |
ctx->sticky = false;
text: |
While the thread not sticky.
test-epilogue: null
test-prologue: null
- name: Other
states:
- name: 'Yes'
test-code: |
ctx->other_ready = true;
text: |
While at least one ready thread with a priority equal to the priority of
the thread exists in the ${/glossary/scheduler-home:/term} of the thread.
- name: 'No'
test-code: |
ctx->other_ready = false;
text: |
While no ready thread with a priority equal to the priority of the thread
exists in the ${/glossary/scheduler-home:/term} of the thread.
test-epilogue: null
test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons:
HelpingNeedsHelping: |
In order to use a helping scheduler a thread needs a helping scheduler.
HelpingNeedsSMP: |
A helping scheduler is only available where the system was built with SMP
support enabled.
StickyNeedsSMP: |
A thread may be sticky only where the system was built with SMP support
enabled.
Sticky: |
Sticky threads are never blocked in their home scheduler. Only sticky
threads may be scheduled on two schedulers at the same time.
HomeNeedsScheduled: |
While a thread uses its home scheduler, it is scheduled in the home scheduler.
test-action: |
const Per_CPU_Control *cpu;
bool other_busy;
if ( ctx->has_helping ) {
TQMutexObtain( &ctx->tq_ctx, TQ_MUTEX_A );
TQSendAndWaitForExecutionStop(
&ctx->tq_ctx,
HELPER,
TQ_EVENT_MUTEX_A_OBTAIN
);
}
if ( ctx->use_helping ) {
MoveToHelping( ctx );
}
TQResetCounter( &ctx->tq_ctx );
if ( ctx->use_helping && ctx->ready ) {
ctx->tq_ctx.busy_wait[ COUNTER ] = true;
TQSend( &ctx->tq_ctx, COUNTER, TQ_EVENT_COUNT | TQ_EVENT_BUSY_WAIT );
other_busy = true;
} else {
other_busy = false;
}
if ( ctx->sticky ) {
ObtainMutex( ctx->sticky_mutex );
}
if ( ctx->other_ready && !other_busy ) {
TQSend( &ctx->tq_ctx, COUNTER, TQ_EVENT_COUNT );
}
cpu = _Per_CPU_Get_by_index( 0 );
ctx->is_idle_before_yield = cpu->heir->is_idle;
TQSchedulerRecordStart( &ctx->tq_ctx );
Yield();
TQSchedulerRecordStop( &ctx->tq_ctx );
#if defined(RTEMS_SMP)
ctx->tq_ctx.busy_wait[ COUNTER ] = false;
while ( cpu->heir == ctx->tq_ctx.worker_tcb[ COUNTER ] ) {
RTEMS_COMPILER_MEMORY_BARRIER();
}
#endif
ctx->is_idle_after_yield = cpu->heir->is_idle;
ctx->cpu_after_yield = rtems_scheduler_get_processor();
if ( ctx->sticky ) {
ReleaseMutex( ctx->sticky_mutex );
}
if ( ctx->has_helping ) {
TQMutexRelease( &ctx->tq_ctx, TQ_MUTEX_A );
TQSendAndWaitForExecutionStop(
&ctx->tq_ctx,
HELPER,
TQ_EVENT_MUTEX_A_RELEASE
);
}
test-brief: null
test-cleanup: null
test-context:
- brief: |
This member contains the thread queue test context.
description: null
member: |
TQContext tq_ctx
- brief: |
This member contains the identifier of a sticky mutex.
description: null
member: |
rtems_id sticky_mutex
- brief: |
This member contains the processor index after yielding.
description: null
member: |
uint32_t cpu_after_yield
- brief: |
If this member is true, then the runner shall have a helping scheduler.
description: null
member: |
bool has_helping
- brief: |
If this member is true, then the runner shall use a helping scheduler.
description: null
member: |
bool use_helping
- brief: |
If this member is true, then the runner shall be ready in its home
scheduler.
description: null
member: |
bool ready
- brief: |
If this member is true, then the runner shall be sticky.
description: null
member: |
bool sticky
- brief: |
If this member is true, then another ready task in the home scheduler of
the runner shall be ready with an equal priority.
description: null
member: |
bool other_ready
- brief: |
If this member is true, then the processor zero was idle before yielding.
description: null
member: |
bool is_idle_before_yield
- brief: |
If this member is true, then the processor zero was idle after yielding.
description: null
member: |
bool is_idle_after_yield
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
- rtems/test-scheduler.h
- rtems/score/percpu.h
test-local-includes:
- tx-support.h
- tx-thread-queue.h
test-prepare: null
test-setup:
brief: null
code: |
rtems_status_code sc;
memset( ctx, 0, sizeof( *ctx ) );
ctx->tq_ctx.enqueue_prepare = TQEnqueuePrepareDefault;
ctx->tq_ctx.enqueue_done = TQEnqueueDoneDefault;
ctx->tq_ctx.enqueue = TQEnqueueClassicSem;
ctx->tq_ctx.surrender = TQSurrenderClassicSem;
ctx->tq_ctx.convert_status = TQConvertStatusClassic;
TQInitialize( &ctx->tq_ctx );
sc = rtems_semaphore_create(
rtems_build_name( 'M', 'U', 'T', 'X' ),
1,
RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
RTEMS_MULTIPROCESSOR_RESOURCE_SHARING,
PRIO_NORMAL,
&ctx->sticky_mutex
);
T_rsc_success( sc );
TQSetPriority( &ctx->tq_ctx, COUNTER, PRIO_NORMAL );
#if defined(RTEMS_SMP)
TQSetScheduler( &ctx->tq_ctx, HELPER, SCHEDULER_B_ID, PRIO_NORMAL );
TQSetPriority( &ctx->tq_ctx, MOVER, PRIO_HIGH );
#endif
description: null
test-stop: null
test-support: |
#define COUNTER TQ_BLOCKER_A
#define HELPER TQ_BLOCKER_B
#define MOVER TQ_BLOCKER_C
typedef ${.:/test-context-type} Context;
static void MoveToHelping( Context *ctx )
{
ctx->tq_ctx.busy_wait[ MOVER ] = true;
TQSend( &ctx->tq_ctx, MOVER, TQ_EVENT_BUSY_WAIT );
TQWaitForEventsReceived( &ctx->tq_ctx, MOVER );
T_eq_u32( rtems_scheduler_get_processor(), 1 );
ctx->tq_ctx.busy_wait[ MOVER ] = false;
TQWaitForExecutionStop( &ctx->tq_ctx, MOVER );
}
static uint32_t GetCounter( const Context *ctx )
{
return TQGetWorkerCounter( &ctx->tq_ctx, COUNTER );
}
test-target: testsuites/validation/tc-sched-yield.c
test-teardown:
brief: null
code: |
TQDestroy( &ctx->tq_ctx );
DeleteMutex( ctx->sticky_mutex );
description: null
text: |
When the thread yields.
transition-map:
- enabled-by: true
post-conditions:
HomeSchedulerState:
- if:
pre-conditions:
UsedScheduler: Home
HomeSchedulerState: Scheduled
Other: 'No'
then: Scheduled
- if:
pre-conditions:
UsedScheduler: Home
HomeSchedulerState: Scheduled
Other: 'Yes'
then: Ready
- if:
pre-conditions:
EligibleScheduler: Helping
UsedScheduler: Helping
HomeSchedulerState: Scheduled
Sticky: 'Yes'
Other: 'No'
then: Idle
- if:
pre-conditions:
EligibleScheduler: Helping
UsedScheduler: Helping
HomeSchedulerState: Scheduled
Sticky: 'Yes'
Other: 'Yes'
then: Ready
- if:
pre-conditions:
EligibleScheduler: Helping
UsedScheduler: Helping
HomeSchedulerState: Blocked
Sticky: 'No'
then: Blocked
- else: Ready
AskForHelp:
- if:
pre-conditions:
EligibleScheduler: Helping
UsedScheduler: Home
HomeSchedulerState: Scheduled
Other: 'Yes'
then: 'Yes'
- else: 'No'
pre-conditions:
EligibleScheduler: all
UsedScheduler: all
HomeSchedulerState: all
Sticky: all
Other: all
- enabled-by: true
post-conditions: HelpingNeedsHelping
pre-conditions:
EligibleScheduler:
- Home
UsedScheduler:
- Helping
HomeSchedulerState: all
Sticky: all
Other: all
- enabled-by:
not: RTEMS_SMP
post-conditions: HelpingNeedsSMP
pre-conditions:
EligibleScheduler:
- Helping
UsedScheduler: all
HomeSchedulerState: all
Sticky: all
Other: all
- enabled-by:
not: RTEMS_SMP
post-conditions: StickyNeedsSMP
pre-conditions:
EligibleScheduler: all
UsedScheduler: all
HomeSchedulerState: all
Sticky:
- 'Yes'
Other: all
- enabled-by: true
post-conditions: Sticky
pre-conditions:
EligibleScheduler:
- Helping
UsedScheduler:
- Helping
HomeSchedulerState:
- Scheduled
- Ready
Sticky:
- 'No'
Other: all
- enabled-by: true
post-conditions: Sticky
pre-conditions:
EligibleScheduler: all
UsedScheduler: all
HomeSchedulerState:
- Blocked
Sticky:
- 'Yes'
Other: all
- enabled-by: true
post-conditions: HomeNeedsScheduled
pre-conditions:
EligibleScheduler: all
UsedScheduler:
- Home
HomeSchedulerState:
- Blocked
- Ready
Sticky: all
Other: all
type: requirement
|