Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1664 | pj | 1 | #include "constants.h" |
2 | #include "atcsim.h" |
||
3 | #include <kernel/func.h> |
||
4 | #include <kernel/kern.h> //include the SHARK kernel header |
||
5 | #include <drivers/glib.h> //include the graphics library |
||
6 | #include <drivers/keyb.h> //include the keyboard library |
||
7 | #include <semaphore.h> //include the semaphore library |
||
8 | #include <stdlib.h> //include the standard library |
||
9 | #include <math.h> //include the math library for random |
||
10 | #include <string.h> |
||
11 | |||
12 | extern sem_t graphics_mutex; |
||
13 | TASK jetdummy_task(void *arg) |
||
14 | { |
||
15 | TIME now_dummy, last_dummy, diff_dummy, slice; |
||
16 | struct timespec now, last, diff; |
||
17 | int x = 0; |
||
18 | int height; |
||
19 | |||
20 | NULL_TIMESPEC(&last); |
||
21 | last_dummy = 0; |
||
22 | for (;;) { |
||
23 | task_nopreempt(); |
||
24 | jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy); |
||
25 | sys_gettime(&now); |
||
26 | task_preempt(); |
||
27 | |||
28 | SUBTIMESPEC(&now, &last, &diff); |
||
29 | slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000; |
||
30 | diff_dummy = now_dummy - last_dummy; |
||
31 | |||
32 | height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice)); |
||
33 | |||
34 | TIMESPEC_ASSIGN(&last, &now); |
||
35 | last_dummy = now_dummy; |
||
36 | |||
37 | sem_wait(&graphics_mutex); |
||
38 | grx_line(JET_DUMMY_X+x,JET_DUMMY_Y, |
||
39 | JET_DUMMY_X+x,JET_DUMMY_Y+height ,black); |
||
40 | grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height, |
||
41 | JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white); |
||
42 | grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y, |
||
43 | JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255); |
||
44 | |||
45 | // grx_text("Dummy task", 100,100, gray, black); |
||
46 | sem_post(&graphics_mutex); |
||
47 | |||
48 | x = (x+1)%JET_DUMMY_WIDTH; |
||
49 | |||
50 | task_endcycle(); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | |||
55 | TASK jetctrl_task(void *arg) |
||
56 | { |
||
57 | char st[50]; |
||
58 | TIME sum, max; |
||
59 | int n; |
||
60 | |||
61 | PID i; |
||
62 | int printed = 0; |
||
63 | |||
64 | for (;;) { |
||
65 | for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) { |
||
66 | if (jet_getstat(i, &sum, &max, &n, NULL) != -1) { |
||
67 | if (!n) n=1; |
||
68 | sprintf(st, "%4d %4d %8s", (int)sum/n, (int)max, proc_table[i].name); |
||
69 | sem_wait(&graphics_mutex); |
||
70 | grx_text(st, XMAX+10, JET_Y_NAME+16+printed*8, gray, black); |
||
71 | sem_post(&graphics_mutex); |
||
72 | printed++; |
||
73 | } |
||
74 | } |
||
75 | while (printed<JET_NTASK) { |
||
76 | sem_wait(&graphics_mutex); |
||
77 | grx_text(" ", |
||
78 | XMAX+10, JET_Y_NAME+16+printed*8, gray, black); |
||
79 | sem_post(&graphics_mutex); |
||
80 | printed++; |
||
81 | } |
||
82 | task_endcycle(); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | TASK jetslide_task(void *arg) |
||
87 | { |
||
88 | TIME sum, curr, max; |
||
89 | |||
90 | TIME total[JET_NTASK]; |
||
91 | int slides[JET_NTASK]; |
||
92 | |||
93 | PID i; |
||
94 | int printed = 0; |
||
95 | |||
96 | for (;;) { |
||
97 | // Fill the total array in a nonpreemptive section |
||
98 | task_nopreempt(); |
||
99 | for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) { |
||
100 | if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) { |
||
101 | total[printed] = sum+curr; |
||
102 | printed++; |
||
103 | } |
||
104 | } |
||
105 | task_preempt(); |
||
106 | |||
107 | while (printed < JET_NTASK) |
||
108 | total[printed++] = 0; |
||
109 | |||
110 | // Compute the Max elapsed time |
||
111 | max = 0; |
||
112 | for (i=0; i<JET_NTASK; i++) |
||
113 | if (total[i] > max) max = total[i]; |
||
114 | if (!max) max = 1; |
||
115 | |||
116 | // Compute the slides width |
||
117 | for (i=0; i<JET_NTASK; i++) |
||
118 | slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH); |
||
119 | |||
120 | // print the data |
||
121 | sem_wait(&graphics_mutex); |
||
122 | for (i=0; i<JET_NTASK; i++) { |
||
123 | grx_box(JET_SLIDE_X, JET_Y_NAME+16+i*8, |
||
124 | JET_SLIDE_X+slides[i], JET_Y_NAME+23+i*8, gray); |
||
125 | grx_box(JET_SLIDE_X+slides[i], JET_Y_NAME+16+i*8, |
||
126 | JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, black); |
||
127 | } |
||
128 | |||
129 | while (i<JET_NTASK) { |
||
130 | grx_box(JET_SLIDE_X, JET_Y_NAME+16+i*8, |
||
131 | JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, black); |
||
132 | i++; |
||
133 | } |
||
134 | sem_post(&graphics_mutex); |
||
135 | task_endcycle(); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | void scenario_jetcontrol(void) |
||
140 | { |
||
141 | grx_text("System load", XMAX+10, YMIN+100, rgb16(0,0,255), black); |
||
142 | grx_line(XMAX+10,YMIN+100,XMAX+JET_DUMMY_WIDTH,YMIN+100,red); |
||
143 | |||
144 | grx_text("Mean Max Name Slide", XMAX+10, JET_Y_NAME, gray, black); |
||
145 | grx_line(XMAX+10,JET_Y_NAME+10,XMAX+JET_DUMMY_WIDTH,JET_Y_NAME+10,gray); |
||
146 | |||
147 | grx_rect(JET_DUMMY_X-1, JET_DUMMY_Y-1, JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, gray); |
||
148 | |||
149 | grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, gray, black); |
||
150 | grx_text(" 0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, gray, black); |
||
151 | |||
152 | grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, gray); |
||
153 | grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, gray); |
||
154 | } |
||
155 | |||
156 | void init_jetcontrol(void) |
||
157 | { |
||
158 | SOFT_TASK_MODEL m3, m4, m5; |
||
159 | |||
160 | PID p3, p4, p5; |
||
161 | |||
162 | soft_task_default_model(m3); |
||
163 | soft_task_def_level(m3,1); |
||
164 | soft_task_def_period(m3, PERIOD_JETCTRL); |
||
165 | soft_task_def_met(m3, WCET_JETCTRL); |
||
166 | soft_task_def_ctrl_jet(m3); |
||
167 | soft_task_def_group(m3, JETCONTROL); |
||
168 | p3 = task_create("jctrl", jetctrl_task, &m3, NULL); |
||
169 | if (p3 == -1) { |
||
170 | sys_shutdown_message("Could not create task <jetctrl> errno=%d", |
||
171 | errno); |
||
172 | sys_end(); |
||
173 | } |
||
174 | |||
175 | soft_task_default_model(m4); |
||
176 | soft_task_def_level(m4,1); |
||
177 | soft_task_def_period(m4, PERIOD_JETDUMMY); |
||
178 | soft_task_def_met(m4, WCET_JETDUMMY); |
||
179 | soft_task_def_group(m4, JETCONTROL); |
||
180 | soft_task_def_usemath(m4); |
||
181 | soft_task_def_ctrl_jet(m4); |
||
182 | p4 = task_create("jdmy", jetdummy_task, &m4, NULL); |
||
183 | if (p4 == -1) { |
||
184 | sys_shutdown_message("Could not create task <jetdummy> errno=%d", |
||
185 | errno); |
||
186 | sys_end(); |
||
187 | } |
||
188 | |||
189 | soft_task_default_model(m5); |
||
190 | soft_task_def_level(m5,1); |
||
191 | soft_task_def_period(m5, PERIOD_JETSLIDE); |
||
192 | soft_task_def_met(m5, WCET_JETSLIDE); |
||
193 | soft_task_def_group(m5, JETCONTROL); |
||
194 | soft_task_def_usemath(m5); |
||
195 | soft_task_def_ctrl_jet(m5); |
||
196 | p5 = task_create("jsli", jetslide_task, &m5, NULL); |
||
197 | if (p5 == -1) { |
||
198 | sys_shutdown_message("Could not create task <jetslide> errno=%d", |
||
199 | errno); |
||
200 | sys_end(); |
||
201 | } |
||
202 | } |
||
203 |