Subversion Repositories shark

Rev

Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed

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