Rev 1120 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
/**
------------
CVS : $Id: perf3.c,v 1.2 2003-01-07 17:10:18 pj Exp $
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2003-01-07 17:10:18 $
------------
Performance Test 3:
this test is based on test D.
the test creates some random events. each event measure the difference
beetween his activation time and thecurrent time.
**/
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
int num_aster
= 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
#define PER_MAX 5
#define APER_MAX 8
#define PER_WCET 8200
#define APER_WCET 20400
#define CLOCK_WCET 1600
#define ASTER_WCET 1600
#define SOFT_MET 3300
#define APER_REP 22000
PID aper_table
[APER_MAX
];
int shutting_down
= 0;
TASK asteroide
(void)
{
int i
;
int y
= rand() % 7 + 1;
int load1
,j
;
char s
[2];
s
[0] = '*'; s
[1] = 0;
for (;;) {
i
= 1;
while (i
< ASTER_LIM
) {
load1
= 10000; //8000 + rand()%2000;
for (j
=0; j
<load1
; j
++) {
s
[0] = '*' + rand() % 100;
puts_xy
(i
,y
,rand()%15+1,s
);
}
task_activate
(aper_table
[rand()%APER_MAX
]);
task_endcycle
();
puts_xy
(i
,y
,WHITE
," ");
i
++;
}
}
//num_aster--;
}
TASK aper_asteroid
(void *a
)
{
int i
;
int y
= rand() % 7 + 1;
int load1
,j
;
int c
;
char s
[2];
c
= (int)a
;
s
[0] = '*'; s
[1] = 0;
for (;;) {
i
= 1;
while (i
< ASTER_LIM
) {
load1
= APER_REP
; //8000 + rand()%2000;
for (j
=0; j
<load1
; j
++) {
s
[0] = '*' + rand() % 100;
puts_xy
(i
,y
,rand()%15+1,s
);
}
s
[0] = c
;
puts_xy
(i
,y
,rand()%15+1,s
);
if (shutting_down
) {
kern_printf
("±%d±",exec_shadow
);
return 0;
}
task_endcycle
();
puts_xy
(i
,y
,WHITE
," ");
i
++;
}
}
}
TASK soft_aster
(void)
{
int i
;
int y
= rand() % 7 + 1;
int load1
,j
;
char s
[2];
s
[0] = '*'; s
[1] = 0;
/*for (;;)*/ {
i
= 1;
while (i
< ASTER_LIM
) {
load1
= 1000 + rand()%9000;
for (j
=0; j
<load1
; j
++) {
s
[0] = '*' + rand() % 100;
puts_xy
(i
,y
,rand()%15+1,s
);
}
s
[0] = 1;
puts_xy
(i
,y
,rand()%15+1,s
);
task_activate
(aper_table
[rand()%APER_MAX
]);
task_endcycle
();
puts_xy
(i
,y
,WHITE
," ");
i
++;
}
}
num_aster
--;
return 0;
}
TASK aster
()
{
PID p
;
HARD_TASK_MODEL m
;
SOFT_TASK_MODEL m_soft
;
int r
;
int x
; // adaptive bandwidth...
srand(7);
hard_task_default_model
(m
);
hard_task_def_wcet
(m
,PER_WCET
);
hard_task_def_ctrl_jet
(m
);
for (x
=0; x
<PER_MAX
; x
++) {
r
= (rand() % 200);
hard_task_def_mit
(m
, (64+r
)*1000);
p
= task_create
("per",asteroide
,&m
,NULL
);
if (p
!=-1) task_activate
(p
);
}
soft_task_default_model
(m_soft
);
soft_task_def_met
(m_soft
,SOFT_MET
);
soft_task_def_ctrl_jet
(m_soft
);
x
= 64;
while (1) {
if (num_aster
< ASTER_MAX
) {
r
= (rand() % 200);
soft_task_def_period
(m_soft
, (x
+r
)*1000);
p
= task_create
("aaa",soft_aster
,&m_soft
,NULL
);
if (p
== -1)
{
if (x
< 500 && errno
!= ENO_AVAIL_TASK
) x
+= 1;
printf_xy
(62,3,WHITE
,"adapt=%3u err=%d",
iq_query_first
(&freedesc
), errno
);
}
else {
num_aster
++;
printf_xy
(62,3,WHITE
,"adapt=%3u ",x
);//,errno);
task_activate
(p
);
x
/= 2;
if (x
<50) x
= 50;
}
}
task_endcycle
();
}
}
TASK
clock()
{
int s
= 0, m
= 0;
while(1) {
printf_xy
(62,1,WHITE
,"%2d:%2d ast=%d",m
,s
, num_aster
);
printf_xy
(62,2,WHITE
,"Uedf=%12u",EDF_usedbandwidth
(0));
printf_xy
(62,4,WHITE
,"Ucbs=%12u",CBS_usedbandwidth
(4));
task_endcycle
();
if (++s
> 59) {
s
= 0;
m
++;
}
printf_xy
(62,1,WHITE
,"%2d:%2d ast=%d",m
,s
, num_aster
);
printf_xy
(62,2,WHITE
,"Uedf=%12u",EDF_usedbandwidth
(0));
printf_xy
(62,4,WHITE
,"Ucbs=%12u",CBS_usedbandwidth
(4));
task_endcycle
();
}
}
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
and plot on the screen the elapsed times... */
TASK jetcontrol
()
{
int i
; /* a counter */
TIME sum
, max
, curr
, last
[5];
int nact
;
int j
; /* the elements set by jet_gettable */
PID p
;
kern_cli
();
printf_xy
(0,STAT_Y
,WHITE
,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
kern_sti
();
for (;;) {
for (i
=0,p
=0; i
<DISPLAY_MAX
+5 && p
<MAX_PROC
; p
++) {
if (jet_getstat
(p
, &sum
, &max
, &nact
, &curr
) == -1 ||
((proc_table
[p
].
pclass & 0xFF00) == HARD_PCLASS
)) continue;
for (j
=0; j
<5; j
++) last
[j
] = 0;
jet_gettable
(p
, &last
[0], 5);
kern_cli
();
if (proc_table
[p
].
task_level == 4)
printf_xy
(0,STAT_Y
+i
+1,WHITE
,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p
, (int)sum
/(nact
==0 ? 1 : nact
), (int)max
, nact
, (int)CBS_get_nact
(4,p
), (int)last
[0], (int)last
[1], (int)last
[2], (int)last
[3], (int)last
[4]);
else
printf_xy
(0,STAT_Y
+i
+1,WHITE
,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p
, (int)sum
/(nact
==0 ? 1 : nact
), (int)max
, nact
, (int)curr
, (int)last
[0], (int)last
[1], (int)last
[2], (int)last
[3], (int)last
[4]);
kern_sti
();
i
++;
}
}
}
void fine
()
{
sys_end
();
}
void exiting
(void *arg
)
{
kern_printf
("EXITING");
shutting_down
= 1;
}
struct timespec last_random_time
;
TIME max
=0;
TIME sum
=0;
int n
=0;
void random_event
(void *arg
)
{
struct timespec t
, sub
;
TIME delta
;
// get the current time
kern_gettime
(&t
);
// compute the delta
SUBTIMESPEC
(&t
, &last_random_time
, &sub
);
delta
= TIMESPEC2USEC
(&sub
);
// update the statistics
if (max
< delta
) max
= delta
;
sum
+= delta
;
n
++;
/* kern_printf("sub=%d.%d t=%d.%d last=%d.%d °\n",sub.tv_sec, sub.tv_nsec/1000,
t.tv_sec, t.tv_nsec/1000,
last_random_time.tv_sec, last_random_time.tv_nsec/1000);
*/ //return;
// create a new event
if (shutting_down
)
return;
delta
= (rand()%30000)+100;
ADDUSEC2TIMESPEC
(delta
, &t
);
TIMESPEC_ASSIGN
(&last_random_time
, &t
);
kern_event_post
(&last_random_time
, random_event
, NULL
);
}
void perftest_printdata
(void *arg
)
{
kern_printf
("\n°°° max=%ld sum=%ld n=%d °°°",max
,sum
,n
);
}
int main
(int argc
, char **argv
)
{
PID p2
; //p1,p3; //,p4,p5,p6;
HARD_TASK_MODEL m
;
// NRT_TASK_MODEL m_nrt;
// SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft
;
int i
;
struct timespec fineprg
;
sys_atrunlevel
(exiting
, NULL
, RUNLEVEL_SHUTDOWN
);
sys_atrunlevel
(perftest_printdata
, NULL
, RUNLEVEL_BEFORE_EXIT
);
kern_printf
("\n\n");
srand(1234);
NULL_TIMESPEC
(&last_random_time
);
i
= rand()%30000+2000;
ADDUSEC2TIMESPEC
(i
, &last_random_time
);
// last_random_time.tv_sec = 2;
// last_random_time.tv_nsec = 0;
kern_cli
();
kern_event_post
(&last_random_time
, random_event
, NULL
);
kern_sti
();
hard_task_default_model
(m
);
hard_task_def_wcet
(m
,ASTER_WCET
);
hard_task_def_mit
(m
,10000);
hard_task_def_group
(m
,1);
hard_task_def_ctrl_jet
(m
);
// nrt_task_default_model(m_nrt);
// nrt_task_def_group(m_nrt,1);
// nrt_task_def_ctrl_jet(m_nrt);
soft_task_default_model
(m_soft
);
soft_task_def_met
(m_soft
,1000);
soft_task_def_period
(m_soft
,100000);
soft_task_def_group
(m_soft
,1);
soft_task_def_ctrl_jet
(m_soft
);
soft_task_def_aperiodic
(m_soft
);
/*
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("test7.c(main): Could not create task <aster> ...");
sys_end();
l1_exit(-1);
}
*/
hard_task_def_mit
(m
,500000);
hard_task_def_wcet
(m
,CLOCK_WCET
);
p2
= task_create
("Clock",clock,&m
,NULL
);
if (p2
== -1) {
perror("test7.c(main): Could not create task <Clock> ...");
sys_end
();
l1_exit
(-1);
}
/*
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
soft_task_default_model(m_aper);
soft_task_def_wcet(m_aper,APER_WCET);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_system(m_aper);
soft_task_def_aperiodic(m_aper);
for (i=0; i<APER_MAX; i++) {
soft_task_def_level(m_aper, i/4 + 2);
soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
if (aper_table[i] == -1) {
perror("test7.c(main): Could not create task <aper> ...");
sys_end();
l1_exit(-1);
}
}
*/
task_nopreempt
();
fineprg.
tv_sec = 6;
fineprg.
tv_nsec = 0;
kern_event_post
(&fineprg
,fine
,NULL
);
group_activate
(1);
return 0;
}