source: rtems/testsuites/sptests/spintrcritical23/init.c @ b679b492

5
Last change on this file since b679b492 was 9bfad8c, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/16 at 20:22:46

score: Add thread priority to scheduler nodes

The thread priority is manifest in two independent areas. One area is
the user visible thread priority along with a potential thread queue.
The other is the scheduler. Currently, a thread priority update via
_Thread_Change_priority() first updates the user visble thread priority
and the thread queue, then the scheduler is notified if necessary. The
priority is passed to the scheduler via a local variable. A generation
counter ensures that the scheduler discards out-of-date priorities.

This use of a local variable ties the update in these two areas close
together. For later enhancements and the OMIP locking protocol
implementation we need more flexibility. Add a thread priority
information block to Scheduler_Node and synchronize priority value
updates via a sequence lock on SMP configurations.

Update #2556.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2015, 2016 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 <tmacros.h>
20#include <intrcritical.h>
21
22#include <string.h>
23
24#include <rtems.h>
25#include <rtems/score/schedulerpriorityimpl.h>
26#include <rtems/score/threadimpl.h>
27
28const char rtems_test_name[] = "SPINTRCRITICAL 23";
29
30typedef struct {
31  RTEMS_INTERRUPT_LOCK_MEMBER(lock)
32  rtems_id task_id;
33  Scheduler_priority_Node *scheduler_node;
34  rtems_task_priority priority_task;
35  rtems_task_priority priority_interrupt;
36  bool done;
37} test_context;
38
39static test_context ctx_instance;
40
41static void change_priority(rtems_id timer, void *arg)
42{
43  /* The arg is NULL */
44  test_context *ctx = &ctx_instance;
45  rtems_interrupt_lock_context lock_context;
46
47  rtems_interrupt_lock_acquire(&ctx->lock, &lock_context);
48  if (
49    ctx->scheduler_node->Ready_queue.current_priority
50      != ctx->scheduler_node->Base.Priority.value
51  ) {
52    rtems_task_priority priority_interrupt;
53    rtems_task_priority priority_task;
54    rtems_task_priority previous;
55    rtems_status_code sc;
56
57    priority_interrupt = ctx->priority_interrupt;
58    priority_task = ctx->priority_task;
59
60    rtems_interrupt_lock_release(&ctx->lock, &lock_context);
61
62    sc = rtems_task_set_priority(
63      ctx->task_id,
64      priority_interrupt,
65      &previous
66    );
67    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
68    rtems_test_assert(previous == priority_task);
69
70    ctx->done = true;
71  } else {
72    rtems_interrupt_lock_release(&ctx->lock, &lock_context);
73  }
74}
75
76static bool test_body(void *arg)
77{
78  test_context *ctx = arg;
79  rtems_status_code sc;
80  rtems_interrupt_lock_context lock_context;
81  rtems_task_priority priority_last;
82  rtems_task_priority priority_task;
83  rtems_task_priority priority_interrupt;
84  rtems_task_priority previous;
85
86  rtems_interrupt_lock_acquire(&ctx->lock, &lock_context);
87  priority_last = ctx->priority_task;
88  priority_task = 1 + (priority_last + 1) % 3;
89  priority_interrupt = 1 + (priority_task + 1) % 3;
90  ctx->priority_task = priority_task;
91  ctx->priority_interrupt = priority_interrupt;
92  rtems_interrupt_lock_release(&ctx->lock, &lock_context);
93
94  sc = rtems_task_set_priority(
95    ctx->task_id,
96    priority_task,
97    &previous
98  );
99  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
100  rtems_test_assert(previous == priority_last);
101
102  if (ctx->done) {
103    sc = rtems_task_set_priority(
104      ctx->task_id,
105      RTEMS_CURRENT_PRIORITY,
106      &previous
107    );
108    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
109    rtems_test_assert(previous == priority_interrupt);
110  }
111
112  return ctx->done;
113}
114
115static void Init(rtems_task_argument arg)
116{
117  test_context *ctx = &ctx_instance;
118
119  TEST_BEGIN();
120
121  rtems_interrupt_lock_initialize(&ctx->lock, "Test");
122  ctx->priority_task = 1;
123  ctx->task_id = rtems_task_self();
124  ctx->scheduler_node =
125    _Scheduler_priority_Thread_get_node(_Thread_Get_executing());
126
127  interrupt_critical_section_test(test_body, ctx, change_priority);
128  rtems_test_assert(ctx->done);
129
130  TEST_END();
131  rtems_test_exit(0);
132}
133
134#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
135#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
136
137#define CONFIGURE_MICROSECONDS_PER_TICK 1000
138
139#define CONFIGURE_MAXIMUM_TASKS 1
140#define CONFIGURE_MAXIMUM_TIMERS 1
141#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
142
143#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
144
145#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
146
147#define CONFIGURE_INIT
148
149#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.