summaryrefslogtreecommitdiffstats
path: root/spec/score/tq/req/surrender-mrsp.yml
blob: fb6b1393e39097e1ddf57fa3a605ef8d0b531fa9 (plain) (blame)
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
functional-type: action
links:
- role: requirement-refinement
  uid: ../if/group
post-conditions:
- name: Dequeue
  states:
  - name: Priority
    test-code: |
      /* Validation is done by spec:/score/tq/req/enqueue-priority */
    text: |
      The first thread in priority order shall be dequeued from the thread
      queue.
  test-epilogue: null
  test-prologue: null
- name: Unblock
  states:
  - name: 'No'
    test-code: |
      T_eq_ptr( GetUnblock( ctx, &i ), NULL );
    text: |
      The dequeued thread shall not be unblocked by the thread queue surrender
      operation.
  test-epilogue: null
  test-prologue: |
    size_t i;

    i = 0;
- name: PreviousOwnerPriority
  states:
  - name: Drop
    test-code: |
      T_eq_u32( ctx->priority_after, PRIO_NORMAL );
    text: |
      Each ${/glossary/priority-eligible:/term} of the previous owner which had
      the highest priority inherited through the thread queue shall be updated.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->priority_after, ctx->priority_before );
    text: |
      No ${/glossary/priority-eligible:/term} of the previous owner shall be
      updated.
  test-epilogue: null
  test-prologue: null
- name: RemoveHelper
  states:
  - name: 'Yes'
    test-code: |
      sc = rtems_task_get_priority(
        ctx->previous_owner,
        SCHEDULER_B_ID,
        &priority
      );
      T_rsc( sc, RTEMS_NOT_DEFINED );
    text: |
      Each ${/glossary/scheduler-helping:/term} of the previous owner which was
      only available due to a priority inherited through the thread queue shall
      be removed from the previous owner.
  - name: 'No'
    test-code: |
      sc = rtems_task_get_priority(
        ctx->previous_owner,
        SCHEDULER_B_ID,
        &priority
      );
      #if defined(RTEMS_SMP)
      T_rsc_success( sc );

      if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) {
        T_eq_u32( priority, PRIO_LOW );
      } else {
        T_eq_u32( priority, PRIO_HIGH );
      }
      #else
      T_rsc( sc, RTEMS_INVALID_ID );
      #endif
    text: |
      No ${/glossary/scheduler-helping:/term} shall be removed from the
      previous owner.
  test-epilogue: null
  test-prologue: |
    rtems_status_code   sc;
    rtems_task_priority priority;
- name: AddHelper
  states:
  - name: 'Yes'
    test-code: |
      sc = rtems_task_get_priority(
        ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ],
        SCHEDULER_A_ID,
        &priority
      );
      T_rsc_success( sc );

      if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) {
        T_eq_u32( priority, PRIO_VERY_HIGH );
      } else {
        T_eq_u32( priority, PRIO_LOW );
      }
    text: |
      Each ${/glossary/scheduler-helping:/term} of the new owner which is only
      available due to a priority inherited through the thread queue shall be
      added to the new owner.
  - name: 'No'
    test-code: |
      sc = rtems_task_get_priority(
        ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ],
        SCHEDULER_A_ID,
        &priority
      );
      #if defined(RTEMS_SMP)
      T_rsc( sc, RTEMS_NOT_DEFINED );
      #else
      T_rsc_success( sc );
      T_eq_u32( priority, PRIO_HIGH );
      #endif
    text: |
      No ${/glossary/scheduler-helping:/term} shall added to the new owner.
  test-epilogue: null
  test-prologue: |
    rtems_status_code   sc;
    rtems_task_priority priority;
- name: Suspended
  states:
  - name: 'Yes'
    test-code: |
      T_true( IsTaskSuspended( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] ) );
    text: |
      The new owner shall be suspended.
  - name: 'No'
    test-code: |
      T_false( IsTaskSuspended( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] ) );
    text: |
      The new owner shall be not suspended.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: InheritedPriority
  states:
  - name: Vital
    test-code: |
      ctx->inherited_priorities_are_dispensible = false;
    text: |
      While at least one priority inherited through the thread queue for the
      previous owner is the highest priority of the previous owner.
  - name: Dispensable
    test-code: |
      ctx->inherited_priorities_are_dispensible = true;
    text: |
      While all priorities inherited through the thread queue for the previous
      owner are not the highest priority of the previous owner.
  test-epilogue: null
  test-prologue: null
- name: PreviousHelping
  states:
  - name: Vital
    test-code: |
      ctx->helping_schedules_are_dispensible = false;
    text: |
      While at least one ${/glossary/scheduler-helping:/term} of the previous
      owner is only available due to a priority inherited through the thread
      queue.
  - name: Dispensable
    test-code: |
      ctx->helping_schedules_are_dispensible = true;
    text: |
      While all ${/glossary/scheduler-helping:/term} of the previous owner are
      not only available due to a priority inherited through the thread queue.
  test-epilogue: null
  test-prologue: null
- name: Scheduler
  states:
  - name: Home
    test-code: |
      ctx->use_helping_scheduler = false;
    text: |
      While the previous owner executes in its
      ${/glossary/scheduler-home:/term}.
  - name: Helping
    test-code: |
      ctx->use_helping_scheduler = true;
    text: |
      While the previous owner executes in a
      ${/glossary/scheduler-helping:/term} which is available due to a priority
      inherited through the thread queue.
  test-epilogue: null
  test-prologue: null
- name: NewHelping
  states:
  - name: Vital
    test-code: |
      ctx->gains_new_helping_scheduler = true;
    text: |
      While at least one ${/glossary/scheduler-helping:/term} of the new owner
      is only available due to a priority inherited through the thread queue.
  - name: Dispensable
    test-code: |
      ctx->gains_new_helping_scheduler = false;
    text: |
      While all ${/glossary/scheduler-helping:/term} of the new owner are not
      only available due to a priority inherited through the thread queue.
  test-epilogue: null
  test-prologue: null
- name: Suspended
  states:
  - name: 'Yes'
    test-code: |
      ctx->suspended = true;
    text: |
      Whiel the new owner is suspended.
  - name: 'No'
    test-code: |
      ctx->suspended = false;
    text: |
      Whiel the new owner is not suspended.
  test-epilogue: null
  test-prologue: null
- name: WaitState
  states:
  - name: IntendToBlock
    test-code: |
      ctx->intend_to_block = true;
    text: |
      While the new owner is in the intend to block wait
      state.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  ctx->previous_owner = ctx->tq_ctx->worker_id[ TQ_HELPER_A ];

  SetSelfPriority( PRIO_LOW );

  if (
    ctx->inherited_priorities_are_dispensible ||
    ctx->helping_schedules_are_dispensible
  ) {
    TQSend( ctx->tq_ctx, TQ_HELPER_A, TQ_EVENT_MUTEX_A_OBTAIN );

    if ( ctx->inherited_priorities_are_dispensible ) {
      TQSend( ctx->tq_ctx, TQ_BLOCKER_B, TQ_EVENT_MUTEX_A_OBTAIN );
    }

    if ( ctx->helping_schedules_are_dispensible ) {
      TQSendAndWaitForExecutionStop(
        ctx->tq_ctx,
        TQ_BLOCKER_C,
        TQ_EVENT_MUTEX_A_OBTAIN
      );
    }
  }

  /*
   * Take only the priorities into account which are inherited from the
   * priority inheritance mutex.  This avoids having to deal with the ceiling
   * priority.
   */
  ctx->priority_before = TQGetPriority( ctx->tq_ctx, TQ_HELPER_A );

  SetSelfScheduler( SCHEDULER_B_ID, PRIO_ULTRA_HIGH );
  ctx->tq_ctx->busy_wait[ TQ_HELPER_A ] = true;
  TQSendAndSynchronizeRunner(
    ctx->tq_ctx,
    TQ_HELPER_A,
    TQ_EVENT_ENQUEUE | TQ_EVENT_BUSY_WAIT
  );
  SetSelfScheduler( SCHEDULER_A_ID, PRIO_ULTRA_HIGH );

  TQSendAndWaitForIntendToBlock(
    ctx->tq_ctx,
    TQ_BLOCKER_A,
    TQ_EVENT_ENQUEUE
  );

  SetSelfScheduler( SCHEDULER_B_ID, PRIO_ULTRA_HIGH );

  if ( ctx->gains_new_helping_scheduler ) {
    TQSend(
      ctx->tq_ctx,
      TQ_BLOCKER_D,
      TQ_EVENT_ENQUEUE
    );
    YieldTask( ctx->tq_ctx->worker_id[ TQ_HELPER_A ] );
    TQWaitForEventsReceived( ctx->tq_ctx, TQ_BLOCKER_D );
    TQWaitForIntendToBlock( ctx->tq_ctx, TQ_BLOCKER_D );
    YieldTask( ctx->tq_ctx->worker_id[ TQ_BLOCKER_D ] );
  }

  if ( ctx->use_helping_scheduler ) {
    SetSelfScheduler( SCHEDULER_A_ID, PRIO_ULTRA_HIGH );
    WaitForHeir( 1, ctx->tq_ctx->worker_id[ TQ_HELPER_A ] );
  }

  if ( ctx->suspended ) {
    SuspendTask( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] );
  }

  ctx->tq_ctx->busy_wait[ TQ_HELPER_A ] = false;
  TQSendAndWaitForExecutionStop(
    ctx->tq_ctx,
    TQ_HELPER_A,
    TQ_EVENT_SCHEDULER_RECORD_START |
      TQ_EVENT_SURRENDER
  );
  TQSchedulerRecordStop( ctx->tq_ctx );
  T_eq_ptr(
    TQGetOwner( ctx->tq_ctx ),
    ctx->tq_ctx->worker_tcb[ TQ_BLOCKER_A ]
  );
  ctx->priority_after = TQGetPriority( ctx->tq_ctx, TQ_HELPER_A );
test-brief: null
test-cleanup: |
  SetSelfScheduler( SCHEDULER_A_ID, PRIO_ULTRA_HIGH );

  if ( ctx->suspended ) {
    ResumeTask( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] );
  }

  TQSendAndSynchronizeRunner(
    ctx->tq_ctx,
    TQ_BLOCKER_A,
    TQ_EVENT_SURRENDER
  );

  if ( ctx->gains_new_helping_scheduler ) {
    TQSendAndSynchronizeRunner(
      ctx->tq_ctx,
      TQ_BLOCKER_D,
      TQ_EVENT_SURRENDER
    );
  }

  if (
    ctx->inherited_priorities_are_dispensible ||
    ctx->helping_schedules_are_dispensible
  ) {
    TQSendAndSynchronizeRunner(
      ctx->tq_ctx,
      TQ_HELPER_A,
      TQ_EVENT_MUTEX_A_RELEASE
    );

    if ( ctx->inherited_priorities_are_dispensible ) {
      TQSendAndSynchronizeRunner(
        ctx->tq_ctx,
        TQ_BLOCKER_B,
        TQ_EVENT_MUTEX_A_RELEASE
      );
    }

    if ( ctx->helping_schedules_are_dispensible ) {
      TQSendAndSynchronizeRunner(
        ctx->tq_ctx,
        TQ_BLOCKER_C,
        TQ_EVENT_MUTEX_A_RELEASE
      );
    }
  }

  T_eq_u32( rtems_scheduler_get_processor(), 0 );
test-context:
- brief: |
    If this member is true, then all priorities of the previous owner inherited
    from the thread queue thread shall be dispensable.
  description: null
  member: |
    bool inherited_priorities_are_dispensible
- brief: |
    If this member is true, then all helping schedulers of the previous owner
    thread gained through the thread queue shall be dispensable.
  description: null
  member: |
    bool helping_schedules_are_dispensible
- brief: |
    If this member is true, then the previous owner thread shall use helping
    scheduler.
  description: null
  member: |
    bool use_helping_scheduler
- brief: |
    If this member is true, then the new owner thread shall gain a vital
    helping scheduler.
  description: null
  member: |
    bool gains_new_helping_scheduler
- brief: |
    If this member is true, then the new owner thread shall be suspended.
  description: null
  member: |
    bool suspended
- brief: |
    If this member is true, then the new owner thread shall be in the intend to
    block wait state.
  description: null
  member: |
    bool intend_to_block
- brief: |
    This member contains the current priority of the previous owner thread
    before the thread queue surrender operation.
  description: null
  member: |
    rtems_task_priority priority_before
- brief: |
    This member contains the current priority of the previous owner thread
    after the thread queue surrender operation.
  description: null
  member: |
    rtems_task_priority priority_after
- brief: |
    This member contains the identifier of the previous owner thread.
  description: null
  member: |
    rtems_id previous_owner
test-context-support: null
test-description: null
test-header:
  code: null
  freestanding: false
  includes: []
  local-includes:
  - tx-thread-queue.h
  run-params:
  - description: |
      is the thread queue test context.
    dir: inout
    name: tq_ctx
    specifier: TQContext *${.:name}
  target: testsuites/validation/tr-tq-surrender-mrsp.h
test-includes:
- rtems/score/threadimpl.h
test-local-includes:
- tx-support.h
- tr-tq-surrender-mrsp.h
test-prepare: |
  ctx->inherited_priorities_are_dispensible = true;
  ctx->helping_schedules_are_dispensible = true;
  ctx->use_helping_scheduler = false;
  ctx->gains_new_helping_scheduler = false;
  ctx->intend_to_block = false;
test-setup:
  brief: null
  code: |
    TQReset( ctx->tq_ctx );
    TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_A, SCHEDULER_B_ID, PRIO_NORMAL );
    TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_B, PRIO_VERY_HIGH );
    TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_C, SCHEDULER_B_ID, PRIO_LOW );
    TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_D, PRIO_VERY_HIGH );
    TQSetPriority( ctx->tq_ctx, TQ_HELPER_A, PRIO_NORMAL );
  description: null
test-stop: null
test-support: |
  typedef ${.:/test-context-type} Context;

  static const rtems_tcb *GetUnblock( Context *ctx, size_t *index )
  {
    return TQGetNextUnblock( ctx->tq_ctx, index )->thread;
  }
test-target: testsuites/validation/tr-tq-surrender-mrsp.c
test-teardown:
  brief: null
  code: |
    SetSelfScheduler( SCHEDULER_A_ID, PRIO_NORMAL );
  description: null
text: |
  When the thread queue is surrendered.
transition-map:
- enabled-by: true
  post-conditions:
    Dequeue: Priority
    Unblock: 'No'
    RemoveHelper:
    - if:
        pre-conditions:
          PreviousHelping: Dispensable
      then: 'No'
    - else: 'Yes'
    AddHelper:
    - if:
        pre-conditions:
          NewHelping: Dispensable
      then: 'No'
    - else: 'Yes'
    PreviousOwnerPriority:
    - if:
        pre-conditions:
          InheritedPriority: Vital
      then: Drop
    - else: Nop
    Suspended:
    - specified-by: Suspended
  pre-conditions:
    InheritedPriority: all
    PreviousHelping: all
    Scheduler: all
    NewHelping: all
    Suspended: all
    WaitState: all
type: requirement