summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/test-scheduler.h
blob: 39474cf250801a6f7e773e556bebba75a09622a4 (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
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RTEMSTestFramework
 *
 * @brief This header file defines the scheduler test support API.
 */

/*
 * Copyright (C) 2021 embedded brains GmbH & Co. KG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _RTEMS_TEST_SCHEDULER_H
#define _RTEMS_TEST_SCHEDULER_H

#include <rtems/test.h>
#include <rtems/score/processormask.h>
#include <rtems/score/scheduler.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup RTEMSTestFramework
 *
 * @{
 */

typedef enum {
	T_SCHEDULER_NOP,
	T_SCHEDULER_ADD_PROCESSOR,
	T_SCHEDULER_ANY,
	T_SCHEDULER_ASK_FOR_HELP,
	T_SCHEDULER_BLOCK,
	T_SCHEDULER_CANCEL_JOB,
	T_SCHEDULER_CLEAN_STICKY,
	T_SCHEDULER_INITIALIZE,
	T_SCHEDULER_MAKE_STICKY,
	T_SCHEDULER_MAP_PRIORITY,
	T_SCHEDULER_NODE_DESTROY,
	T_SCHEDULER_NODE_INITIALIZE,
	T_SCHEDULER_PIN,
	T_SCHEDULER_RECONSIDER_HELP_REQUEST,
	T_SCHEDULER_RELEASE_JOB,
	T_SCHEDULER_REMOVE_PROCESSOR,
	T_SCHEDULER_SCHEDULE,
	T_SCHEDULER_SET_AFFINITY,
	T_SCHEDULER_START_IDLE,
	T_SCHEDULER_UNBLOCK,
	T_SCHEDULER_UNMAP_PRIORITY,
	T_SCHEDULER_UNPIN,
	T_SCHEDULER_UPDATE_PRIORITY,
	T_SCHEDULER_WITHDRAW_NODE,
	T_SCHEDULER_YIELD
} T_scheduler_operation;

typedef struct {
	Thread_Control *executing;
	uint32_t cpu;
	T_time instant;
	T_scheduler_operation operation;
	Thread_Control *thread;
	Scheduler_Node *node;
	union {
		struct {
			Priority_Control in;
			Priority_Control out;
		} map_unmap_priority;
		struct {
			bool success;
		} ask_for_help;
		struct {
#ifdef RTEMS_SMP
			Thread_Scheduler_state next_state;
#else
			int next_state;
#endif
		} withdraw_node;
		struct {
			struct Per_CPU_Control *cpu;
		} pin_unpin;
		struct {
			Thread_Control *idle;
		} add_processor;
		struct {
			struct Per_CPU_Control *cpu;
			Thread_Control *idle;
		} remove_processor;
		struct {
			Priority_Node *priority;
			uint64_t deadline;
		} release_job;
		struct {
			Priority_Node *priority;
		} cancel_job;
		struct {
			Processor_mask affinity;
			Status_Control status;
		} set_affinity;
	};
} T_scheduler_event;

typedef struct {
	size_t recorded;
	size_t capacity;
	uint64_t operations;
} T_scheduler_header;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[T_ZERO_LENGTH_ARRAY];
} T_scheduler_log;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[2];
} T_scheduler_log_2;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[4];
} T_scheduler_log_4;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[10];
} T_scheduler_log_10;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[20];
} T_scheduler_log_20;

typedef struct {
	T_scheduler_header header;
	T_scheduler_event events[40];
} T_scheduler_log_40;

T_scheduler_log *T_scheduler_record(T_scheduler_log *);

T_scheduler_log *T_scheduler_record_2(T_scheduler_log_2 *);

T_scheduler_log *T_scheduler_record_4(T_scheduler_log_4 *);

T_scheduler_log *T_scheduler_record_10(T_scheduler_log_10 *);

T_scheduler_log *T_scheduler_record_20(T_scheduler_log_20 *);

T_scheduler_log *T_scheduler_record_40(T_scheduler_log_40 *);

typedef enum {
	T_SCHEDULER_BEFORE,
	T_SCHEDULER_AFTER
} T_scheduler_when;

typedef void (*T_scheduler_event_handler)(void *, const T_scheduler_event *,
    T_scheduler_when);

void T_scheduler_set_event_handler(T_scheduler_event_handler, void *);

extern const T_scheduler_event T_scheduler_event_null;

const T_scheduler_event *T_scheduler_next(T_scheduler_header *,
    T_scheduler_operation, size_t *);

const T_scheduler_event *T_scheduler_next_any(T_scheduler_header *,
    size_t *);

void T_scheduler_initialize(const Scheduler_Control *);

void T_scheduler_schedule(const Scheduler_Control *, Thread_Control *);

void T_scheduler_yield(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_block(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_unblock(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_update_priority(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

Priority_Control T_scheduler_map_priority(const Scheduler_Control *,
    Priority_Control);

Priority_Control T_scheduler_unmap_priority(const Scheduler_Control *,
    Priority_Control);

void T_scheduler_node_initialize(const Scheduler_Control *, Scheduler_Node *,
    Thread_Control *, Priority_Control);

void T_scheduler_node_destroy(const Scheduler_Control *, Scheduler_Node *);

void T_scheduler_release_job(const Scheduler_Control *, Thread_Control *,
    Priority_Node *, uint64_t, Thread_queue_Context *);

void T_scheduler_cancel_job(const Scheduler_Control *, Thread_Control *,
    Priority_Node *, Thread_queue_Context *);

void T_scheduler_start_idle(const Scheduler_Control *, Thread_Control *,
    struct Per_CPU_Control *);

#ifdef RTEMS_SMP
bool T_scheduler_ask_for_help(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_reconsider_help_request(const Scheduler_Control *,
    Thread_Control *, Scheduler_Node *);

void T_scheduler_withdraw_node(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *, Thread_Scheduler_state);

void T_scheduler_make_sticky(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_clean_sticky(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *);

void T_scheduler_pin(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *, struct Per_CPU_Control *);

void T_scheduler_unpin(const Scheduler_Control *, Thread_Control *,
    Scheduler_Node *, struct Per_CPU_Control *);

void T_scheduler_add_processor(const Scheduler_Control *, Thread_Control *);

Thread_Control *T_scheduler_remove_processor(const Scheduler_Control *,
    struct Per_CPU_Control *);

Status_Control T_scheduler_set_affinity(const Scheduler_Control *,
    Thread_Control *, Scheduler_Node *, const Processor_mask *);
#endif

#ifdef RTEMS_SMP
#define T_SCHEDULER_ENTRY_POINTS { T_scheduler_initialize, \
    T_scheduler_schedule, T_scheduler_yield, T_scheduler_block, \
    T_scheduler_unblock, T_scheduler_update_priority, \
    T_scheduler_map_priority, T_scheduler_unmap_priority, \
    T_scheduler_ask_for_help, T_scheduler_reconsider_help_request, \
    T_scheduler_withdraw_node, T_scheduler_make_sticky, \
    T_scheduler_clean_sticky, T_scheduler_pin, T_scheduler_unpin, \
    T_scheduler_add_processor, T_scheduler_remove_processor, \
    T_scheduler_node_initialize, T_scheduler_node_destroy, \
    T_scheduler_release_job, T_scheduler_cancel_job, \
    T_scheduler_start_idle, T_scheduler_set_affinity }
#else
#define T_SCHEDULER_ENTRY_POINTS { T_scheduler_initialize, \
    T_scheduler_schedule, T_scheduler_yield, T_scheduler_block, \
    T_scheduler_unblock, T_scheduler_update_priority, \
    T_scheduler_map_priority, T_scheduler_unmap_priority, \
    T_scheduler_node_initialize, T_scheduler_node_destroy, \
    T_scheduler_release_job, T_scheduler_cancel_job, \
    T_scheduler_start_idle }
#endif

extern const Scheduler_Operations T_scheduler_operations[];

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* _RTEMS_TEST_SCHEDULER_H */