Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Gerardo Lamastra <gerardo@sssup.it> |
||
6 | * |
||
7 | * Authors : Paolo Gai <pj@hartik.sssup.it> |
||
8 | * (see authors.txt for full list of hartik's authors) |
||
9 | * |
||
10 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
11 | * |
||
12 | * http://www.sssup.it |
||
13 | * http://retis.sssup.it |
||
14 | * http://hartik.sssup.it |
||
15 | */ |
||
16 | |||
17 | /** |
||
18 | ------------ |
||
19 | CVS : $Id: testc.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $ |
||
20 | |||
21 | File: $File$ |
||
22 | Revision: $Revision: 1.1.1.1 $ |
||
23 | Last update: $Date: 2002-09-02 09:37:48 $ |
||
24 | ------------ |
||
25 | |||
26 | Test Number 12 (C): |
||
27 | |||
28 | CBS test, similar to Test 11 |
||
29 | |||
30 | then at start time two task are started, one of them |
||
31 | calling task_nopreempt. when the task releases, the other exec all |
||
32 | the pending activations. |
||
33 | at sec. 4 the test stops. |
||
34 | |||
35 | **/ |
||
36 | |||
37 | /* |
||
38 | * Copyright (C) 2000 Paolo Gai |
||
39 | * |
||
40 | * This program is free software; you can redistribute it and/or modify |
||
41 | * it under the terms of the GNU General Public License as published by |
||
42 | * the Free Software Foundation; either version 2 of the License, or |
||
43 | * (at your option) any later version. |
||
44 | * |
||
45 | * This program is distributed in the hope that it will be useful, |
||
46 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
47 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
48 | * GNU General Public License for more details. |
||
49 | * |
||
50 | * You should have received a copy of the GNU General Public License |
||
51 | * along with this program; if not, write to the Free Software |
||
52 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
53 | * |
||
54 | */ |
||
55 | |||
56 | #include "kernel/kern.h" |
||
57 | |||
58 | TASK pippo() |
||
59 | { |
||
60 | // int i; |
||
61 | struct timespec t; |
||
62 | // int last = 0; |
||
63 | |||
64 | do { |
||
65 | kern_cli(); |
||
66 | ll_gettime(TIME_EXACT, &t); |
||
67 | kern_sti(); |
||
68 | } while (t.tv_nsec <= 30000000L); |
||
69 | return 0; |
||
70 | } |
||
71 | |||
72 | TASK pippo2() |
||
73 | { |
||
74 | // int i; |
||
75 | struct timespec t; |
||
76 | // int last = 0; |
||
77 | |||
78 | do { |
||
79 | kern_cli(); |
||
80 | ll_gettime(TIME_EXACT, &t); |
||
81 | kern_sti(); |
||
82 | |||
83 | } while (t.tv_nsec <= 30000000L); |
||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | TASK asteroide(void) |
||
88 | { |
||
89 | int i; |
||
90 | int y = rand() % 7 + 15; |
||
91 | |||
92 | int load1,j; |
||
93 | |||
94 | char s[2]; |
||
95 | |||
96 | s[0] = '*'; s[1] = 0; |
||
97 | |||
98 | /*for (;;)*/ { |
||
99 | i = 1; |
||
100 | while (i < 60) { |
||
101 | load1 = 10000; //8000 + rand()%2000; |
||
102 | for (j=0; j<load1; j++) { |
||
103 | s[0] = '*' + rand() % 100; |
||
104 | puts_xy(i,y,rand()%15+1,s); |
||
105 | } |
||
106 | |||
107 | task_endcycle(); |
||
108 | |||
109 | // if (i==7) testactive = 0; |
||
110 | |||
111 | puts_xy(i,y,WHITE," "); |
||
112 | i++; |
||
113 | } |
||
114 | } |
||
115 | //num_aster--; |
||
116 | return 0; |
||
117 | } |
||
118 | |||
119 | TASK aper(void *a) |
||
120 | { |
||
121 | int i; |
||
122 | int y; |
||
123 | |||
124 | int load1,j; |
||
125 | |||
126 | char s[2]; |
||
127 | |||
128 | y = (int) a; |
||
129 | |||
130 | s[0] = '*'; s[1] = 0; |
||
131 | |||
132 | /*for (;;)*/ { |
||
133 | i = 1; |
||
134 | while (i < 60) { |
||
135 | load1 = 600000; //8000 + rand()%2000; |
||
136 | for (j=0; j<load1; j++) { |
||
137 | s[0] = '*' + rand() % 100; |
||
138 | puts_xy(i,y,rand()%15+1,s); |
||
139 | } |
||
140 | |||
141 | task_endcycle(); |
||
142 | |||
143 | puts_xy(i,y,WHITE," "); |
||
144 | i++; |
||
145 | } |
||
146 | } |
||
147 | //num_aster--; |
||
148 | return 0; |
||
149 | } |
||
150 | |||
151 | |||
152 | TASK per(void) |
||
153 | { |
||
154 | int i; |
||
155 | int y = rand() % 7 + 15; |
||
156 | |||
157 | int load1,j; |
||
158 | |||
159 | char s[2]; |
||
160 | |||
161 | s[0] = '*'; s[1] = 0; |
||
162 | |||
163 | /*for (;;)*/ { |
||
164 | i = 1; |
||
165 | while (i < 60) { |
||
166 | load1 = 1000; //8000 + rand()%2000; |
||
167 | for (j=0; j<load1; j++) { |
||
168 | s[0] = '*' + rand() % 100; |
||
169 | puts_xy(i,y,rand()%15+1,s); |
||
170 | } |
||
171 | |||
172 | task_endcycle(); |
||
173 | |||
174 | // if (i==7) testactive = 0; |
||
175 | |||
176 | //puts_xy(i,y,WHITE," "); |
||
177 | i++; |
||
178 | } |
||
179 | } |
||
180 | //num_aster--; |
||
181 | return 0; |
||
182 | } |
||
183 | |||
184 | TASK stoppa() |
||
185 | { |
||
186 | struct timespec t; |
||
187 | |||
188 | task_nopreempt(); |
||
189 | kern_printf("\nTask nopreempt"); |
||
190 | do { |
||
191 | kern_cli(); |
||
192 | ll_gettime(TIME_EXACT, &t); |
||
193 | kern_sti(); |
||
194 | } while (t.tv_sec < 3); |
||
195 | kern_printf("\nTask preempt"); |
||
196 | task_preempt(); |
||
197 | kern_printf("\nFine STOPPA"); |
||
198 | return 0; |
||
199 | } |
||
200 | |||
201 | |||
202 | |||
203 | int main(int argc, char **argv) |
||
204 | { |
||
205 | struct timespec t; |
||
206 | int i; |
||
207 | NRT_TASK_MODEL m; |
||
208 | // HARD_TASK_MODEL m_per; |
||
209 | SOFT_TASK_MODEL m_aper; |
||
210 | PID p8, p9; //p1, p2, p3, p4, p5, p6, p7, |
||
211 | |||
212 | // int k=1; |
||
213 | |||
214 | srand(7); |
||
215 | |||
216 | nrt_task_default_model(m); |
||
217 | nrt_task_def_group(m,1); |
||
218 | |||
219 | soft_task_default_model(m_aper); |
||
220 | soft_task_def_met(m_aper,10000); |
||
221 | soft_task_def_period(m_aper,100000); |
||
222 | soft_task_def_group(m_aper,1); |
||
223 | soft_task_def_system(m_aper); |
||
224 | soft_task_def_arg(m_aper, (void *)14); |
||
225 | soft_task_def_aperiodic(m_aper); |
||
226 | // soft_task_def_skip_arrivals(m_aper); |
||
227 | |||
228 | soft_task_def_periodic(m_aper); |
||
229 | p8 = task_create("per", per, &m_aper, NULL); |
||
230 | if (p8 == NIL) |
||
231 | { kern_printf("Can't create per task...\n"); } |
||
232 | |||
233 | p9 = task_create("stoppa", stoppa, &m, NULL); |
||
234 | if (p9 == NIL) |
||
235 | { kern_printf("Can't create stoppa task...\n"); } |
||
236 | |||
237 | task_activate(p8); |
||
238 | |||
239 | i = 0; |
||
240 | |||
241 | NULL_TIMESPEC(&t); |
||
242 | do { |
||
243 | kern_cli(); |
||
244 | ll_gettime(TIME_EXACT, &t); |
||
245 | kern_sti(); |
||
246 | |||
247 | if (i == 0 && t.tv_sec == 1 && t.tv_nsec >= 0) { |
||
248 | task_activate(p9); |
||
249 | i = 1; |
||
250 | } |
||
251 | } while (t.tv_sec < 10); |
||
252 | /* |
||
253 | testactive = 0; |
||
254 | kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds); |
||
255 | for (i=0; i<useds; i++) |
||
256 | kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i, |
||
257 | s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]); |
||
258 | */ |
||
259 | return 0; |
||
260 | } |