forked from teawater/libhermit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.h
More file actions
291 lines (239 loc) · 7.57 KB
/
Copy pathtasks.h
File metadata and controls
291 lines (239 loc) · 7.57 KB
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
/*
* Copyright (c) 2010, Stefan Lankes, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 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 REGENTS 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.
*/
/**
* @author Stefan Lankes
* @file include/hermit/tasks.h
* @brief Task related
*
* Create and leave tasks or fork them.
*/
#ifndef __TASKS_H__
#define __TASKS_H__
#include <hermit/stddef.h>
#include <hermit/tasks_types.h>
#include <asm/tasks.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief System call to terminate a user level process */
void NORETURN sys_exit(int);
/** @brief Task switcher
*
* Timer-interrupted use of this function for task switching
*
* @return
* - 0 no context switch
* - !0 address of the old stack pointer
*/
size_t** scheduler(void);
/** @brief Initialize the multitasking subsystem
*
* This procedure sets the current task to the
* current "task" (there are no tasks, yet) and that was it.
*
* @return
* - 0 on success
* - -ENOMEM (-12) on failure
*/
int multitasking_init(void);
/** @brief Clone current task with a specific entry point
*
* @todo Don't acquire table_lock for the whole task creation.
*
* @param id Pointer to a tid_t struct were the id shall be set
* @param ep Pointer to the function the task shall start with
* @param arg Arguments list
* @param prio Desired priority of the new task
* @param core_id Start the new task on the core with this id
*
* @return
* - 0 on success
* - -ENOMEM (-12) or -EINVAL (-22) on failure
*/
int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio);
/** @brief Create a task with a specific entry point
*
* @todo Don't acquire table_lock for the whole task creation.
*
* @param id Pointer to a tid_t struct were the id shall be set
* @param ep Pointer to the function the task shall start with
* @param arg Arguments list
* @param prio Desired priority of the new task
* @param core_id Start the new task on the core with this id
*
* @return
* - 0 on success
* - -ENOMEM (-12) or -EINVAL (-22) on failure
*/
int create_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio, uint32_t core_id);
/** @brief create a kernel-level task on the current core.
*
* @param id The value behind this pointer will be set to the new task's id
* @param ep Pointer to the entry function for the new task
* @param args Arguments the task shall start with
* @param prio Desired priority of the new kernel task
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int create_kernel_task(tid_t* id, entry_point_t ep, void* args, uint8_t prio);
/** @brief create a kernel-level task.
*
* @param id The value behind this pointer will be set to the new task's id
* @param ep Pointer to the entry function for the new task
* @param args Arguments the task shall start with
* @param prio Desired priority of the new kernel task
* @param core_id Start the new task on the core with this id
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int create_kernel_task_on_core(tid_t* id, entry_point_t ep, void* args, uint8_t prio, uint32_t core_id);
/** @brief Cleanup function for the task termination
*
* On termination, the task call this function to cleanup its address space.
*/
void finish_task_switch(void);
/** @brief determine the highest priority of all tasks, which are ready
*
* @return
* - return highest priority
* - if no task is ready, the function returns an invalid value (> MAX_PRIO)
*/
uint32_t get_highest_priority(void);
/** @brief Call to rescheduling
*
* This is a purely assembled procedure for rescheduling
*/
void reschedule(void);
/** @brief Wake up a blocked task
*
* The task's status will be changed to TASK_READY
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int wakeup_task(tid_t);
/** @brief Wake up a core_id
*
* Wakeup core to be sure that
* the core isn't in halt state
*
* @param core_id Specifies the core
*/
void wakeup_core(uint32_t core_id);
/** @brief Block current task
*
* The current task's status will be changed to TASK_BLOCKED
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int block_current_task(void);
/** @brief Block task until a new arrived
*
*/
void wait_for_task(void);
/** @brief Get readyqueue of the current core
*
* @return
* - address of the readyqueue
*/
void* get_readyqueue(void);
/** @brief Get a process control block
*
* @param id ID of the task to retrieve
* @param task Location to store pointer to task
* @return
* - 0 on success
* - -ENOMEM (-12) if @p task is NULL
* - -ENOENT ( -2) if @p id not in task table
* - -EINVAL (-22) if there's no valid task with @p id
*/
int get_task(tid_t id, task_t** task);
/** @brief Block current task until timer expires
*
* @param deadline Clock tick, when the timer expires
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int set_timer(uint64_t deadline);
/** @brief check is a timer is expired */
void check_timers(void);
/** @brief Abort current task */
void NORETURN do_abort(void);
/** @brief This function shall be called by leaving kernel-level tasks */
void NORETURN leave_kernel_task(void);
/** @brief Release the thread local storage of the current thread */
void destroy_tls(void);
/** @brief if a task exists with higher priority, HermitCore switch to it. */
void check_scheduling(void);
/** @brief return true if a task is available and ready. */
int is_task_available(void);
/** @brief This function shutdowns the (ip) network */
int network_shutdown(void);
#ifdef DYNAMIC_TICKS
/** @brief check, if the tick counter has to be updated
*/
void check_ticks(void);
#endif
/** @brief shutdown the whole system
*/
void shutdown_system(void);
extern volatile uint32_t go_down;
static inline void check_workqueues_in_irqhandler(int irq)
{
#ifdef DYNAMIC_TICKS
// Increment ticks
check_ticks();
#endif
check_timers();
if (go_down)
shutdown_system();
if (irq < 0)
check_scheduling();
}
static inline void check_workqueues(void)
{
// call with invalid interrupt number
check_workqueues_in_irqhandler(-1);
}
/** @brief check if a proxy is available
*/
int is_proxy(void);
/** @brief initialized the stacks of the idle tasks
*/
int set_boot_stack(tid_t id, size_t stack, size_t ist_addr);
#ifdef __cplusplus
}
#endif
#endif