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
|
/* CLEANUP: Add comments and make it less messy.
*
*/
#ifndef __UNC_RT_DOMAIN_H__
#define __UNC_RT_DOMAIN_H__
#include <litmus/heap.h>
#define RELEASE_QUEUE_SLOTS 127 /* prime */
struct _rt_domain;
typedef int (*check_resched_needed_t)(struct _rt_domain *rt);
typedef void (*release_jobs_t)(struct _rt_domain *rt, struct heap* tasks);
struct release_queue {
/* each slot maintains a list of release heaps sorted
* by release time */
struct list_head slot[RELEASE_QUEUE_SLOTS];
};
typedef struct _rt_domain {
/* runnable rt tasks are in here */
spinlock_t ready_lock;
struct heap ready_queue;
/* real-time tasks waiting for release are in here */
spinlock_t release_lock;
struct release_queue release_queue;
/* for moving tasks to the release queue */
spinlock_t tobe_lock;
struct list_head tobe_released;
/* how do we check if we need to kick another CPU? */
check_resched_needed_t check_resched;
/* how do we release jobs? */
release_jobs_t release_jobs;
/* how are tasks ordered in the ready queue? */
heap_prio_t order;
} rt_domain_t;
struct release_heap {
/* list_head for per-time-slot list */
struct list_head list;
lt_t release_time;
/* all tasks to be released at release_time */
struct heap heap;
/* used to trigger the release */
struct hrtimer timer;
/* required for the timer callback */
rt_domain_t* dom;
};
static inline struct task_struct* __next_ready(rt_domain_t* rt)
{
struct heap_node *hn = heap_peek(rt->order, &rt->ready_queue);
if (hn)
return heap2task(hn);
else
return NULL;
}
void rt_domain_init(rt_domain_t *rt, heap_prio_t order,
check_resched_needed_t check,
release_jobs_t relase);
void __add_ready(rt_domain_t* rt, struct task_struct *new);
void __merge_ready(rt_domain_t* rt, struct heap *tasks);
void __add_release(rt_domain_t* rt, struct task_struct *task);
static inline struct task_struct* __take_ready(rt_domain_t* rt)
{
struct heap_node* hn = heap_take(rt->order, &rt->ready_queue);
if (hn)
return heap2task(hn);
else
return NULL;
}
static inline struct task_struct* __peek_ready(rt_domain_t* rt)
{
struct heap_node* hn = heap_peek(rt->order, &rt->ready_queue);
if (hn)
return heap2task(hn);
else
return NULL;
}
static inline int is_queued(struct task_struct *t)
{
return heap_node_in_heap(tsk_rt(t)->heap_node);
}
static inline void remove(rt_domain_t* rt, struct task_struct *t)
{
heap_delete(rt->order, &rt->ready_queue, tsk_rt(t)->heap_node);
}
static inline void add_ready(rt_domain_t* rt, struct task_struct *new)
{
unsigned long flags;
/* first we need the write lock for rt_ready_queue */
spin_lock_irqsave(&rt->ready_lock, flags);
__add_ready(rt, new);
spin_unlock_irqrestore(&rt->ready_lock, flags);
}
static inline void merge_ready(rt_domain_t* rt, struct heap* tasks)
{
unsigned long flags;
spin_lock_irqsave(&rt->ready_lock, flags);
__merge_ready(rt, tasks);
spin_unlock_irqrestore(&rt->ready_lock, flags);
}
static inline struct task_struct* take_ready(rt_domain_t* rt)
{
unsigned long flags;
struct task_struct* ret;
/* first we need the write lock for rt_ready_queue */
spin_lock_irqsave(&rt->ready_lock, flags);
ret = __take_ready(rt);
spin_unlock_irqrestore(&rt->ready_lock, flags);
return ret;
}
static inline void add_release(rt_domain_t* rt, struct task_struct *task)
{
unsigned long flags;
/* first we need the write lock for rt_ready_queue */
spin_lock_irqsave(&rt->tobe_lock, flags);
__add_release(rt, task);
spin_unlock_irqrestore(&rt->tobe_lock, flags);
}
static inline int __jobs_pending(rt_domain_t* rt)
{
return !heap_empty(&rt->ready_queue);
}
static inline int jobs_pending(rt_domain_t* rt)
{
unsigned long flags;
int ret;
/* first we need the write lock for rt_ready_queue */
spin_lock_irqsave(&rt->ready_lock, flags);
ret = !heap_empty(&rt->ready_queue);
spin_unlock_irqrestore(&rt->ready_lock, flags);
return ret;
}
#endif
|