File: rtai_sched.h

package info (click to toggle)
rtai 3.1.0-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 23,560 kB
  • ctags: 19,698
  • sloc: ansic: 88,861; cpp: 31,340; tcl: 14,684; sh: 10,652; xml: 760; yacc: 575; lex: 537; makefile: 394; asm: 310; php: 300; perl: 108
file content (418 lines) | stat: -rw-r--r-- 9,834 bytes parent folder | download
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
/*
 * Copyright (C) 1999-2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _RTAI_SCHED_H
#define _RTAI_SCHED_H

#include <rtai.h>
#ifndef __KERNEL__
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include <rtai_types.h>
#endif /* __KERNEL__ */

#define RT_SCHED_UP   1
#define RT_SCHED_SMP  2
#define RT_SCHED_MUP  3

#define RT_SCHED_HIGHEST_PRIORITY  0
#define RT_SCHED_LOWEST_PRIORITY   0x3fffFfff
#define RT_SCHED_LINUX_PRIORITY    0x7fffFfff

#define RT_SCHED_READY        1
#define RT_SCHED_SUSPENDED    2
#define RT_SCHED_DELAYED      4
#define RT_SCHED_SEMAPHORE    8
#define RT_SCHED_SEND        16
#define RT_SCHED_RECEIVE     32
#define RT_SCHED_RPC         64
#define RT_SCHED_RETURN     128
#define RT_SCHED_MBXSUSP    256
#define RT_SCHED_SFTRDY     512

struct rt_task_struct;

#ifdef __KERNEL__

#include <linux/time.h>
#include <linux/errno.h>

#define RT_TASK_MAGIC 0x754d2774

#ifndef __cplusplus

#include <linux/sched.h>

typedef struct rt_queue {
	struct rt_queue *prev;
	struct rt_queue *next;
	struct rt_task_struct *task;
} QUEUE;

struct mcb_t {
    void *sbuf;
    int sbytes;
    void *rbuf;
    int rbytes;
};

typedef struct rt_ExitHandler {
    /* Exit handler functions are called like C++ destructors in
       rt_task_delete(). */
    struct rt_ExitHandler *nxt;
    void (*fun) (void *arg1, int arg2);
    void *arg1;
    int   arg2;
} XHDL;

struct rt_heap_t { void *heap, *kadr, *uadr; };

typedef struct rt_task_struct {

    int *stack;
    int uses_fpu;
    int magic;
    volatile int state, running;
    unsigned long runnable_on_cpus;
    int *stack_bottom;
    volatile int priority;
    int base_priority;
    int policy;
    int sched_lock_priority;
    struct rt_task_struct *prio_passed_to;
    RTIME period;
    RTIME resume_time;
    RTIME yield_time;
    int rr_quantum;
    int rr_remaining;
    int suspdepth;
    struct rt_queue queue;
    int owndres;
    struct rt_queue *blocked_on;
    struct rt_queue msg_queue;
    int tid;	/* trace ID */
    unsigned msg;
    struct rt_queue ret_queue;
    void (*signal)(void);
    FPU_ENV fpu_reg;
    struct rt_task_struct *prev;
    struct rt_task_struct *next;
    struct rt_task_struct *tprev;
    struct rt_task_struct *tnext;
    struct rt_task_struct *rprev;
    struct rt_task_struct *rnext;

    /* Appended for calls from LINUX. */
    int *fun_args, *bstack;
    struct task_struct *lnxtsk;
    long long retval;
    char *msg_buf[2];
    int max_msg_size[2];
    char task_name[16];
    void *system_data_ptr;
    struct rt_task_struct *nextp;
    struct rt_task_struct *prevp;

    /* Added to support user specific trap handlers. */
    RT_TRAP_HANDLER task_trap_handler[RTAI_NR_TRAPS];

    /* Added from rtai-22. */
    void (*usp_signal)(void);
    volatile unsigned long pstate;
    unsigned long usp_flags;
    unsigned long usp_flags_mask;
    unsigned long force_soft;
    volatile int is_hard;

    /* Added to terminate qBlks. */
    void *tick_queue;

    /* Added to terminate re-entry of user space functions. */

    void *trap_handler_data; 
    int trap_signo;

    /* For use by watchdog. */
    int resync_frame;

    /* For use by exit handler functions. */
    XHDL *ExitHook;
    int linux_signal;
    int errno;
    void (*linux_signal_handler)(int sig);
    RTIME exectime[2];
    struct mcb_t mcb;

	/* Real time heaps. */
	struct rt_heap_t heap[2];

} RT_TASK __attribute__ ((__aligned__ (16)));

#else /* __cplusplus */
extern "C" {
#endif /* !__cplusplus */

int rt_task_init(struct rt_task_struct *task,
		 void (*rt_thread)(int),
		 int data,
		 int stack_size,
		 int priority,
		 int uses_fpu,
		 void(*signal)(void));

int rt_task_init_cpuid(struct rt_task_struct *task,
		       void (*rt_thread)(int),
		       int data,
		       int stack_size,
		       int priority,
		       int uses_fpu,
		       void(*signal)(void),
		       unsigned run_on_cpu);

void rt_set_runnable_on_cpus(struct rt_task_struct *task,
			     unsigned long cpu_mask);

void rt_set_runnable_on_cpuid(struct rt_task_struct *task,
			      unsigned cpuid);

void rt_set_sched_policy(struct rt_task_struct *task,
			 int policy,
			 int rr_quantum_ns);

int rt_task_delete(struct rt_task_struct *task);

int rt_get_task_state(struct rt_task_struct *task);

void rt_gettimeorig(RTIME time_orig[]);

int rt_get_timer_cpu(void);

int rt_is_hard_timer_running(void);

void rt_set_periodic_mode(void);

void rt_set_oneshot_mode(void);

RTIME start_rt_timer(int period);

RTIME start_rt_timer_cpuid(int period,
			   int cpuid);

#define start_rt_timer_ns(period) start_rt_timer(nano2count((period)))

void start_rt_apic_timers(struct apic_timer_setup_data *setup_mode,
			  unsigned rcvr_jiffies_cpuid);

void stop_rt_timer(void);

struct rt_task_struct *rt_whoami(void);

int rt_sched_type(void);

int rt_task_signal_handler(struct rt_task_struct *task,
			   void (*handler)(void));

int rt_task_use_fpu(struct rt_task_struct *task,
		    int use_fpu_flag);
  
void rt_linux_use_fpu(int use_fpu_flag);

void rt_preempt_always(int yes_no);

void rt_preempt_always_cpuid(int yes_no,
			     unsigned cpuid);

RTIME count2nano(RTIME timercounts);

RTIME nano2count(RTIME nanosecs);
  
RTIME count2nano_cpuid(RTIME timercounts,
		       unsigned cpuid);

RTIME nano2count_cpuid(RTIME nanosecs,
		       unsigned cpuid);
  
RTIME rt_get_time(void);

RTIME rt_get_time_cpuid(unsigned cpuid);

RTIME rt_get_time_ns(void);

RTIME rt_get_time_ns_cpuid(unsigned cpuid);

RTIME rt_get_cpu_time_ns(void);

int rt_get_prio(struct rt_task_struct *task);

int rt_get_inher_prio(struct rt_task_struct *task);

void rt_spv_RMS(int cpuid);

int rt_change_prio(struct rt_task_struct *task,
		   int priority);

void rt_sched_lock(void);

void rt_sched_unlock(void);

void rt_task_yield(void);

int rt_task_suspend(struct rt_task_struct *task);

int rt_task_resume(struct rt_task_struct *task);

int rt_task_make_periodic_relative_ns(struct rt_task_struct *task,
				      RTIME start_delay,
				      RTIME period);

int rt_task_make_periodic(struct rt_task_struct *task,
			  RTIME start_time,
			  RTIME period);

void rt_task_set_resume_end_times(RTIME resume,
				  RTIME end);

int rt_set_resume_time(struct rt_task_struct *task,
		       RTIME new_resume_time);

int rt_set_period(struct rt_task_struct *task,
		  RTIME new_period);

void rt_task_wait_period(void);

void rt_schedule(void);

RTIME next_period(void);

void rt_busy_sleep(int nanosecs);

void rt_sleep(RTIME delay);

void rt_sleep_until(RTIME time);

int rt_task_wakeup_sleeping(struct rt_task_struct *task);

struct rt_task_struct *rt_named_task_init(const char *task_name,
					  void (*thread)(int),
					  int data,
					  int stack_size,
					  int prio,
					  int uses_fpu,
					  void(*signal)(void));

struct rt_task_struct *rt_named_task_init_cpuid(const char *task_name,
						void (*thread)(int),
						int data,
						int stack_size,
						int prio,
						int uses_fpu,
						void(*signal)(void),
						unsigned run_on_cpu);

int rt_named_task_delete(struct rt_task_struct *task);

RT_TRAP_HANDLER rt_set_task_trap_handler(struct rt_task_struct *task,
					 unsigned vec,
					 RT_TRAP_HANDLER handler);

static inline RTIME timeval2count(struct timeval *t)
{
        return nano2count(t->tv_sec*1000000000LL + t->tv_usec*1000);
}

static inline void count2timeval(RTIME rt, struct timeval *t)
{
        t->tv_sec = ulldiv(count2nano(rt), 1000000000, (unsigned long *)&t->tv_usec);
        t->tv_usec /= 1000;
}

static inline RTIME timespec2count(const struct timespec *t)
{
        return nano2count(t->tv_sec*1000000000LL + t->tv_nsec);
}

static inline void count2timespec(RTIME rt, struct timespec *t)
{
        t->tv_sec = ulldiv(count2nano(rt), 1000000000, (unsigned long *)&t->tv_nsec);
}

static inline RTIME timespec2nanos(const struct timespec *t)
{
        return t->tv_sec*1000000000LL + t->tv_nsec;
}

static inline void nanos2timespec(RTIME rt, struct timespec *t)
{
        t->tv_sec = ulldiv(rt, 1000000000, (unsigned long *)&t->tv_nsec);
}

#ifdef __cplusplus
}
#else /* !__cplusplus */

/* FIXME: These calls should move to rtai_schedcore.h */

RT_TASK *rt_get_base_linux_task(RT_TASK **base_linux_task);

RT_TASK *rt_alloc_dynamic_task(void);

void rt_enq_ready_edf_task(RT_TASK *ready_task);

void rt_enq_ready_task(RT_TASK *ready_task);

int rt_renq_ready_task(RT_TASK *ready_task,
		       int priority);

void rt_rem_ready_task(RT_TASK *task);

void rt_rem_ready_current(RT_TASK *rt_current);

void rt_enq_timed_task(RT_TASK *timed_task);

void rt_rem_timed_task(RT_TASK *task);

void rt_dequeue_blocked(RT_TASK *task);

RT_TASK **rt_register_watchdog(RT_TASK *wdog,
			       int cpuid);

void rt_deregister_watchdog(RT_TASK *wdog,
			    int cpuid);

#endif /* __cplusplus */

#endif /* __KERNEL__ */

#if !defined(__KERNEL__) || defined(__cplusplus)

typedef struct rt_task_struct {
    int opaque;
} RT_TASK;

typedef struct QueueBlock {
    int opaque;
} QBLK;

typedef struct QueueHook {
    int opaque;
} QHOOK;

#endif /* !__KERNEL__ || __cplusplus */

#endif /* !_RTAI_SCHED_H */