-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchronos.c
executable file
·219 lines (199 loc) · 6.92 KB
/
chronos.c
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
/***************************************************************************
* Copyright (C) 2009-2012 Virginia Tech Real-Time Systems Lab *
* Written by Matthew Dellinger *
* *
* 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. *
***************************************************************************/
#include "chronos.h"
/* Set the basic information of the calling task */
long begin_rtseg_selfbasic(int prio, struct timespec* deadline,
struct timespec* period) {
struct rt_data data;
data.tid = 0;
data.prio = prio;
data.max_util = 0;
data.exec_time = 0;
data.period = period;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_BEGIN, &data);
}
/* Set the basic information of another task */
long begin_rtseg_basic(int tid, int prio, struct timespec* deadline,
struct timespec* period) {
struct rt_data data;
data.tid = tid;
data.prio = prio;
data.max_util = 0;
data.exec_time = 0;
data.period = period;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_BEGIN, &data);
}
/* Set the full rt information of the calling task */
long begin_rtseg_self(int prio, int max_util, struct timespec* deadline,
struct timespec* period, unsigned long exec_time) {
struct rt_data data;
data.tid = 0;
data.prio = prio;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = period;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_BEGIN, &data);
}
/* Set the full rt information of another task */
long begin_rtseg(int tid, int prio, int max_util, struct timespec* deadline,
struct timespec* period, unsigned long exec_time) {
struct rt_data data;
data.tid = tid;
data.prio = prio;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = period;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_BEGIN, &data);
}
/* End the real-time portion of the calling task */
long end_rtseg_self(int prio) {
struct rt_data data;
data.tid = 0;
data.prio = prio;
data.period = NULL;
data.deadline = NULL;
return syscall(__NR_do_rt_seg, RT_SEG_END, &data);
}
/* End the real-time portion of another task */
long end_rtseg(int tid, int prio) {
struct rt_data data;
data.tid = tid;
data.prio = prio;
data.period = NULL;
data.deadline = NULL;
return syscall(__NR_do_rt_seg, RT_SEG_END, &data);
}
/* Add an abort handler for the task */
long add_abort_handler_self(int max_util, struct timespec *deadline,
unsigned long exec_time) {
struct rt_data data;
data.tid = 0;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = NULL;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_ADD_ABORT, &data);
}
/* Add an abort handler for another task */
long add_abort_handler(int tid, int max_util, struct timespec *deadline,
unsigned long exec_time) {
struct rt_data data;
data.tid = tid;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = NULL;
data.deadline = deadline;
return syscall(__NR_do_rt_seg, RT_SEG_ADD_ABORT, &data);
}
/* Add an abort handler for the task with no deadline */
long add_abort_handler_selfnodeadline(int max_util, unsigned long exec_time) {
struct rt_data data;
data.tid = 0;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = NULL;
data.deadline = NULL;
return syscall(__NR_do_rt_seg, RT_SEG_ADD_ABORT, &data);
}
/* Add an abort handler for another task with no deadline */
long add_abort_handler_nodeadline(int tid, int max_util,
unsigned long exec_time) {
struct rt_data data;
data.tid = tid;
data.max_util = max_util;
data.exec_time = exec_time;
data.period = NULL;
data.deadline = NULL;
return syscall(__NR_do_rt_seg, RT_SEG_ADD_ABORT, &data);
}
long set_scheduler(int scheduler, int prio, unsigned long cpus) {
unsigned long mask = cpus;
unsigned int len = sizeof(mask);
return syscall(__NR_set_scheduler, scheduler, prio, len, (cpu_set_t*) &mask);
}
/* Changed from class for ease in replacing pthread_mutext */
/* Init a resource */
/*
long chronos_mutex_init(chronos_mutex_t *m) {
m->value = 0;
m->owner = 0;
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_INIT);
}
*/
//Modified version of chronos_mutex_init
/******** SH-ST *********/
long chronos_mutex_init(chronos_mutex_t **m, int *lock_pro) {
m[0]->value = 0;
m[0]->owner = 0;
int num_mutex=1; //dummy variable for sys_call
int num_proc=1; //dummy variable for sys_call
int sched_no=1; //dummy variable for sys_call
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_INIT, &num_mutex, lock_pro, &num_proc, &sched_no);
}
/******** SH-END *********/
/* Destroy a resource */
/*
long chronos_mutex_destroy(chronos_mutex_t *m) {
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_DESTROY);
}
*/
//Modified version of chronos_mutex_destroy
/********* SH-ST **********/
long chronos_mutex_destroy(chronos_mutex_t **m) {
int lock_pro=1; //dummy variable for sys_call
int num_proc=1; //dummy variable for sys_call
int num_mutex=1; //dummy variable for sys_call
int sched_no=1; //dummy variable for sys_call
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_DESTROY,&num_mutex,&lock_pro,&num_proc,&sched_no);
}
/********* SH-END **********/
/* Request a resource from the host */
/*
long chronos_mutex_lock(chronos_mutex_t *m) {
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_REQUEST);
}
*/
/******* SH-ST ********/
//Modified version of chronos_mutex_lock
long chronos_mutex_lock(chronos_mutex_t **m, int *num_mutex, int *lock_pro, int *num_proc, int *sched_no) {
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_REQUEST, num_mutex, lock_pro, num_proc, sched_no);
}
/******* SH-END ********/
/* Release a resource */
/*
long chronos_mutex_unlock(chronos_mutex_t *m) {
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_RELEASE);
}
*/
//Modified version of chronos_mutex_unlock
/********* SH-ST ************/
long chronos_mutex_unlock(chronos_mutex_t **m, int *num_mutex, int *lock_pro, int *sched_no) {
int num_proc=1; //dummy variable for sys_call
return syscall(__NR_do_chronos_mutex, m, CHRONOS_MUTEX_RELEASE, num_mutex, lock_pro, &num_proc, sched_no);
}
/********* SH-END ************/
int chronos_mutex_owner(chronos_mutex_t *m) {
return m->owner;
}