Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

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