Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1665 | pj | 1 | ////////////////////////////////////////////////////////////////// |
2 | // Pong |
||
3 | // Written for CS 324, UIUC |
||
4 | // Spencer Hoke |
||
5 | // James Kim |
||
6 | // Tao Luo |
||
7 | // |
||
8 | // Last Modified: April 29, 2004 |
||
9 | |||
10 | #include "pong.h" |
||
11 | |||
12 | /////////////////////////////////////// |
||
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 | mutex_lock(&draw_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,blue); |
||
44 | mutex_unlock(&draw_mutex); |
||
45 | |||
46 | x = (x+1)%JET_DUMMY_WIDTH; |
||
47 | |||
48 | task_endcycle(); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | /////////////////////////////////////// |
||
53 | TASK jetctrl_task(void *arg) |
||
54 | { |
||
55 | char st[50]; |
||
56 | TIME sum, max; |
||
57 | int n; |
||
58 | |||
59 | PID i; |
||
60 | int printed = 0; |
||
61 | |||
62 | for (;;) { |
||
63 | for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) { |
||
64 | if (jet_getstat(i, &sum, &max, &n, NULL) != -1) { |
||
65 | if (!n) n=1; |
||
66 | sprintf(st, " %4d %4d %s", (int)sum/n, (int)max, proc_table[i].name); |
||
67 | mutex_lock(&draw_mutex); |
||
68 | grx_text(st, JET_DUMMY_X-45, JET_Y_NAME+16+printed*8, gray, black); |
||
69 | mutex_unlock(&draw_mutex); |
||
70 | printed++; |
||
71 | } |
||
72 | } |
||
73 | while (printed < JET_NTASK) { |
||
74 | mutex_lock(&draw_mutex); |
||
75 | grx_text(" ", JET_DUMMY_X-45, JET_Y_NAME+16+printed*8, gray, black); |
||
76 | mutex_unlock(&draw_mutex); |
||
77 | printed++; |
||
78 | } |
||
79 | task_endcycle(); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /////////////////////////////////////// |
||
84 | TASK jetslide_task(void *arg) |
||
85 | { |
||
86 | TIME sum, curr, max; |
||
87 | |||
88 | TIME total[JET_NTASK]; |
||
89 | int slides[JET_NTASK]; |
||
90 | |||
91 | PID i; |
||
92 | int printed = 0; |
||
93 | |||
94 | for (;;) { |
||
95 | // Fill the total array in a nonpreemptive section |
||
96 | task_nopreempt(); |
||
97 | for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) { |
||
98 | if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) { |
||
99 | total[printed] = sum+curr; |
||
100 | printed++; |
||
101 | } |
||
102 | } |
||
103 | task_preempt(); |
||
104 | |||
105 | while (printed < JET_NTASK) |
||
106 | total[printed++] = 0; |
||
107 | |||
108 | // Compute the Max elapsed time |
||
109 | max = 0; |
||
110 | for (i=0; i<JET_NTASK; i++) |
||
111 | if (total[i] > max) max = total[i]; |
||
112 | if (!max) max = 1; |
||
113 | |||
114 | // Compute the slides width |
||
115 | for (i=0; i<JET_NTASK; i++) |
||
116 | slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH); |
||
117 | |||
118 | // print the data |
||
119 | mutex_lock(&draw_mutex); |
||
120 | for (i=0; i<JET_NTASK; i++) { |
||
121 | grx_box(JET_SLIDE_X, JET_Y_NAME+16+i*8, |
||
122 | JET_SLIDE_X+slides[i], JET_Y_NAME+23+i*8, gray); |
||
123 | grx_box(JET_SLIDE_X+slides[i], JET_Y_NAME+16+i*8, |
||
124 | JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, black); |
||
125 | } |
||
126 | |||
127 | while (i<JET_NTASK) { |
||
128 | grx_box(JET_SLIDE_X, JET_Y_NAME+16+i*8, |
||
129 | JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, black); |
||
130 | i++; |
||
131 | } |
||
132 | mutex_unlock(&draw_mutex); |
||
133 | task_endcycle(); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | /////////////////////////////////////// |
||
138 | void scenario_jetcontrol(void) |
||
139 | { |
||
140 | grx_line(JET_DUMMY_X-40,JET_DUMMY_Y-15,JET_DUMMY_X+200,JET_DUMMY_Y-15, redorange); |
||
141 | grx_text("Mean Max Name Slide", JET_DUMMY_X-40, JET_Y_NAME, gray, black); |
||
142 | grx_line(JET_DUMMY_X-40,JET_Y_NAME+10,JET_DUMMY_X+200,JET_Y_NAME+10,lime); |
||
143 | grx_rect(JET_DUMMY_X-1, JET_DUMMY_Y-1, |
||
144 | JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, lime); |
||
145 | grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, lime, black); |
||
146 | grx_text(" 0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, lime, black); |
||
147 | } |
||
148 | |||
149 | /////////////////////////////////////// |
||
150 | void init_jetcontrol(void) |
||
151 | { |
||
152 | SOFT_TASK_MODEL m3, m4, m5; |
||
153 | |||
154 | PID p3, p4, p5; |
||
155 | |||
156 | soft_task_default_model(m3); |
||
157 | soft_task_def_level(m3,1); |
||
158 | soft_task_def_period(m3, PERIOD_JETCTRL); |
||
159 | soft_task_def_met(m3, WCET_JETCTRL); |
||
160 | soft_task_def_ctrl_jet(m3); |
||
161 | soft_task_def_group(m3, JET_GROUP); |
||
162 | p3 = task_create("jctrl", jetctrl_task, &m3, NULL); |
||
163 | if (p3 == -1) { |
||
164 | grx_close(); |
||
165 | sys_shutdown_message("Could not create task <jetcontrol> errno=%d", errno); |
||
166 | sys_end(); |
||
167 | } |
||
168 | |||
169 | soft_task_default_model(m4); |
||
170 | soft_task_def_level(m4,1); |
||
171 | soft_task_def_period(m4, PERIOD_JETDUMMY); |
||
172 | soft_task_def_met(m4, WCET_JETDUMMY); |
||
173 | soft_task_def_group(m4, JET_GROUP); |
||
174 | soft_task_def_usemath(m4); |
||
175 | soft_task_def_ctrl_jet(m4); |
||
176 | p4 = task_create("jdmy", jetdummy_task, &m4, NULL); |
||
177 | if (p4 == -1) { |
||
178 | grx_close(); |
||
179 | sys_shutdown_message("Could not create task <jetdummy> errno=%d", errno); |
||
180 | sys_end(); |
||
181 | } |
||
182 | |||
183 | soft_task_default_model(m5); |
||
184 | soft_task_def_level(m5,1); |
||
185 | soft_task_def_period(m5, PERIOD_JETSLIDE); |
||
186 | soft_task_def_met(m5, WCET_JETSLIDE); |
||
187 | soft_task_def_group(m5, JET_GROUP); |
||
188 | soft_task_def_usemath(m5); |
||
189 | soft_task_def_ctrl_jet(m5); |
||
190 | p5 = task_create("jsli", jetslide_task, &m5, NULL); |
||
191 | if (p5 == -1) { |
||
192 | grx_close(); |
||
193 | sys_shutdown_message("Could not create task <jetslide> errno=%d", errno); |
||
194 | sys_end(); |
||
195 | } |
||
196 | } |
||
197 |