Blame |
Last modification |
View Log
| RSS feed
// JetControl
#include "demo.h"
#include "kernel/func.h"
TASK jetdummy_task
(void *arg
)
{
TIME now_dummy
, last_dummy
, diff_dummy
, slice
;
struct timespec now
, last
, diff
;
int x
= 0;
int height
;
NULL_TIMESPEC
(&last
);
last_dummy
= 0;
for (;;) {
task_nopreempt
();
jet_getstat
(DUMMY_PID
, NULL
, NULL
, NULL
, &now_dummy
);
sys_gettime
(&now
);
task_preempt
();
SUBTIMESPEC
(&now
, &last
, &diff
);
slice
= diff.
tv_sec * 1000000 + diff.
tv_nsec/1000;
diff_dummy
= now_dummy
- last_dummy
;
height
= (int)(JET_DUMMY_HEIGHT
*((float)diff_dummy
)/((float)slice
));
TIMESPEC_ASSIGN
(&last
, &now
);
last_dummy
= now_dummy
;
mutex_lock
(&mutex
);
grx_line
(JET_DUMMY_X
+x
,JET_DUMMY_Y
,
JET_DUMMY_X
+x
,JET_DUMMY_Y
+height
,black
);
grx_line
(JET_DUMMY_X
+x
,JET_DUMMY_Y
+height
,
JET_DUMMY_X
+x
,JET_DUMMY_Y
+JET_DUMMY_HEIGHT
,white
);
grx_line
(JET_DUMMY_X
+(x
+1)%JET_DUMMY_WIDTH
,JET_DUMMY_Y
,
JET_DUMMY_X
+(x
+1)%JET_DUMMY_WIDTH
,JET_DUMMY_Y
+JET_DUMMY_HEIGHT
,255);
mutex_unlock
(&mutex
);
x
= (x
+1)%JET_DUMMY_WIDTH
;
task_endcycle
();
}
}
TASK jetctrl_task
(void *arg
)
{
char st
[50];
TIME sum
, max
;
int n
;
PID i
;
int printed
= 0;
for (;;) {
for (i
=2, printed
=0; i
<MAX_PROC
&& printed
<JET_NTASK
; i
++) {
if (jet_getstat
(i
, &sum
, &max
, &n
, NULL
) != -1) {
if (!n
) n
=1;
sprintf(st
, "%6d %6d %10s", (int)sum
/n
, (int)max
, proc_table
[i
].
name);
mutex_lock
(&mutex
);
grx_text
(st
, 384, JET_Y_NAME
+16+printed
*8, gray
, black
);
mutex_unlock
(&mutex
);
printed
++;
}
}
while (printed
<JET_NTASK
) {
mutex_lock
(&mutex
);
grx_text
(" ",
384, JET_Y_NAME
+16+printed
*8, gray
, black
);
mutex_unlock
(&mutex
);
printed
++;
}
task_endcycle
();
}
}
TASK jetslide_task
(void *arg
)
{
TIME sum
, curr
, max
;
TIME total
[JET_NTASK
];
int slides
[JET_NTASK
];
PID i
;
int printed
= 0;
for (;;) {
// Fill the total array in a nonpreemptive section
task_nopreempt
();
for (i
=2, printed
=0; i
<MAX_PROC
&& printed
<JET_NTASK
; i
++) {
if (jet_getstat
(i
, &sum
, NULL
, NULL
, &curr
) != -1) {
total
[printed
] = sum
+curr
;
printed
++;
}
}
task_preempt
();
while (printed
< JET_NTASK
)
total
[printed
++] = 0;
// Compute the Max elapsed time
max
= 0;
for (i
=0; i
<JET_NTASK
; i
++)
if (total
[i
] > max
) max
= total
[i
];
if (!max
) max
= 1;
// Compute the slides width
for (i
=0; i
<JET_NTASK
; i
++)
slides
[i
] = (int)( (((float)total
[i
])/max
) * JET_SLIDE_WIDTH
);
// print the data
mutex_lock
(&mutex
);
for (i
=0; i
<JET_NTASK
; i
++) {
grx_box
(JET_SLIDE_X
, JET_Y_NAME
+16+i
*8,
JET_SLIDE_X
+slides
[i
], JET_Y_NAME
+23+i
*8, gray
);
grx_box
(JET_SLIDE_X
+slides
[i
], JET_Y_NAME
+16+i
*8,
JET_SLIDE_X
+JET_SLIDE_WIDTH
, JET_Y_NAME
+23+i
*8, black
);
}
while (i
<JET_NTASK
) {
grx_box
(JET_SLIDE_X
, JET_Y_NAME
+16+i
*8,
JET_SLIDE_X
+JET_SLIDE_WIDTH
, JET_Y_NAME
+20+i
*8, black
);
i
++;
}
mutex_unlock
(&mutex
);
task_endcycle
();
}
}
void scenario_jetcontrol
(void)
{
grx_text
("System load" , 384, 248, rgb16
(0,0,255), black
);
grx_line
(384,258,639,258,red
);
grx_text
(" Mean Max Name Slide", 384, JET_Y_NAME
, gray
, black
);
grx_line
(384,JET_Y_NAME
+10,639,JET_Y_NAME
+10,gray
);
grx_rect
(JET_DUMMY_X
-1, JET_DUMMY_Y
-1,
JET_DUMMY_X
+JET_DUMMY_WIDTH
, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
+1, gray
);
grx_text
("100%", JET_DUMMY_X
-40, JET_DUMMY_Y
, gray
, black
);
grx_text
(" 0%", JET_DUMMY_X
-40, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
-8, gray
, black
);
grx_line
(JET_DUMMY_X
-1, JET_DUMMY_Y
, JET_DUMMY_X
-5, JET_DUMMY_Y
, gray
);
grx_line
(JET_DUMMY_X
-1, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
, JET_DUMMY_X
-5, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
, gray
);
grx_line
(384,258,639,258,red
);
}
void init_jetcontrol
(void)
{
SOFT_TASK_MODEL m3
, m4
, m5
;
PID p3
, p4
, p5
;
soft_task_default_model
(m3
);
soft_task_def_level
(m3
,1);
soft_task_def_period
(m3
, PERIOD_JETCTRL
);
soft_task_def_met
(m3
, WCET_JETCTRL
);
soft_task_def_ctrl_jet
(m3
);
soft_task_def_group
(m3
, 1);
p3
= task_create
("jctrl", jetctrl_task
, &m3
, NULL
);
if (p3
== -1) {
grx_close
();
perror("FFTPlay: Could not create task <jetctrl>\n");
ll_abort
(54);
sys_end
();
}
soft_task_default_model
(m4
);
soft_task_def_level
(m4
,1);
soft_task_def_period
(m4
, PERIOD_JETDUMMY
);
soft_task_def_met
(m4
, WCET_JETDUMMY
);
soft_task_def_group
(m4
, 1);
soft_task_def_usemath
(m4
);
soft_task_def_ctrl_jet
(m4
);
p4
= task_create
("jdmy", jetdummy_task
, &m4
, NULL
);
if (p4
== -1) {
grx_close
();
perror("FFTPlay: Could not create task <jetdummy>\n");
ll_abort
(54);
sys_end
();
}
soft_task_default_model
(m5
);
soft_task_def_level
(m5
,1);
soft_task_def_period
(m5
, PERIOD_JETSLIDE
);
soft_task_def_met
(m5
, WCET_JETSLIDE
);
soft_task_def_group
(m5
, 1);
soft_task_def_usemath
(m5
);
soft_task_def_ctrl_jet
(m5
);
p5
= task_create
("jsli", jetslide_task
, &m5
, NULL
);
if (p5
== -1) {
grx_close
();
perror("FFTPlay: Could not create task <jetslide>\n");
ll_abort
(54);
sys_end
();
}
}