Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1121 → Rev 1085

/demos/branches/pj/oldexamples/makefile
File deleted
/demos/branches/pj/oldexamples/tracer/test0.c
0,0 → 1,71
/*
*
*
*
*/
 
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <sys/mount.h>
 
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
 
#include "common.h"
 
#define FILENAME "/TEMP/ALFA1.TXT"
 
#include <trace/trace.h>
#include <trace/queues.h>
 
int __register_sub_init_prologue(void)
{
TRC_init_phase1(NULL);
trc_register_fixed_queue();
trc_create_queue(TRC_FIXED_QUEUE,NULL);
return 0;
}
 
int main(int argc,char *argv[])
{
int h;
 
showmessage("A file is opened for reading while the tracer\n"
"with a fixed queue is runnig\n");
cprintf("OPENING %s\n",FILENAME);
h=open(FILENAME,O_RDONLY);
if (h>=0) {
char buffer[128];
int len;
cprintf("OPENED!\n");
 
cprintf("READING...\n");
len=read(h,buffer,sizeof(buffer));
cprintf("READ %i bytes\n",len);
memset(buffer,'\0',sizeof(buffer));
cprintf("buffer='%s'\n",buffer);
 
cprintf("READING...\n");
len=read(h,buffer,sizeof(buffer));
cprintf("READ %i bytes\n",len);
memset(buffer,'\0',sizeof(buffer));
cprintf("buffer='%s'\n",buffer);
 
close(h);
} else
cprintf("FAILED!\n");
waitend();
return 0;
}
/demos/branches/pj/oldexamples/tracer/hello.c
0,0 → 1,209
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Massimiliano Giorgi <massy@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
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* 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
*
*/
 
/*
* CVS : $Id: hello.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1.1.1 $
* Last update: $Date: 2002-09-02 09:37:48 $
*/
 
/*
* Example of tracer initialization.
*/
 
#include <ll/i386/cons.h>
 
#include <kernel/func.h>
#include <kernel/trace.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <trace/trace.h>
#include <trace/queues.h>
 
#include <sys/mount.h>
#include <stddef.h>
 
/*
this example use initfs.c to initialize the system; this file define
the following two function.
__kernel_register_levels__(), must initialize all kernel modules,
it has this structure:
 
{
__register_sub_init_prologue();
 
... modules initialization....
__register_sub_init();
}
 
__init__(void *arg) is called when the first task is created
and must call the main():
 
{
 
... drivers initialization ....
 
__bdev_sub_init();
__fs_sub_init();
 
call_main()
 
}
*/
 
/*
* This function is called before all other modules initialization because
* all modules that need the tracer must follow tracer initialization.
*/
int __register_sub_init_prologue(void)
{
/* the first functions to call... parameters can be passed */
TRC_init_phase1(NULL);
/* all the tracer queues must be registrated (in this case only */
/* a dummy queue is initialized) */
trc_register_dummy_queue();
/* the queues must be created (only one in this example) */
trc_create_queue(TRC_DUMMY_QUEUE,NULL);
/* events can be dispatch to a queue (nothing in this case) */
return 0;
}
 
/*
* This function is called after all other modules initialization
* functions... notjing to do.
*/
int __register_sub_init(void)
{
return 0;
}
 
__dev_t root_device;
__dev_t temp_device;
 
/*
* Now the system is running... we have to initialize the block device
* drivers
*/
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
 
/* This to initialize the block device drivers... a NULL can be passed */
/* to the bdev_init() functions */
bdev_def_showinfo(bdev,FALSE);
bdev_init(&bdev);
 
/* The following phase ca be made in several way: we must decide the */
/* device that we want mount as root... we use the bdev_find_byname() */
/* functions to find a specific device */
root_device=bdev_find_byname("ide/hda1");
if (root_device<0) {
cprintf("can't find root device to mount on /!!!\n");
sys_end();
return -1;
}
 
/* Well, we want a device to mount into /TEMP */
temp_device=bdev_find_byname("ide/hdb3");
if (temp_device<0) {
cprintf("can't find a filesystem to mount on /TEMP!!!\n");
sys_end();
return -1;
}
return 0;
}
 
 
/*
* This is the real filesystem initialization!
*/
int __fs_sub_init(void)
{
FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
extern int libc_initialize(void);
int res;
struct mount_opts opts;
 
/* We set the root device and call the filesystem_init() function */
filesystem_def_rootdevice(fs,root_device);
filesystem_def_fs(fs,FS_MSDOS);
filesystem_def_showinfo(fs,FALSE);
filesystem_init(&fs);
 
/* We must initialize the libC if we use it */
libc_initialize();
 
/* We have choose to mount the second partiotion into the /TEMP */
/* directory with read/write privilegies (this step is not required) */
if (temp_device>=0) {
memset(&opts,0,sizeof(struct mount_opts));
opts.flags=MOUNT_FLAG_RW;
res=mount(temp_device,FS_MSDOS,"/TEMP",&opts);
if (res!=0) {
cprintf("can't mount XXX on /TEMP (errno: %i)\n",errno);
}
}
 
/* NOW we call the tracer initialization phase 2!!! */
/* It must FOLLOW the filesystem initialization... (this function */
/* can be called after the call to filesystem_init() functions but */
/* we do it here because we want be able to write into the /TEMP */
/* directory! */
TRC_init_phase2();
return 0;
}
 
void ctrlc_exit(KEY_EVT *k)
{
sys_end();
}
 
int main(int argc,char *argv[])
{
cprintf("\nHello, world!\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/sa.c
0,0 → 1,81
 
#include <netinet/in.h>
 
#include <stdlib.h>
#include <stdio.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
/* distribuzione del delta schedule_time - arrival_time */
 
#define MAXX 50
#define PREC 100
#define DELTA ((double)MAXX/(double)PREC)
 
#include "distr.c"
 
int task;
long a=-1;
long s;
 
int safunc(trc_event_t *ev)
{
if (event_class(ev->event)!=TRC_CLASS_SYSTEM) return 0;
if (ev->x.sys.task!=task) return 0;
 
if (a==-1) {
if (ev->event==TRC_ACTIVATE||ev->event==TRC_INTACTIVATION)
a=ev->time;
} else {
if (ev->event==TRC_SCHEDULE) {
s=ev->time;
d_insert(s-a);
a=-1;
}
}
return 0;
}
 
/* -- */
 
int main(int argc, char *argv[])
{
int res;
if (argc!=4) {
fprintf(stderr,"usage: sa [tracefile] [pid] [outputfile]\n");
return -1;
}
 
d_init();
 
task=atoi(argv[2]);
res=read_trace(argv[1],safunc);
 
if (res==0) {
FILE *fout;
fout=fopen(argv[3],"wt");
if (fout==NULL) {
fprintf(stderr,"error writing output file!\n");
return 0;
}
d_dump(fout);
fclose(fout);
}
 
if (res!=0) {
fprintf(stderr,"error=%i\n",res);
perror("ERROR");
}
 
return 0;
}
 
 
 
 
 
 
 
/demos/branches/pj/oldexamples/tracer/wait.c
0,0 → 1,56
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
/* distribuzione dei tempi di attesa sulle richieste al disco */
 
#define MAXX 37000
#define PREC 37000
#define DELTA ((double)MAXX/(double)PREC)
 
#include "distr.c"
 
int task;
long a=-1;
 
int waitfunc(trc_event_t *ev)
{
if (event_class(ev->event)!=TRC_CLASS_USER) return 0;
if (ev->x.usr.n!=task) return 0;
if (ev->event==TRC_USER1) {
a=ev->time;
return 0;
}
if (ev->event==TRC_USER2) {
if (a!=-1) d_insert(ev->time-a);
a=-1;
}
return 0;
}
 
int main(int argc, char *argv[])
{
FILE *fout;
int res;
if (argc!=4) {
fprintf(stderr,"missing filename!\n");
return -1;
}
d_init();
task=atoi(argv[2]);
res=read_trace(argv[1],waitfunc);
if (res==0) {
fout=fopen(argv[3],"wt");
if (fout!=NULL) {
d_dump(fout);
fclose(fout);
} else
fprintf(stderr,"can't create output file!\n");
} else
fprintf(stderr,"read_trace error\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/types.h
0,0 → 1,13
#ifndef __TYPES_H__
#define __TYPES_H__
 
#include <sys/types.h>
 
typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned long u_int32_t;
 
#include <types.h>
 
#endif
 
/demos/branches/pj/oldexamples/tracer/util.c
0,0 → 1,122
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
 
#include "types.h"
#include <trace.h>
#include <types.h>
 
static char *names[]={
"reserved",
"hoops",
/*--*/
"create",
"activate",
"schedule",
"delay",
"sleep",
"endcycle",
"destroy",
"intactiv",
/*--*/
"user0",
"user1",
"user2",
"user3",
"user4",
"user5",
"user6",
"user7",
/*--*/
"wait",
"waitnb",
"signal"
};
 
int classtable[TRC_NUMCLASSES+1]={
TRC_F_TRACER,
TRC_F_SYSTEM,
TRC_F_USER,
TRC_F_SEM,
TRC_F_LAST
};
 
int event_class(int ev)
{
int i;
if (ev<0||ev>=TRC_NUMEVENTS) return -1;
for (i=0;i<TRC_NUMCLASSES;i++)
if (ev>=classtable[i]&&ev<classtable[i+1]) return i;
return -1;
}
 
char *event_name(int ev)
{
if (ev<0||ev>=TRC_NUMEVENTS) return "unknown";
return names[ev];
}
 
char *event_hexdump(u_int8_t *ptr,int maxsize)
{
static char buffer[256];
int i;
for (i=0;i<maxsize;i++) sprintf(buffer+i*2,"%02x",*(ptr+i));
buffer[maxsize*2]='\0';
return buffer;
}
 
char *event_strdump(u_int8_t *ptr, int maxsize)
{
static char buffer[256];
memcpy(buffer,ptr,maxsize);
buffer[maxsize]='\0';
return buffer;
}
 
 
char *format_time(long time)
{
static char buffer[256];
if (time<1000l) {
sprintf(buffer,"%li",time);
return buffer;
}
if (time<1000000l) {
sprintf(buffer,"%li,%03li",time/1000l,time%1000l);
return buffer;
}
sprintf(buffer,"%li,%03li,%03li",
(time/1000000l),
(time%1000000l)/1000l,
time%1000l);
return buffer;
}
 
#ifndef O_BINARY
#define O_BINARY 0
#endif
 
int read_trace(char *filename,int (*func)(trc_event_t *))
{
trc_event_t buffer;
int fin;
int res;
fin=open(filename,O_RDONLY|O_BINARY);
if (fin==-1) return -1;
for (;;) {
res=read(fin,&buffer,sizeof(trc_event_t));
if (res!=sizeof(trc_event_t)) {
close(fin);
return res==0?0:-2;
}
res=(*func)(&buffer);
if (res!=0) {
close(fin);
return res;
}
}
close(fin);
return 0;
}
/demos/branches/pj/oldexamples/tracer/jdump.c
0,0 → 1,465
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Massimiliano Giorgi <massy@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
*/
 
/*
* Copyright (C) 1999 Massimiliano Giorgi
*
* 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
*
*/
 
/*
* CVS : $Id: jdump.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1.1.1 $
* Last update: $Date: 2002-09-02 09:37:48 $
*/
 
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
 
#include "types.h"
#include <trace.h>
#include "util.h"
 
/*
*
*
*
*/
 
/* All times are dived by this costant. */
#define TIMESCALE 1
 
/* If defined dump on stdout the packets (in ascii) that will be written
* on the output file (the file of the tracer).
*/
 
#define DUMPOUT
 
/*
*
*
*
*/
 
int pippo=0;
 
int writeInt(int h, int x)
{
int y,res;
y=htonl(x);
res=write(h,&y,sizeof(int));
return res!=sizeof(int);
}
 
 
int writeStr(int h, char *s)
{
int res,size;
size=strlen(s);
writeInt(h,size);
res=write(h,s,size);
return res!=size;
}
 
/*
*
*/
 
#define TASK_ARRIVAL 0
#define TASK_SCHEDULE 1
#define TASK_DESCHEDULE 2
#define TASK_END 3
#define TASK_DLINEPOST 4
#define TASK_DLINESET 5
#define TASK_WAIT 6
#define TASK_SIGNAL 7
#define TASK_IDLE 8
#define TASK_NAME 9
 
#define EVT_NUMBER 10
 
char *eventsname[]={
"task_arrival",
"task_schedule",
"task_deschedule",
"task_end",
"task_dlinepost",
"task_dlineset",
"task_wait",
"task_signal",
"task_idle",
"task_name"
};
 
struct j_evt_prolog {
int type;
int time;
};
 
struct j_evt_task {
struct j_evt_prolog p;
int task;
};
 
struct j_evt_dlinepost {
struct j_evt_task t;
int taskD;
int taskD2;
};
 
struct j_evt_dlineset {
struct j_evt_task t;
int taskD;
};
 
struct j_evt_semaph {
struct j_evt_task t;
int res;
char *name;
};
 
struct j_evt_name {
struct j_evt_task t;
char *name;
};
 
/*
*
*/
 
int j_write_prolog(int h, void *ptr)
{
#ifdef DUMPOUT
printf("%10i ",((struct j_evt_prolog *)ptr)->time);
printf("%-18s ",eventsname[((struct j_evt_prolog *)ptr)->type]);
#endif
if (writeInt(h,((struct j_evt_prolog *)ptr)->type)) return -2;
if (writeInt(h,((struct j_evt_prolog *)ptr)->time)) return -3;
return 0;
}
 
int j_write_task(int h, void *ptr)
{
int res;
res=j_write_prolog(h,ptr);
#ifdef DUMPOUT
printf("tsk=%i ",((struct j_evt_task *)ptr)->task);
#endif
if (res) return res;
if (writeInt(h,((struct j_evt_task *)ptr)->task)) return -4;
return 0;
}
 
int j_write_dlinepost(int h, void *ptr)
{
int res;
res=j_write_task(h,ptr);
if (res) return res;
if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD)) return -5;
if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD2)) return -6;
return 0;
}
 
int j_write_dlineset(int h, void *ptr)
{
int res;
res=j_write_task(h,ptr);
if (res) return res;
if (writeInt(h,((struct j_evt_dlineset *)ptr)->taskD)) return -7;
return 0;
}
 
int j_write_semaph(int h, void *ptr)
{
int res;
res=j_write_task(h,ptr);
if (res) return res;
if (writeInt(h,((struct j_evt_semaph *)ptr)->res)) return -8;
if (writeStr(h,((struct j_evt_semaph *)ptr)->name)) return -9;
return 0;
}
 
int j_write_name(int h, void *ptr)
{
int res;
res=j_write_task(h,ptr);
#ifdef DUMPOUT
printf("name='%s' ",((struct j_evt_name *)ptr)->name);
#endif
if (res) return res;
if (writeStr(h,((struct j_evt_name *)ptr)->name)) return -10;
return 0;
}
int writeEvent(int h, void *ptr)
{
int res;
//printf("<%i>",((struct j_evt_prolog*)ptr)->type);
((struct j_evt_prolog*)ptr)->time/=TIMESCALE;
 
switch(((struct j_evt_prolog*)ptr)->type) {
case TASK_ARRIVAL:
case TASK_SCHEDULE:
case TASK_DESCHEDULE:
case TASK_END:
case TASK_IDLE:
res=j_write_task(h,ptr);
break;
case TASK_DLINEPOST:
res=j_write_dlinepost(h,ptr);
break;
case TASK_DLINESET:
res=j_write_dlineset(h,ptr);
break;
case TASK_WAIT:
case TASK_SIGNAL:
res=j_write_semaph(h,ptr);
break;
case TASK_NAME:
res=j_write_name(h,ptr);
break;
default:
return -1;
}
 
#ifdef DUMPOUT
printf(" \n");
#endif
 
return res;
}
 
/*
*
*
*
*/
 
#define MAX_PROC 150
 
//int activated[MAX_PROC];
 
int cxx=0;
/* write MAXC-1 events */
#define MAXC 14
 
long lasttime;
 
int sys_event(int h, void *param)
{
static int prevtask=-1;
trc_event_t *ptr=(trc_event_t *)param;
struct j_evt_task evt;
 
evt.p.time=ptr->time;
evt.task=ptr->x.sys.task;
 
lasttime=ptr->time;
switch(ptr->event) {
case TRC_CREATE:
return 0;
 
case TRC_ACTIVATE:
case TRC_INTACTIVATION:
 
 
//activated[ptr->x.sys.task]=1;
 
 
evt.p.type=TASK_ARRIVAL;
break;
case TRC_DESTROY:
 
 
//activated[ptr->x.sys.task]=0;
 
 
 
return 0;
case TRC_DELAY:
prevtask=-1;
evt.p.type=TASK_DESCHEDULE;
break;
case TRC_SLEEP:
prevtask=-1;
evt.p.type=TASK_DESCHEDULE;
break;
case TRC_ENDCYCLE:
evt.p.type=TASK_END;
break;
 
case TRC_SCHEDULE:
if (prevtask!=-1) {
struct j_evt_task evt2;
int res;
evt2.p.time=ptr->time;
evt2.p.type=TASK_DESCHEDULE;
evt2.task=prevtask;
res=writeEvent(h,&evt2);
if (res!=0) return -1;
}
 
/*
if (!activated[ptr->x.sys.task]) {
struct j_evt_task evt2;
 
evt2.p.time=ptr->time-1;
evt2.task=ptr->x.sys.task;
evt2.p.type=TASK_ARRIVAL;
 
writeEvent(h,&evt2);
activated[ptr->x.sys.task]=1;
}
*/
 
evt.p.type=TASK_SCHEDULE;
prevtask=ptr->x.sys.task;
break;
 
default:
return 0;
}
 
cxx++;
if (cxx==MAXC) return -1;
 
return writeEvent(h,&evt);
}
 
 
int sem_event(int h,void *param)
{
//trc_event_t *ptr=(trc_event_t *)param;
//struct j_evt_semaph evt;
 
return 0;
/*
evt.t.p.time=ptr->x.norm.when;
evt.t.task=ptr->x.norm.who;
switch(ptr->what) {
case TRC_SEM_WAIT: evt.t.p.type=TASK_WAIT; break;
case TRC_SEM_SIGNAL: evt.t.p.type=TASK_SIGNAL; break;
case TRC_SEM_WAITNB: return 0;
default: return 0;
}
evt.res=1;
evt.name="NoName";
return j_write_semaph(h,&evt);
*/
}
 
/* -- */
 
#define MAX_PROC 150
int names[MAX_PROC];
 
int outfile;
 
int dumpfunc(trc_event_t *ptr)
{
//printf("{%i}",ptr->event);
 
if (!names[ptr->x.sys.task]) {
struct j_evt_name evtname;
static char name[24];
 
cxx++;
if (cxx==MAXC) return -1;
evtname.t.p.time=lasttime;
evtname.t.task=ptr->x.sys.task;
evtname.t.p.type=TASK_NAME;
sprintf(name,"task%03i",ptr->x.sys.task);
evtname.name=name;
writeEvent(outfile,&evtname);
names[ptr->x.sys.task]=1;
 
}
 
switch(event_class(ptr->event)) {
case TRC_CLASS_SYSTEM:
return sys_event(outfile,ptr);
case TRC_CLASS_SEM:
return 0;
return sem_event(outfile,ptr);
case TRC_CLASS_USER:
return 0;
}
return 0;
}
 
/*
*
*/
 
#ifndef O_BINARY
#define O_BINARY 0
#endif
 
int main(int argc, char *argv[])
{
int res;
int i;
 
if (argc!=3) {
fprintf(stderr,"missing filenames\n");
fprintf(stderr,"usage: jdump H4tracefilename JTRACERtracefilename\n");
return -1;
}
 
for (i=0;i<MAX_PROC;i++) {
names[i]=0;
//activated[i]=0;
}
 
outfile=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0777);
if (outfile==-1) {
perror("can't open outfile");
return -1;
}
res=read_trace(argv[1],dumpfunc);
close(outfile);
//fprintf(stderr,"result=%i",res);
return 0;
}
/demos/branches/pj/oldexamples/tracer/util.h
0,0 → 1,17
 
#ifndef __UTIL_H
#define __UTIL_H
 
#include "types.h"
 
char *event_name(int evt);
char *event_hexdump(u_int8_t *ptr, int maxsize);
char *event_strdump(u_int8_t *ptr, int maxsize);
int event_class(int evt);
 
int read_trace(char *filename,int (*func)(trc_event_t *));
 
char *format_time(long time);
 
#endif
/demos/branches/pj/oldexamples/tracer/treec1.c
0,0 → 1,211
/*
*
*
*
*/
 
#include <kernel/func.h>
#include <kernel/model.h>
 
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <semaphore.h>
#include <stdio.h>
 
#include "common.h"
 
#include <trace/trace.h>
#include <trace/queues.h>
 
 
int noscroll=0;
SEM console;
 
#define MPROC ((50<(MAX_PROC-10))?50:MAX_PROC-10)
 
TASK viewdir(void *prof);
sem_t actmutex,actsync;
char *globpathname;
PID globpid;
int counter=0,actcounter=0;
 
void activate_task(int prof, char *pathname)
{
char tname[32];
NRT_TASK_MODEL m;
PID pid;
 
REPEAT:
sem_wait(&actmutex);
 
if (actcounter>=MPROC) {
sem_signal(&actmutex);
task_delay(10000);
goto REPEAT;
}
globpathname=pathname;
counter++;
sprintf(tname,"tsk%i",counter);
 
nrt_task_default_model(m);
nrt_task_def_arg(m,(void*)counter);
globpid=pid=task_create(tname,viewdir,&m,NULL);
if (pid==-1) {
sem_wait(&console);
cprintf("can't create '%s'\n",tname);
perror("can't create task");
sem_signal(&console);
sys_end();
return;
}
task_activate(pid);
sem_wait(&actsync);
actcounter++;
 
sem_signal(&actmutex);
}
 
/*
*
*/
 
int filecounter=0;
 
TASK viewdir(void *pointer)
{
struct dirent *den;
struct stat st;
char *str;
DIR *d;
int res;
int x;
char pathname[1024];
PID mypid;
int prof=(int)pointer;
 
strcpy(pathname,globpathname);
mypid=globpid;
sem_signal(&actsync);
 
str=pathname+(x=strlen(pathname));
d=opendir(pathname);
if (d==NULL) {
sem_wait(&console);
cprintf("%03i ERR: can't open dir %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
goto END;
}
 
while ((den=readdir(d))!=NULL) {
 
if (x==1&&*pathname=='/')
strcat(pathname,den->d_name);
else
strcat(strcat(pathname,"/"),den->d_name);
 
sem_wait(&console);
if (noscroll) {
place(0,10);
cprintf(" ");
place(0,10);
}
cprintf("t%03i %s\n",prof,pathname);
filecounter++;
sem_signal(&console);
 
if (!strcmp(den->d_name,".")) goto SKIP;
if (!strcmp(den->d_name,"..")) goto SKIP;
 
res=stat(pathname,&st);
if (res!=0) {
sem_wait(&console);
cprintf("t%03i can't stat %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
closedir(d);
goto END;
} else {
if (S_ISDIR(st.st_mode)) {
sem_wait(&console);
sem_signal(&console);
activate_task(prof,pathname);
}
}
 
SKIP:
*str='\0';
}
 
closedir(d);
 
END:
sem_wait(&actmutex);
actcounter--;
sem_signal(&actmutex);
 
return 0;
}
 
/*
*
*/
 
int __register_sub_init_prologue(void)
{
TRC_init_phase1(NULL);
trc_register_circular_queue();
trc_create_queue(TRC_CIRCULAR_QUEUE,NULL);
return 0;
}
 
/*
*
*/
 
int main(int argc,char *argv[])
{
// int res;
 
showmessage("This test show all filenames of a directory of an hardisk\n"
"recursively using a soft task for every directory.\n"
"The tracer with a circular queue is activated.\n");
 
sem_init(&console,0,1);
sem_init(&actmutex,0,1);
sem_init(&actsync,0,0);
 
activate_task(-1,FROMDIR);
 
for(;;) {
sem_wait(&actmutex);
if (actcounter==0) break;
sem_signal(&actmutex);
task_delay(500000);
}
 
cprintf("\nfiles: %i\n",filecounter);
waitend();
return 0;
}
/demos/branches/pj/oldexamples/tracer/treec2.c
0,0 → 1,224
/*
*
*
*
*/
 
#include <kernel/func.h>
#include <kernel/model.h>
 
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <semaphore.h>
#include <stdio.h>
 
#include "common.h"
 
#include <trace/trace.h>
#include <trace/queues.h>
 
#define sem_signal sem_post
 
int noscroll=0;
SEM console;
 
#define MPROC ((50<(MAX_PROC-10))?50:MAX_PROC-10)
 
TASK viewdir(void *prof);
sem_t actmutex,actsync;
char *globpathname;
PID globpid;
int counter=0,actcounter=0;
 
void activate_task(int prof, char *pathname)
{
char tname[32];
NRT_TASK_MODEL m;
PID pid;
 
REPEAT:
sem_wait(&actmutex);
 
if (actcounter>=MPROC) {
sem_signal(&actmutex);
task_delay(10000);
goto REPEAT;
}
globpathname=pathname;
counter++;
sprintf(tname,"tsk%i",counter);
 
nrt_task_default_model(m);
nrt_task_def_arg(m,(void*)counter);
globpid=pid=task_create(tname,viewdir,&m,NULL);
if (pid==-1) {
sem_wait(&console);
cprintf("can't create '%s'\n",tname);
perror("can't create task");
sem_signal(&console);
sys_end();
return;
}
task_activate(pid);
sem_wait(&actsync);
actcounter++;
 
sem_signal(&actmutex);
}
 
/*
*
*/
 
int filecounter=0;
 
TASK viewdir(void *pointer)
{
struct dirent *den;
struct stat st;
char *str;
DIR *d;
int res;
int x;
char pathname[1024];
PID mypid;
int prof=(int)pointer;
 
strcpy(pathname,globpathname);
mypid=globpid;
sem_signal(&actsync);
 
str=pathname+(x=strlen(pathname));
d=opendir(pathname);
if (d==NULL) {
sem_wait(&console);
cprintf("%03i ERR: can't open dir %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
goto END;
}
 
while ((den=readdir(d))!=NULL) {
 
if (x==1&&*pathname=='/')
strcat(pathname,den->d_name);
else
strcat(strcat(pathname,"/"),den->d_name);
 
sem_wait(&console);
if (noscroll) {
place(0,10);
cprintf(" ");
place(0,10);
}
cprintf("t%03i %s\n",prof,pathname);
filecounter++;
sem_signal(&console);
 
if (!strcmp(den->d_name,".")) goto SKIP;
if (!strcmp(den->d_name,"..")) goto SKIP;
 
res=stat(pathname,&st);
if (res!=0) {
sem_wait(&console);
cprintf("t%03i can't stat %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
closedir(d);
goto END;
} else {
if (S_ISDIR(st.st_mode)) {
sem_wait(&console);
sem_signal(&console);
activate_task(prof,pathname);
}
}
 
SKIP:
*str='\0';
}
 
closedir(d);
 
END:
sem_wait(&actmutex);
actcounter--;
sem_signal(&actmutex);
 
return 0;
}
 
/*
*
*/
 
int __register_sub_init_prologue(void)
{
TRC_CIRCULAR_PARMS args;
int q;
TRC_init_phase1(NULL);
trc_register_circular_queue();
trc_circular_default_parms(args);
trc_circular_def_onlinetask(args);
q=trc_create_queue(TRC_CIRCULAR_QUEUE,&args);
 
trc_assign_class_to_queue(TRC_CLASS_SYSTEM,q);
trc_trace_class(TRC_CLASS_SYSTEM);
return 0;
}
 
/*
*
*/
 
int main(int argc,char *argv[])
{
// int res;
 
showmessage("This test show all filenames of a directory of an hardisk\n"
"recursively using a soft task for every directory.\n"
"The tracer with a circular queue is activated that write\n"
"on hardisk online (while the system is running)\n");
 
sem_init(&console,0,1);
sem_init(&actmutex,0,1);
sem_init(&actsync,0,0);
 
activate_task(-1,FROMDIR);
//activate_task(-1,"/");
 
for(;;) {
sem_wait(&actmutex);
if (actcounter==0) break;
sem_signal(&actmutex);
task_delay(500000);
}
 
cprintf("\nfiles: %i\n",filecounter);
waitend();
return 0;
}
/demos/branches/pj/oldexamples/tracer/hello1.c
0,0 → 1,27
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <stddef.h>
 
#include <trace/trace.h>
#include <trace/queues.h>
 
int __register_sub_init_prologue(void)
{
TRC_init_phase1(NULL);
trc_register_dummy_queue();
trc_create_queue(TRC_DUMMY_QUEUE,NULL);
return 0;
}
 
int main(int argc,char *argv[])
{
cprintf("\nHello, world!\n");
cprintf("The tracer has been activated!\n");
cprintf("(No result are produced)\n\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/distr.c
0,0 → 1,44
 
long t[PREC];
long counter;
long hoops;
long maxv=0;
 
void d_init(void)
{
int i;
hoops=counter=0;
for (i=0;i<PREC;i++) t[i]=0;
}
 
void d_insert(long d)
{
if (d>=MAXX) {
hoops++;
if (d>maxv) maxv=d;
return;
}
 
counter++;
t[(int)(d/DELTA)]++;
}
 
void d_dump(FILE *fout)
{
int i;
 
if (counter==0) {
fprintf(stderr,"nothing to write to the output file\n");
return;
}
if (hoops) {
fprintf(stderr,"%li values to big (max=%li)\n",hoops,maxv);
}
for (i=0;i<PREC;i++)
fprintf(fout,"%f %f\n",
DELTA/2.0+DELTA*i,
(double)t[i]/(double)counter
);
}
/demos/branches/pj/oldexamples/tracer/road.c
0,0 → 1,57
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
 
/* distribuzione degli spostamenti della testina */
 
#define MAXX 1000
#define PREC 1000
#define DELTA ((double)MAXX/(double)PREC)
 
#include "distr.c"
 
int dumpusr(int event, trc_user_event_t *usr)
{
static long last=-1;
long d;
if (event!=TRC_USER0) return 0;
if (last!=-1) {
d=abs(last-usr->n);
d_insert(d);
}
last=usr->n;
return 0;
}
 
int dumpfunc(trc_event_t *ev)
{
if (event_class(ev->event)==TRC_CLASS_USER) dumpusr(ev->event,&ev->x.usr);
return 0;
}
 
int main(int argc, char *argv[])
{
FILE *fout;
int res;
if (argc!=3) {
fprintf(stderr,"missing filename!\n");
return -1;
}
d_init();
res=read_trace(argv[1],dumpfunc);
if (res==0) {
fout=fopen(argv[2],"wt");
if (fout!=NULL) {
d_dump(fout);
fclose(fout);
} else
fprintf(stderr,"can't create output file!\n");
} else
fprintf(stderr,"read_trace error\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/hello2.c
0,0 → 1,30
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <stddef.h>
 
#include <trace/trace.h>
#include <trace/queues.h>
 
int __register_sub_init_prologue(void)
{
int q;
TRC_init_phase1(NULL);
trc_register_fixed_queue();
q=trc_create_queue(TRC_FIXED_QUEUE,NULL);
trc_assign_class_to_queue(TRC_CLASS_SYSTEM,q);
trc_trace_class(TRC_CLASS_SYSTEM);
return 0;
}
 
int main(int argc,char *argv[])
{
cprintf("\nHello, world!\n");
cprintf("The tracer has been activated! Look at the results.\n");
cprintf("(A fixed queue has been created)\n\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/treef1.c
0,0 → 1,215
/*
*
*
*
*/
 
#include <kernel/func.h>
#include <kernel/model.h>
 
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <semaphore.h>
#include <stdio.h>
 
#include "common.h"
 
#include <trace/trace.h>
#include <trace/queues.h>
 
#define sem_signal sem_post
 
int noscroll=0;
SEM console;
 
#define MPROC ((50<(MAX_PROC-10))?50:MAX_PROC-10)
 
TASK viewdir(void *prof);
sem_t actmutex,actsync;
char *globpathname;
PID globpid;
int counter=0,actcounter=0;
 
void activate_task(int prof, char *pathname)
{
char tname[32];
NRT_TASK_MODEL m;
PID pid;
 
REPEAT:
sem_wait(&actmutex);
 
if (actcounter>=MPROC) {
sem_signal(&actmutex);
task_delay(10000);
goto REPEAT;
}
globpathname=pathname;
counter++;
sprintf(tname,"tsk%i",counter);
 
nrt_task_default_model(m);
nrt_task_def_arg(m,(void*)counter);
globpid=pid=task_create(tname,viewdir,&m,NULL);
if (pid==-1) {
sem_wait(&console);
cprintf("can't create '%s'\n",tname);
perror("can't create task");
sem_signal(&console);
sys_end();
return;
}
task_activate(pid);
sem_wait(&actsync);
actcounter++;
 
sem_signal(&actmutex);
}
 
/*
*
*/
 
int filecounter=0;
 
TASK viewdir(void *pointer)
{
struct dirent *den;
struct stat st;
char *str;
DIR *d;
int res;
int x;
char pathname[1024];
PID mypid;
int prof=(int)pointer;
 
strcpy(pathname,globpathname);
mypid=globpid;
sem_signal(&actsync);
 
str=pathname+(x=strlen(pathname));
d=opendir(pathname);
if (d==NULL) {
sem_wait(&console);
cprintf("%03i ERR: can't open dir %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
goto END;
}
 
while ((den=readdir(d))!=NULL) {
 
if (x==1&&*pathname=='/')
strcat(pathname,den->d_name);
else
strcat(strcat(pathname,"/"),den->d_name);
 
sem_wait(&console);
if (noscroll) {
place(0,10);
cprintf(" ");
place(0,10);
}
cprintf("t%03i %s\n",prof,pathname);
filecounter++;
sem_signal(&console);
 
if (!strcmp(den->d_name,".")) goto SKIP;
if (!strcmp(den->d_name,"..")) goto SKIP;
 
res=stat(pathname,&st);
if (res!=0) {
sem_wait(&console);
cprintf("t%03i can't stat %s\n",prof,pathname);
cprintf("errno: %i '%s'\n",errno,strerror(errno));
sem_signal(&console);
 
sys_end();
l1_exit(0);
closedir(d);
goto END;
} else {
if (S_ISDIR(st.st_mode)) {
sem_wait(&console);
sem_signal(&console);
activate_task(prof,pathname);
}
}
 
SKIP:
*str='\0';
}
 
closedir(d);
 
END:
sem_wait(&actmutex);
actcounter--;
sem_signal(&actmutex);
 
return 0;
}
 
/*
*
*/
 
int __register_sub_init_prologue(void)
{
int q;
TRC_init_phase1(NULL);
trc_register_fixed_queue();
q=trc_create_queue(TRC_FIXED_QUEUE,NULL);
trc_assign_class_to_queue(TRC_CLASS_SYSTEM,q);
trc_trace_class(TRC_CLASS_SYSTEM);
return 0;
}
 
/*
*
*/
 
int main(int argc,char *argv[])
{
// int res;
 
showmessage("This test show all filenames of a directory of an hardisk\n"
"recursively using a soft task for every directory.\n"
"The tracer with a circular queue is activated.\n");
 
sem_init(&console,0,1);
sem_init(&actmutex,0,1);
sem_init(&actsync,0,0);
 
activate_task(-1,FROMDIR);
 
for(;;) {
sem_wait(&actmutex);
if (actcounter==0) break;
sem_signal(&actmutex);
task_delay(500000);
}
 
cprintf("\nfiles: %i\n",filecounter);
waitend();
return 0;
}
/demos/branches/pj/oldexamples/tracer/common.c
0,0 → 1,134
 
#include <kernel/func.h>
#include <kernel/trace.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <trace/trace.h>
#include <trace/queues.h>
 
#include <sys/mount.h>
 
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
 
int __register_sub_init(void)
{
return 0;
}
 
/* -- */
 
__dev_t root_device;
__dev_t temp_device;
 
int choose_root_callback(__dev_t dev,__uint8_t fs)
{
if (fs==FS_MSDOS) return dev;
return -1;
}
 
int choose_temp_callback(__dev_t dev,__uint8_t fs)
{
static int flag=0;
if (fs==FS_MSDOS) {
if (flag) return dev;
flag=1;
}
return -1;
}
 
/* -- */
 
extern int bdev_scan_devices(int(*callback)(__dev_t,__uint8_t));
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,FALSE);
bdev_init(&bdev);
 
root_device=bdev_scan_devices(choose_root_callback);
if (root_device<0) {
cprintf("can't find root device to mount on /!!!\n");
sys_end();
return -1;
}
 
temp_device=bdev_scan_devices(choose_temp_callback);
if (temp_device<0) {
cprintf("can't find a filesystem to mount on /TEMP!!!\n");
}
return 0;
}
 
/* -- */
 
extern int libc_initialize(void);
 
int __fs_sub_init(void)
{
FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
struct mount_opts opts;
int res;
filesystem_def_rootdevice(fs,root_device);
filesystem_def_fs(fs,FS_MSDOS);
filesystem_def_showinfo(fs,FALSE);
 
 
//filesystem_init_prologue();
filesystem_init(&fs);
libc_initialize();
 
if (temp_device>=0) {
memset(&opts,0,sizeof(struct mount_opts));
opts.flags=MOUNT_FLAG_RW;
res=mount(temp_device,FS_MSDOS,"/TEMP",&opts);
if (res!=0) {
cprintf("can't mount XXX on /TEMP (errno: %i)\n",errno);
}
}
TRC_init_phase2();
return 0;
}
 
/* -- */
 
void ctrlc_exit(KEY_EVT *k)
{
extern void dump_sem_table(void);
extern void dump_nop_table(void);
//dump_sem_table();
//dump_nop_table();
//sys_status(SCHED_STATUS);
sys_end();
}
 
/* -- */
 
void showmessage(char *s)
{
cputs(s);
cprintf("Press [x] to begin...");
while (keyb_getchar()!='x');
cprintf("\n");
}
 
void waitend(void)
{
int c;
cprintf("Press [x] to exit...");
while ((c=keyb_getchar())!='x');
cprintf("\n");
}
/demos/branches/pj/oldexamples/tracer/tdump.c
0,0 → 1,73
 
#include <netinet/in.h>
 
#include <stdio.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
int dumpsys(trc_system_event_t *sys)
{
/*
if (sys->event==TRC_SCHEDULE) {
//if (sys->prev!=65535)
// printf("%02i->%02i\n",sys->prev,sys->task);
//else
printf("??->%02i\n",sys->task);
return 0;
}
*/
printf("%02i\n",sys->task);
return 0;
}
 
int dumpusr(trc_user_event_t *usr)
{
printf("%8li ",usr->n);
printf("\n");
return 0;
}
 
int dumpsem(trc_sem_event_t *sem)
{
printf("on [%i]\n",sem->id);
return 0;
}
 
int dumpfunc(trc_event_t *ev)
{
static int counter=0;
printf("%4i ",counter);
counter++;
printf("%12s ",format_time(ev->time));
printf("%-10s ",event_name(ev->event));
 
//printf("%08x\n",(unsigned)ev->sys.event);
//return 0;
switch(event_class(ev->event)) {
case TRC_CLASS_SYSTEM: return dumpsys(&ev->x.sys);
case TRC_CLASS_USER: return dumpusr(&ev->x.usr);
case TRC_CLASS_SEM: return dumpsem(&ev->x.sem);
}
printf("\nEVENT %i... CLASS %i UNKNOWN!\n",ev->event,event_class(ev->event));
return -1;
}
 
int main(int argc, char *argv[])
{
int res;
if (argc!=2) {
fprintf(stderr,"missing filename!\n");
return -1;
}
 
res=read_trace(argv[1],dumpfunc);
 
//fprintf(stderr,"result=%i\n",res);
//fprintf(stderr,"size=%li\n",sizeof(trc_event_t));
return 0;
}
/demos/branches/pj/oldexamples/tracer/simple.c
0,0 → 1,132
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Massimiliano Giorgi <massy@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
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* 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
*
*/
 
/*
* CVS : $Id: simple.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1.1.1 $
* Last update: $Date: 2002-09-02 09:37:48 $
*/
 
/*
* Example of simple tracer initialization.
*/
 
#include <ll/i386/cons.h>
 
#include <kernel/func.h>
#include <kernel/trace.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <trace/trace.h>
 
#include <sys/mount.h>
#include <stddef.h>
 
#define ROOTDEVICE "ide/hda2"
 
int __register_sub_init_prologue(void)
{
int res;
/* tracer initialization phase 1 */
res=TRC_init_phase1_standard();
if (res!=0) {
cprintf("tracer initialization error (%i)!!!\n",res);
sys_end();
return -1;
}
return 0;
}
 
int __register_sub_init(void)
{
return 0;
}
 
__dev_t root_device;
 
int __bdev_sub_init(void)
{
/* block device initialization */
bdev_init(NULL);
 
/* choose root device */
root_device=bdev_find_byname(ROOTDEVICE);
if (root_device<0) {
cprintf("can't find root device to mount on /!!!\n");
sys_end();
return -1;
}
 
return 0;
}
 
int __fs_sub_init(void)
{
FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
extern int libc_initialize(void);
 
/* filesystems initialization */
filesystem_def_rootdevice(fs,root_device);
filesystem_def_fs(fs,FS_MSDOS);
filesystem_def_showinfo(fs,FALSE);
filesystem_init(&fs);
 
/* libC initialization */
libc_initialize();
 
/* tracer initialization phase 2 */
TRC_init_phase2_standard();
return 0;
}
 
void ctrlc_exit(KEY_EVT *k)
{
sys_end();
}
 
int main(int argc,char *argv[])
{
cprintf("\nSimple hello world (with tracer)!\n\n");
return 0;
}
/demos/branches/pj/oldexamples/tracer/makefile
0,0 → 1,69
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS= simple hello hello1 hello2 test0 treef1 treec1 treec2
OBJS=common.o
 
include $(BASE)/config/example.mk
 
simple:
make -f $(SUBMAKE) APP=simple INIT=initfs.o OTHEROBJS=
hello:
make -f $(SUBMAKE) APP=hello INIT=initfs.o OTHEROBJS=
hello1:
make -f $(SUBMAKE) APP=hello1 INIT=initfs.o OTHEROBJS=common.o
hello2:
make -f $(SUBMAKE) APP=hello2 INIT=initfs.o OTHEROBJS=common.o
test0:
make -f $(SUBMAKE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
treef1:
make -f $(SUBMAKE) APP=treef1 INIT=initfs.o OTHEROBJS=common.o
treec1:
make -f $(SUBMAKE) APP=treec1 INIT=initfs.o OTHEROBJS=common.o
treec2:
make -f $(SUBMAKE) APP=treec2 INIT=initfs.o OTHEROBJS=common.o
 
#
#
#
 
 
.PHONY: util
 
util: tdump.exe jdump.exe sa.exe road.exe wait.exe
 
tdump.exe: tdump.c util.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace tdump.c util.c -o tdump.exe
 
jdump.exe: jdump.c util.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace jdump.c util.c -o jdump.exe
 
sa.exe: sa.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace sa.c util.c -o sa.exe
 
road.exe: road.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace road.c util.c -o road.exe
 
wait.exe: wait.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace wait.c util.c -o wait.exe
 
 
 
#include $(BASE)/config/example.mk
 
 
 
 
 
 
/demos/branches/pj/oldexamples/tracer/common.h
0,0 → 1,28
 
#ifndef _COMMON_H
#define _COMMON_H
 
#include <sys/types.h>
 
/*
#include <kernel/int_sem.h>
#define SEM internal_sem_t
#define sem_init internal_sem_init
#define sem_signal internal_sem_post
#define sem_wait internal_sem_wait
*/
 
#define SEM sem_t
#define sem_signal sem_post
 
extern __dev_t root_device;
extern __dev_t temp_device;
 
int choose_temp_callback(__dev_t dev,__uint8_t fs);
 
void showmessage(char *s);
void waitend(void);
 
#define FROMDIR "/TEMP"
 
#endif
/demos/branches/pj/oldexamples/kernel/test7.ori
0,0 → 1,244
/*
* 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: test7.ori,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 7:
 
this is a part of the classic Hartik demo Aster.
 
It checks:
- jet functions
- The EDF level with many task, with almost full bandwidth used
 
**/
 
/*
* 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"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
//#define PER_WCET 6200
//#define CLOCK_WCET 100
//#define ASTER_WCET 100
#define PER_WCET 20000
#define CLOCK_WCET 1000
#define ASTER_WCET 1000
 
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; // 5000 + rand()%5000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = 64;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",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,"U=%12u",EDF_usedbandwidth(0));
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,"U=%12u",EDF_usedbandwidth(0));
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) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
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++;
}
}
}
 
int main(int argc, char **argv)
{
PID p1,p2,p3; //,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
 
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);
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("test7.c(main): Could not create task <aster> ...");
sys_end();
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();
exit(-1);
}
 
p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
if (p2 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
exit(-1);
}
 
group_activate(1);
 
{
struct timespec t;
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_sec < 6);
}
//sys_status(SCHED_STATUS);
sys_end();
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/perf1.c
0,0 → 1,186
/*
* 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: perf1.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance test 1:
 
there is one RR task that is preempted N_EDF times by an EDF task.
 
the test prints the differences of the execution time.
 
the test have to be compiled with the one shot timer, and it does not
use any init file.
 
**/
 
/*
* 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/rr.h"
#include "modules/dummy.h"
 
#define TIMESPEC_N 100
#define RR_N 1000000000
#define EDF_N 2500
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(1000*1000*1000, RR_MAIN_NO, mb);
RR_register_level(10000, RR_MAIN_YES, mb);
dummy_register_level();
 
return 300;
}
 
void *crash_RR(void *arg);
void *crash_EDF(void *arg);
 
void *__init__(void *arg)
{
int i;
 
PID p1,p2;
 
HARD_TASK_MODEL m_hard;
NRT_TASK_MODEL m_nrt;
 
TIME t[TIMESPEC_N];
 
// JET data
TIME sum, max, curr;
int nact;
 
 
 
hard_task_default_model(m_hard);
hard_task_def_mit (m_hard,2000);
hard_task_def_wcet (m_hard,1000);
hard_task_def_group (m_hard,1);
hard_task_def_ctrl_jet (m_hard);
 
nrt_task_default_model (m_nrt);
nrt_task_def_group (m_nrt,1);
nrt_task_def_ctrl_jet (m_nrt);
 
p1 = task_create("crash_EDF",crash_EDF,&m_hard,NULL);
if (p1 == -1) {
perror("Could not create task <crask_EDF> ...");
sys_end();
}
 
p2 = task_create("crash_RR",crash_RR,&m_nrt,NULL);
if (p2 == -1) {
perror("Could not create task <crask_RR> ...");
sys_end();
}
 
kern_cli();
/* timespec read time */
for (i=0; i<TIMESPEC_N; i++) {
t[i] = ll_gettime(TIME_EXACT, NULL);
}
kern_sti();
 
kern_printf("\n");
for (i=0; i<TIMESPEC_N; i++) {
kern_printf("%d: %ld Û", i, t[i]);
}
kern_printf("\n");
 
task_activate(p2);
 
jet_getstat(p2, &sum, &max, &nact, &curr);
kern_printf("RR test (alone): sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
jet_delstat(p2);
 
group_activate(1);
 
jet_getstat(p2, &sum, &max, &nact, &curr);
kern_printf("\nRR test : sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
jet_getstat(p1, &sum, &max, &nact, &curr);
kern_printf("EDF test : sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
 
sys_end();
 
return 0;
}
 
void *crash_RR(void *arg)
{
int i;
 
for (;;) {
for (i=0; i<RR_N; i++);
task_sleep();
}
return 0;
}
 
void *crash_EDF(void *arg)
{
int i;
 
for (;;) {
for (i=0; i<EDF_N; i++)
task_endcycle();
task_sleep();
}
return 0;
}
 
// not used!!!
int main(int argc, char **argv)
{
return 0;
}
 
 
 
 
/demos/branches/pj/oldexamples/kernel/perf2.c
0,0 → 1,401
/*
* 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: perf2.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance Test 2:
 
This test tries to measure the time spent into the event handlers.
It is based on test D.
 
WARNING: the symbol __PERF_TEST2__ must be defined into the file
kernel/config.h
 
 
**/
 
/*
* 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",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;
}
 
TIME perftime_prol[10001];
TIME perftime_epil[10001];
int perftime_count = 0;
 
void perftest_stat(void *arg)
{
int i;
TIME d, sum=0, max=0;
 
for (i=0; i<9000; i++) {
d = perftime_epil[i]-perftime_prol[i];
sum += d;
if (max < d) max = d;
kern_printf("Û%ld %ldÛ",perftime_epil[i],perftime_prol[i]);
}
kern_printf("\n°°° perftime_count=%u sum=%lu max=%lu °°°\n",perftime_count, sum, max);
}
 
int main(int argc, char **argv)
{
PID p1,p2,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;
 
kern_cli();
 
kern_sti();
 
sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
sys_atrunlevel(perftest_stat, NULL, RUNLEVEL_BEFORE_EXIT);
 
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 = 60;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,fine,NULL);
group_activate(1);
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/perf3.c
0,0 → 1,434
/*
* 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.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
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",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
ll_gettime(TIME_EXACT, &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;
}
 
/demos/branches/pj/oldexamples/kernel/testa.c
0,0 → 1,308
/*
* 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: testa.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 10 (A):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 7, with the use of TBS to serve a set of aperiodic
tasks.
 
There are APER_MAX tasks sleeping, and when an asteroide task finish
the current activation, it activate also an aperiodic task chosen
randomly (if the task chosen is already active, the task_activate do
nothing!)
 
 
**/
 
/*
* 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"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define APER_MAX 8
 
#define PER_WCET 6200
#define APER_WCET 18400
#define CLOCK_WCET 200
#define ASTER_WCET 200
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
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--;
return 0;
}
 
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);
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = 64;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",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,"U=%12u",EDF_usedbandwidth(0));
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,"U=%12u",EDF_usedbandwidth(0));
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) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
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, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
kern_sti();
i++;
}
task_endcycle();
}
}
 
int main(int argc, char **argv)
{
PID p1,p2;//,p3,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
int i;
 
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);
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);
}
 
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);
 
soft_task_def_level(m_aper, 2);
aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (aper_table[0] == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
for (i=1; 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);
}
}
 
 
group_activate(1);
 
{
struct timespec t;
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_sec < 6);
}
//sys_status(SCHED_STATUS);
sys_end();
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/perf4.c
0,0 → 1,112
/*
* 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: perf4.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance test 1:
 
there is one RR task that is preempted N_EDF times by an EDF task.
 
the test prints the differences of the execution time.
 
the test have to be compiled with the one shot timer, and it does not
use any init file.
 
**/
 
/*
* 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/rr.h"
#include "modules/dummy.h"
#include "modules/pi.h"
 
#define TIMESPEC_N 100
#define RR_N 1000000000
#define EDF_N 2500
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(1000*1000*1000, RR_MAIN_NO, mb);
RR_register_level(10000, RR_MAIN_YES, mb);
dummy_register_level();
 
PI_register_module();
 
return 1200;
}
 
void *crash_RR(void *arg);
void *crash_EDF(void *arg);
 
void *__init__(void *arg)
{
TIME t1, t2;
PI_mutexattr_t a;
mutex_t m1;
int i;
 
PI_mutexattr_default(a);
 
mutex_init(&m1, &a);
 
t1 = sys_gettime(NULL);
for (i=0; i<1000; i++) {
mutex_lock(&m1);
mutex_unlock(&m1);
}
t2 = sys_gettime(NULL);
 
kern_printf("t1=%ld, t2=%ld\n",t1,t2);
 
return 0;
}
 
// not used !!!
int main(int argc, char **argv)
{
return 0;
}
/demos/branches/pj/oldexamples/kernel/testb.c
0,0 → 1,244
/*
* 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: testb.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 11 (B):
 
CBS test, similar to Test 10
 
There are 4 CBS aperiodic tasks and 1 periodic task.
after 5 secs, there is another activation of two of the four tasks.
at sec. 10 the test stops.
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_nsec <= 30000000L);
}
 
TASK pippo2()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 30000000L);
}
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
task_endcycle();
 
if (i==7) testactive = 0;
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
TASK aper(void *a)
{
int i;
int y;
 
int load1,j;
 
char s[2];
 
y = (int) a;
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 600000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_aper;
PID p1, p2, p3, p4, p5;
int k=1;
 
srand(7);
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p1 = task_create("pippo", pippo, &m, NULL);
if (p1 == NIL)
{ kern_printf("Can't create pippo task...\n"); }
 
p2 = task_create("pippo2", pippo2, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); }
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,15000);
hard_task_def_wcet(m_per,6200);
hard_task_def_group(m_per,1);
p3 = task_create("asteroide", asteroide, &m_per, NULL);
if (p3 == NIL)
{ kern_printf("Can't create asteroide task...\n"); }
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,100000);
soft_task_def_group(m_aper,1);
soft_task_def_system(m_aper);
soft_task_def_arg(m_aper, 14);
soft_task_def_aperiodic(m_aper);
p4 = task_create("aper", aper, &m_aper, NULL);
if (p4 == NIL)
{ kern_printf("Can't create aper task...\n"); }
 
soft_task_def_arg(m_aper, 13);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
soft_task_def_arg(m_aper, 12);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
soft_task_def_arg(m_aper, 11);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
// kern_printf("p1=%d p2=%d p3=%d p4=%d\n",p1,p2,p3,p4);
group_activate(1);
 
 
// task_kill(p2);
i = 1;
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i && t.tv_sec == 5) {
task_activate(p4);
task_activate(p5);
i = 0;
}
 
// task_kill(p3);
} while (t.tv_sec < 10);
testactive = 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testc.c
0,0 → 1,260
/*
* 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: testc.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 12 (C):
 
CBS test, similar to Test 11
 
then at start time two task are started, one of them
calling task_nopreempt. when the task releases, the other exec all
the pending activations.
at sec. 4 the test stops.
 
**/
 
/*
* 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"
 
TASK pippo()
{
// int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_nsec <= 30000000L);
return 0;
}
 
TASK pippo2()
{
// int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 30000000L);
return 0;
}
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
// if (i==7) testactive = 0;
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
return 0;
}
 
TASK aper(void *a)
{
int i;
int y;
 
int load1,j;
 
char s[2];
 
y = (int) a;
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 600000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
return 0;
}
 
 
TASK per(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 1000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
// if (i==7) testactive = 0;
 
//puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
return 0;
}
 
TASK stoppa()
{
struct timespec t;
 
task_nopreempt();
kern_printf("\nTask nopreempt");
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_sec < 3);
kern_printf("\nTask preempt");
task_preempt();
kern_printf("\nFine STOPPA");
return 0;
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
// HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_aper;
PID p8, p9; //p1, p2, p3, p4, p5, p6, p7,
 
// int k=1;
 
srand(7);
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,100000);
soft_task_def_group(m_aper,1);
soft_task_def_system(m_aper);
soft_task_def_arg(m_aper, (void *)14);
soft_task_def_aperiodic(m_aper);
// soft_task_def_skip_arrivals(m_aper);
 
soft_task_def_periodic(m_aper);
p8 = task_create("per", per, &m_aper, NULL);
if (p8 == NIL)
{ kern_printf("Can't create per task...\n"); }
 
p9 = task_create("stoppa", stoppa, &m, NULL);
if (p9 == NIL)
{ kern_printf("Can't create stoppa task...\n"); }
 
task_activate(p8);
 
i = 0;
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i == 0 && t.tv_sec == 1 && t.tv_nsec >= 0) {
task_activate(p9);
i = 1;
}
} while (t.tv_sec < 10);
/*
testactive = 0;
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
*/
return 0;
}
/demos/branches/pj/oldexamples/kernel/testd.c
0,0 → 1,381
/*
* 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: testd.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 13 (D):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 10 (A), and use the CBS to serve the periodic tasks.
 
There still remain some periodic tasks, that are guaranteed basing on their
wcet.
 
It also tests the shutdown...
 
 
**/
 
/*
* 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 25000
#define APER_WCET 53000
#define CLOCK_WCET 1000
#define ASTER_WCET 1000
#define SOFT_MET 6300
 
#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",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;
}
 
int main(int argc, char **argv)
{
PID p1,p2,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);
 
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;
}
 
/demos/branches/pj/oldexamples/kernel/teste.c
0,0 → 1,115
/*
* 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: teste.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 14 (E):
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the sem module.
 
 
**/
 
/*
* 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/sem.h>
 
sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
kern_printf("before sem_wait %d\n",(int)a);
sem_wait(&s);
kern_printf("after sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
kern_printf("before sem_post %d\n",(int)a);
sem_post(&s);
kern_printf("after sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("pippo2", pippo, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
sem_init(&s,0,1);
 
group_activate(1);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testf.c
0,0 → 1,128
/*
* 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: testf.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 15 (F):
 
This test verify the correctness of the PI module.
 
 
the main task (NRT) lock a PI mutex.
then 2 tasks arrives, with priority higher than the main
 
the first try to lock the mutex, but it can't, so the main inherit
his priority. The second simply prints a string.
 
If all works, the string of the second task is printed after the end of
the first task.
 
**/
 
/*
* 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"
 
mutex_t m1;
 
 
TASK pippo1(void *a)
{
// int i=0;
// struct timespec t;
// int last = 0;
 
kern_printf("pippo1 prima di mutex_lock\n");
mutex_lock(&m1);
kern_printf("pippo1 dopo mutex_lock\n");
 
mutex_unlock(&m1);
kern_printf("pippo1 dopo mutex_unlock\n");
return 0;
}
 
TASK pippo2()
{
kern_printf("pippo2 Dentro pippo2\n");
return 0;
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
HARD_TASK_MODEL m;
PID p2,p3;
 
PI_mutexattr_t a;
 
hard_task_default_model(m);
hard_task_def_mit(m,50000);
hard_task_def_wcet(m,10000);
hard_task_def_group(m,1);
 
hard_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo1, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo1 task...\n"); return 1; }
 
hard_task_def_mit(m,100000);
p3 = task_create("pippo2", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
kern_printf("main prima di mutex_lock\n");
mutex_lock(&m1);
kern_printf("main dopo mutex_lock, exec=%d, exec_shadow=%d\n", exec, exec_shadow);
 
group_activate(1);
 
kern_printf("main dopo group_activate, exec=%d, exec_shadow=%d\n", exec, exec_shadow);
mutex_unlock(&m1);
kern_printf("main dopo mutex_unlock\n");
 
mutex_destroy(&m1);
kern_printf("main dopo mutex_destroy\n");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testg.c
0,0 → 1,485
/*
* 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: testg.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 16 (G):
 
This is a part of the cbsmouse.c Hartik's example.
 
It only prints the task scheduling in graphic mode...
 
There is a parameter to choose the type of scheduling module
to initialize.
 
to init correctly the module and task bandwidth parameters, set the defines
NUM and DEN in initg.c and testg.c and remember the "s" (soft) parameter!!!
 
to plot the deadlines assigned by CBS or TBS, compile cbs.c or tbs.c with
the TESTG define
(gray dots over the mouse line are the deadlines, green dots are CBS
shifts)
 
**/
 
/*
* 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 "drivers/glib.h"
#include "drivers/keyb.h"
#include "drivers/mouse.h"
 
/*--------------------------------------------------------------*/
/* TEST ON EDF SCHEDULING */
/*--------------------------------------------------------------*/
 
#define LMOUSE 20
#define LM 40 /* line of main */
#define OFFSET 20 /* initial phase */
#define CHAR_DIM 8 /* Height of chars in pixels */
 
int col[3] = {2, 4, 14}; /* colors of timelines */
int lev[3] = {80, 120, 160}; /* level of timelines */
int ptime[3] = {10, 20, 25}; /* number of cycles */
int period[3] = {40, 50,100}; /* tasks' periods */
int tick = 1; /* system tick */
int tscale = 1; /* time scale */
TIME starttime = 0; /* Simulation start time (scaled) */
 
char *title; /* used in initg.c */
 
/* period[] is scaled with a factor of PERIODSCALE usec */
#define PERIODSCALE 5000
 
// update also initg.c!!!
#define NUM 200
#define DEN 64000
 
//SEM mutex; /* Semaphore for graphix*/
 
//#define IY(y) (480 - y)
#define IY(y) y
 
/*
* mouse cursor
*
*/
 
#define W WHITE
#define R RED
#define G GREEN
#define M MAGENTA
 
/* shape */
 
BYTE mycursor[16*16]= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,W,W,W,W,0,0,0,0,0,0,W,W,W,W,0,
0,W,M,0,0,0,0,0,0,0,0,0,0,M,W,0,
0,W,0,M,0,0,0,0,0,0,0,0,M,0,W,0,
0,W,0,0,M,0,0,0,0,0,0,M,0,0,W,0,
0,0,0,0,0,M,0,0,0,0,M,0,0,0,0,0,
0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
0,0,0,0,0,M,M,M,M,M,M,0,0,0,0,0,
0,0,0,0,M,M,M,M,M,M,M,M,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
 
#define F 0xff
#define B 0x00
 
/* mask */
BYTE mybkg[16*16]= {
B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
};
 
#undef B
#define B 0xff
 
/* bad mask */
BYTE mybadbkg[16*16]= {
B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
};
 
/* very bad mask */
BYTE myverybadbkg[16*16]= {
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
};
 
/*--------------------------------------------------------------*/
/* Prints a grid to show task periods during execution */
/*--------------------------------------------------------------*/
 
void print_grid()
{
int i;
int a1, a2, a3;
int temp;
// char str[50];
 
a1 = 0;
a2 = 0;
a3 = 0;
temp = 0;
 
grx_text(title, 0, 240-10 ,10, 0);
 
grx_line(OFFSET, lev[0], 639, lev[0], 5);
grx_line(OFFSET, lev[1], 639, lev[1], 5);
grx_line(OFFSET, lev[2], 639, lev[2], 5);
grx_text("T1", 0, lev[0]-8, 9, 0);
grx_text("T2", 0, lev[1]-8, 9, 0);
grx_text("T3", 0, lev[2]-8, 9, 0);
grx_text("MA", 0, LM, 8, 0);
grx_text("MO", 0, LMOUSE, 8, 0);
 
for (i = OFFSET; i < 640; i++) {
if (temp >= a1) {
grx_line(i, lev[0] - 1, i, lev[0] - 20, 3);
a1 += period[0];
}
if (temp >= a2) {
grx_line(i, lev[1] - 1, i, lev[1] - 20, 3);
a2 += period[1];
}
if (temp >= a3) {
grx_line(i, lev[2] - 1, i, lev[2] - 20, 3);
a3 += period[2];
}
temp += tick/tscale;
}
}
 
/*--------------------------------------------------------------*/
/* This function is called at system termination */
/*--------------------------------------------------------------*/
 
void my_end()
{
grx_close();
// sys_status(0xFFFF);
// sys_end();
}
 
/*--------------------------------------------------------------*/
/* GENERIC PERIODIC PROCESS */
/*--------------------------------------------------------------*/
 
TASK color(int k)
{
int i;
DWORD x = OFFSET;
TIME t;
while ( x < 640L) {
for (i = 0; i < ptime[k]; i++) {
 
t = sys_gettime(NULL) / PERIODSCALE;
x = (t - starttime) + OFFSET;
if (x>=640) break;
//sem_wait(mutex, BLOCK);
kern_cli();
grx_plot(x, lev[k] - 4, col[k]);
grx_plot(x, lev[k] - 5, col[k]);
grx_plot(x, lev[k] - 6, col[k]);
grx_plot(x, lev[k] - 7, col[k]);
//sem_signal(mutex);
kern_sti();
while (sys_gettime(NULL)/PERIODSCALE == t);
}
task_endcycle();
}
return 0;
}
 
void my_mouse_handler(MOUSE_EVT *ev)
{
int x;
 
x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
if (x>=640) return;
//sem_wait(mutex, BLOCK);
grx_plot(x, LMOUSE, 8);
//while (sys_ticks()==s);
//sem_signal(mutex);
}
 
/*--------------------------------------------------------------*/
/* MAIN PROCESS */
/*--------------------------------------------------------------*/
 
int main(int argc, char *argv[])
{
int i;
int x = OFFSET;
 
MOUSE_PARMS mouse = BASE_MOUSE;
HARD_TASK_MODEL mouse_hard;
SOFT_TASK_MODEL mouse_soft;
NRT_TASK_MODEL mouse_nrt;
 
char c;
KEY_EVT emerg;
 
HARD_TASK_MODEL m_per;
int modenum;
 
//sys_def_nocheck(si);
//sys_def_tick(si, tick, mSec);
//sys_init(&si);
 
//cprintf("Sys GetTick... %lu 100000 / sys_tick: %lu \n", sys_gettick(), 100000 / sys_gettick());
 
if (argc>=3)
switch(*argv[2]) {
case 'h':
/* this is not correct, because it don't remember activations */
hard_task_default_model(mouse_hard);
hard_task_def_mit(mouse_hard,DEN);
hard_task_def_wcet(mouse_hard,NUM);
hard_task_def_system(mouse_hard);
hard_task_def_aperiodic(mouse_hard);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_hard);
break;
case 's':
soft_task_default_model(mouse_soft);
soft_task_def_wcet(mouse_soft,NUM);
soft_task_def_met(mouse_soft,NUM);
soft_task_def_period(mouse_soft,DEN);
soft_task_def_system(mouse_soft);
soft_task_def_aperiodic(mouse_soft);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_soft);
break;
case 'n':
/* this is not correct, because it don't remember activations */
nrt_task_default_model(mouse_nrt);
nrt_task_def_system(mouse_nrt);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_nrt);
break;
default:
argc=0;
break;
}
mouse_def_ms(mouse,0);
 
if (argc>=4) {
period[0]=atoi(argv[3]);
if (period[0]<ptime[0]) period[0]=ptime[0]+5;
}
if (argc>=5) {
period[1]=atoi(argv[4]);
if (period[1]<ptime[1]) period[1]=ptime[1]+5;
}
if (argc>=6) {
period[2]=atoi(argv[5]);
if (period[2]<ptime[2]) period[2]=ptime[2]+5;
}
if (argc<2) {
cprintf("syntax: x testg <config> <mouse-task> [t1] [t2] [t3]\n");
cprintf("where <config> can be:\n");
cprintf("\t0 - EDF + CBS + RR\n");
cprintf("\t1 - RM + PS ( bkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t2 - RM + PS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t3 - EDF + PS ( bkg, U=1/16) + RR\n");
cprintf("\t4 - EDF + PS (nobkg, U=1/16) + RR\n");
cprintf("\t5 - EDF + TBS( U=1/16) + RR\n");
cprintf("\t6 - RM + DS ( bkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t7 - RM + DS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\nwhere <mouse-task> can be:\n");
cprintf("\th - Hard\n");
cprintf("\ts - Soft (understimated wcet)\n");
cprintf("\tn - NRT\n");
sys_end();
return -1;
}
 
if (grx_init() == -1) {
cprintf("Error initing GraphLib!!!\n");
sys_end();
}
modenum = grx_getmode(640, 480, 8);
cprintf("Modenum :%d\n", modenum);
 
if (grx_setmode(modenum) == -1) {
cprintf("No SetMode!!!\n");
sys_end();
}
/* */
// grx_close();
print_grid();
#define DX (640/5-1)
grx_box(DX*0,240,DX*1-1,479,GREEN);
grx_box(DX*1,240,DX*2-1,479,WHITE);
grx_box(DX*2,240,DX*3-1,479,RED);
grx_box(DX*3,240,DX*4-1,479,MAGENTA);
grx_box(DX*4,240,DX*5-1,479,BLACK);
 
for (i=0;i<3;i++) {
period[i]=period[i]*PERIODSCALE;
//ptime[i]=ptime[i] *PERIODSCALE; ptime is not scaled
}
sys_atrunlevel(my_end, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* mutex */
// mutex = sem_create(1);
 
/* keyboard */
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,(void (*)(KEY_EVT *))sys_end);
keyb_getchar();
 
/* mouse */
mouse_init(&mouse);
mouse_limit(XMINLIMIT(640,480),
240,
XMAXLIMIT(640,480),
YMAXLIMIT(640,480));
mouse_position(320,280);
mouse_threshold(2);
//grx_setcolor(255,255,255,255);
mouse_grxshape(mycursor,mybkg);
mouse_grxcursor(ENABLE);
mouse_on();
mouse_hook(my_mouse_handler);
 
/* hard task creation */
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,period[0]);
hard_task_def_wcet(m_per,ptime[0]*PERIODSCALE);
hard_task_def_group(m_per, 1);
//task_def_wcet(m, ptime[0] * sys_tick);
if (task_create("verde", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <green>:");
sys_end();
l1_exit(-1);
}
hard_task_def_arg(m_per, (void *)1);
hard_task_def_wcet(m_per, ptime[1]*PERIODSCALE);
hard_task_def_mit(m_per,period[1]);
if (task_create("red", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <red>:");
sys_end();
l1_exit(-1);
}
hard_task_def_arg(m_per, (void *)2);
hard_task_def_wcet(m_per, ptime[2]*PERIODSCALE);
hard_task_def_mit(m_per,period[2]);
if (task_create("yellow", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <yellow>:");
sys_end();
l1_exit(-1);
}
starttime = sys_gettime(NULL) / PERIODSCALE;
group_activate(1);
 
/* main loop */
while (x < 640L) {
x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
if (x>=640) break;
//sem_wait(mutex, BLOCK);
kern_cli();
grx_plot(x, LM, 7);
kern_sti(); // sem_signal(mutex);
}
 
c = keyb_getchar();
return 0;
}
 
/*--------------------------------------------------------------*/
/demos/branches/pj/oldexamples/kernel/testh.c
0,0 → 1,493
/*
* 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: testh.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 17 (h):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 13 (d), and use the CBS to serve the periodic tasks.
 
There are not periodic tasks, only CBS tasks.
 
The tasks use a PI, NPP or NOP mutex to access the video memory.
 
A flag (LONGSC) is provided to try long and short critical sections.
 
**/
 
/*
* 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"
#include "drivers/keyb.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 6200
#define APER_WCET 18400
#define JET_WCET 10000
#define JET_PERIOD 100000
 
#define APER_REP 22000
 
//PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 3000 /* 3000 12000 */
#define CLOCK_WCET 400 /* 200 300*/
#define ASTER_WCET 400 /* 200 300*/
#else
#define SOFT_MET 80000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
// task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
// task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(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 = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
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;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
 
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
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(2));
 
mutex_unlock(&m1);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
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(2));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
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) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 2)
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³p%-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), 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]);
// p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)proc_table[p].status, (int)proc_table[p].shadow, (int)proc_table[p].timespec_priority.tv_sec,(int)proc_table[p].timespec_priority.tv_nsec/1000 , (int)last[3], (int)last[4]);
mutex_unlock(&m1);
i++;
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
int main(int argc, char **argv)
{
PID p1,p2,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;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,100000);
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_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,JET_PERIOD);
soft_task_def_met(m_soft,JET_WCET);
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 (p2 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
//kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/testi.c
0,0 → 1,234
/*
* 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: testi.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 18 (I):
 
This test verify the correctness of the PC module.
 
The test uses 3 mutexes
m0 with ceiling 0
m1 with ceiling 0
m2 with ceiling 1
 
the main task (NRT) creates three tasks.
 
J0 with PC priority 0
starts at t=1.5 sec and lock m0, unlock m0, then lock and unlock m1
 
J1 with PC priority 1
starts at t=0.5 sec and try to lock m2
 
J2 with PC priority 2
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 197 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
**/
 
/*
* 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 "drivers/keyb.h"
 
mutex_t m0,m1,m2;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",p);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK j0()
{
kern_printf("J0: before locking m0\n");
mutex_lock(&m0);
kern_printf("J0: locked m0\n");
mutex_unlock(&m0);
kern_printf("J0: unlocked m0, locking m1\n");
 
mutex_lock(&m1);
kern_printf("J0: locked m1\n");
mutex_unlock(&m1);
kern_printf("J0: unlocked m1, end task\n");
return 0;
}
 
 
TASK j1()
{
kern_printf("J1: before locking m2\n");
mutex_lock(&m2);
kern_printf("J1: locked m2\n");
mutex_unlock(&m2);
kern_printf("J1: unlocked m2, end task\n");
return 0;
}
 
 
TASK j2()
{
// struct timespec t;
kern_printf("J2: before locking m2\n");
mutex_lock(&m2);
kern_printf("J2: locked m2, waiting to t=1 sec\n");
 
while (gt() < 1000000);
 
kern_printf("J2: t = 1 sec reached\n");
mutex_lock(&m1);
kern_printf("J2: locked m1, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("J2: t = 2 sec reached\n");
mutex_unlock(&m1);
kern_printf("J2: unlocked m1\n");
 
mutex_unlock(&m2);
kern_printf("J2: unlocked m2, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
PC_mutexattr_t a;
PI_mutexattr_t a2;
PC_RES_MODEL r;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,0);
p0 = task_create("J0", j0, &m, &r);
if (p0 == NIL)
{ kern_printf("Can't create J0 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,1);
p1 = task_create("J1", j1, &m, &r);
if (p1 == NIL)
{ kern_printf("Can't create J1 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
PC_res_default_model(r,2);
p2 = task_create("J2", j2, &m, &r);
if (p2 == NIL)
{ kern_printf("Can't create J2 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
PC_mutexattr_default(a,0);
mutex_init(&m0,(mutexattr_t *)&a);
mutex_init(&m1,(mutexattr_t *)&a);
 
PC_mutexattr_default(a,1);
mutex_init(&m2,(mutexattr_t *)&a);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testj.c
0,0 → 1,268
/*
* 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: testj.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 19 (J):
 
This test verify the correctness of the SRP module.
 
There are 3 taks, Jh, Jm, Jl that uses 3 mutexes m1, m2, m3
 
the main task (NRT) creates the three tasks.
 
Jh with preemption level 3
starts at t=1.5 sec and lock m3, lock m1, unlock m1, unlock m3
 
Jm with preemption level 2
starts at t=0.5 sec and lock m3, lock m2, unlock m2, unlock m3
then lock and unlock m1
 
Jl with preemption level 1
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
then it unlocks m2, and finally it locks and unlocks m3
 
 
The example is similar to the scheduling diagram shown at p. 210 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
mutex_t m1,m2,m3;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",a);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK Jlobby()
{
kern_printf("(*)");
return 0;
}
 
TASK Jh()
{
PID l;
HARD_TASK_MODEL m;
SRP_RES_MODEL r;
 
kern_printf("JH: creating Jy before locking m3\n");
 
hard_task_default_model(m);
hard_task_def_mit(m,30000);
hard_task_def_wcet(m,1000);
SRP_res_default_model(r,4);
l = task_create("Jlobby",Jlobby,&m,&r);
task_activate(l);
 
mutex_lock(&m3);
kern_printf("JH: locked m3, locking m1\n");
mutex_lock(&m1);
kern_printf("JH: locked m1, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JH: unlocked m1, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("JH: unlocked m3, end task\n");
return 0;
}
 
 
TASK Jm()
{
kern_printf("JM: before locking m3\n");
mutex_lock(&m3);
kern_printf("JM: locked m3, locking m2\n");
mutex_lock(&m2);
kern_printf("JM: locked m2, unlocking m2\n");
mutex_unlock(&m2);
kern_printf("JM: unlocked m2, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("JM: unlocked m3, locking m1\n");
mutex_lock(&m1);
kern_printf("JM: locked m1, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JM: unlocked m1, end task\n");
return 0;
}
 
 
TASK Jl()
{
// struct timespec t;
kern_printf("JL: before locking m2\n");
mutex_lock(&m2);
kern_printf("JL: locked m2, waiting to t=1 sec\n");
 
while (gt() < 1000000);
 
kern_printf("JL: t = 1 sec reached, locking m1\n");
mutex_lock(&m1);
kern_printf("JL: locked m1, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("JL: t = 2 sec reached, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JL: unlocked m1, unlocking m2\n");
 
mutex_unlock(&m2);
 
kern_printf("JL: unlocked m2, locking m3\n");
mutex_lock(&m3);
kern_printf("JL: locked m3, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("JL: unlocked m3, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
SRP_mutexattr_t a;
SRP_RES_MODEL r;
 
PI_mutexattr_t a2;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
SRP_mutexattr_default(a);
mutex_init(&m1,&a);
mutex_init(&m2,&a);
mutex_init(&m3,&a);
 
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 3);
p0 = task_createn("JH", Jh, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1), NULL);
if (p0 == NIL)
{ kern_printf("Can't create JH task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 2);
p1 = task_createn("JM", Jm, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p1 == NIL)
{ kern_printf("Can't create JM task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
SRP_res_default_model(r, 1);
p2 = task_createn("JL", Jl, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p2 == NIL)
{ kern_printf("Can't create JL task...\n"); return 1; }
 
// sys_abort(1);
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testk.c
0,0 → 1,226
/*
* 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: testk.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 20 (K):
 
This test verify the correctness of the NOP module. It works with the PI
module, too.
 
The test uses one mutex
 
the main task (NRT) creates three tasks.
 
J1 with PC priority 0
starts at t=0.5 sec and lock m0
 
J2 with PC priority 1
starts at t=1 sec and doesn't lock any mutex
 
J3 with PC priority 2
it starts and locks m0
at t=2 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 188 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
mutex_t m0;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",p);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK j1()
{
kern_printf("J1: before locking m0\n");
mutex_lock(&m0);
kern_printf("J1: locked m0\n");
mutex_unlock(&m0);
kern_printf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
kern_printf("J2: waiting t=1.5 sec\n");
 
while (gt() < 1500000);
 
kern_printf("J2: end task\n");
return 0;
}
 
 
TASK j3()
{
kern_printf("J3: before locking m0\n");
mutex_lock(&m0);
kern_printf("J3: locked m0, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("J3: t = 1 sec reached, unlocking m0\n");
mutex_unlock(&m0);
kern_printf("J3: unlocked m0, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
PC_mutexattr_t a;
PI_mutexattr_t a2;
NOP_mutexattr_t a3;
SRP_mutexattr_t a4;
NPP_mutexattr_t a5;
 
PC_RES_MODEL r;
SRP_RES_MODEL srp;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PC_mutexattr_default(a,0);
PI_mutexattr_default(a2);
NOP_mutexattr_default(a3);
SRP_mutexattr_default(a4);
NPP_mutexattr_default(a5);
mutex_init(&m0,&a4);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_wcet(m,20000);
hard_task_def_mit(m,10000000);
PC_res_default_model(r,0);
SRP_res_default_model(srp,3);
// p0 = task_createn("J1", j1, &m, &r, &srp, NULL);
p0 = task_createn("J1", j1, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p0 == NIL)
{ kern_printf("Can't create J1 task...\n"); return 1; }
 
hard_task_def_wcet(m,1600000);
hard_task_def_mit(m,21000000);
PC_res_default_model(r,1);
SRP_res_default_model(srp,2);
p1 = task_createn("J2", j2, (TASK_MODEL *)&m, &r, &srp, NULL);
if (p1 == NIL)
{ kern_printf("Can't create J2 task...\n"); return 1; }
 
hard_task_def_wcet(m,3000000);
hard_task_def_mit(m,100000000);
PC_res_default_model(r,2);
SRP_res_default_model(srp,1);
// p2 = task_createn("J3", j3, &m, &r, &srp, NULL);
p2 = task_createn("J3", j3, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p2 == NIL)
{ kern_printf("Can't create J3 task...\n"); return 1; }
 
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p0);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p1);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testl.c
0,0 → 1,487
/*
* 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: testl.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 21 (l):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a polling server
 
**/
 
/*
* 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"
#include "drivers/keyb.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 6200
#define APER_WCET 18400
#define JET_WCET 10000
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 3000 /* 12000 */
#define CLOCK_WCET 200 /* 300*/
#define ASTER_WCET 200 /* 300*/
#else
#define SOFT_MET 80000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(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 = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
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;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
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(2));
 
mutex_unlock(&m1);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
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(2));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
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) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 2)
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(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), 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, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, nact, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , last[3], last[4]);
mutex_unlock(&m1);
i++;
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
int main(int argc, char **argv)
{
PID p1,p2,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;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
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_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,100000);
soft_task_def_met(m_soft,JET_WCET);
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_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/testm.c
0,0 → 1,318
/*
* 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: testm.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 22 (M):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 10(A), and test the PS with RM.
 
The JetControl is served by a dedicated Polling Server, too.
 
There are APER_MAX tasks sleeping, and when an asteroide task finish
the current activation, it activate also an aperiodic task chosen
randomly (if the task chosen is already active, the task_activate do
nothing!)
 
 
**/
 
/*
* 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 "drivers/keyb.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define APER_MAX 8
 
#define PER_WCET 7800
#define APER_WCET 14000
#define CLOCK_WCET 200
#define ASTER_WCET 200
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
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--;
return 0;
}
 
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);
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = 64;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",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,"U=%12u",EDF_usedbandwidth(0));
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,"U=%12u",EDF_usedbandwidth(0));
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) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
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(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
PID p1,p2,p3; //,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
int i;
struct timespec fineprg;
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
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);
 
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);
}
 
soft_task_default_model(m_aper);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_level(m_aper, 1);
soft_task_def_group(m_aper,1);
soft_task_def_aperiodic(m_aper);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
soft_task_def_wcet(m_aper,APER_WCET);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
for (i=0; i<APER_MAX; i++) {
soft_task_def_level(m_aper, i/4 + 3);
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);
}
}
 
fineprg.tv_sec = 1000;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
 
group_activate(1);
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/testn.c
0,0 → 1,211
/*
* 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: testn.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 23 (N):
 
This is the mousfind.c Hartik's example.
 
It find the mouse...
 
**/
 
/*
* 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 <drivers/mouse.h>
#include <drivers/keyb.h>
 
/* don't include this into real applications*/
#include <../drivers/char/_mouse.h>
 
#define cons_columns 80
#define cons_rows 25
 
int done;
 
void my_ctrlC_function(KEY_EVT *k)
{
CRSR_STD();
done=1;
//sys_status(0xffff);
sys_end();
l1_exit(0);
}
 
//extern int tindex;
//extern DWORD tdata[];
//int first=1;
 
 
void my_mouse_hook(MOUSE_EVT *m)
{
static int buttons=-1;
if (buttons!=m->buttons) {
buttons=m->buttons;
//mouse_off();
if (isLeftButton(*m)) puts_xy(9,22,RED,"active");
else puts_xy(9,22,RED," ");
if (isCentralButton(*m)) puts_xy(9,23,RED,"active");
else puts_xy(9,23,RED," ");
if (isRightButton(*m)) puts_xy(9,24,RED,"active");
else puts_xy(9,24,RED," ");
//mouse_on();
}
 
 
/*
if (tindex>20&&first) {
int i;
cprintf("\nSTART\n");
for (i=0;i<tindex;i++) {
cprintf("%i\n",(int)tdata[i]);
}
for (i=1;i<tindex;i++) {
cprintf("%i ",(int)(tdata[i]-tdata[i-1]));
}
first=0;
}
*/
}
 
int main(int argc,char *argv[])
{
// KEYB_PARMS keyb =BASE_KEYB;
MOUSE_PARMS mouse=BASE_MOUSE;
int ch,running,nm;
int sens=5;
 
/* keyboard initialization */
// keyb_def_ctrlC(keyb,my_ctrlC_function);
// keyb_init(&keyb);
 
/* screen */
clear();
nm=0;
while (*vmouse[nm].name!='\0') {
cprintf("%c %s:\t %s\n",(char)('a'+nm),vmouse[nm].name,vmouse[nm].desc);
nm++;
}
cprintf("\n[a-%c]\t select a mouse server\n",(char)(nm+'a'-1));
cprintf("[z]\t decrement mouse threshold\n");
cprintf("[x]\t incremnet mouse threshold\n");
cprintf("[ctrl-c]\t exit\n");
place(0,20);
cputs("mouse server:\n");
cputs("threshold:\n");
cputs("left :\n");
cputs("central:\n");
cputs("right :");
CRSR_OFF();
 
/* main loop */
running=done=0;
while (!done) {
ch=keyb_getch(TRUE);
switch(ch) {
 
/* decrement threshold */
case 'z':
sens--;
if (sens<2) sens=2;
mouse_threshold(sens);
/* threshold */
place(11,21);
cprintf("%i ",sens);
break;
 
/* increment threshold */
case 'x':
sens++;
if (sens>100) sens=100;
mouse_threshold(sens);
/* threshold */
place(11,21);
cprintf("%i ",sens);
break;
 
/* change mouse protocol */
default:
if (ch>='a'&&ch<='a'+nm-1) {
/* check if a mouse server is running... */
if (running) {
/* disable autocursor */
mouse_txtcursor(DISABLE);
/* destroy actual mouse server */
mouse_end();
}
/* mouse server name */
puts_xy(14,20,GREEN," ");
puts_xy(14,20,GREEN,vmouse[ch-'a'].name);
/* threshold */
place(11,21);
cprintf("%i ",sens);
/* don't use this method to change a mouse protocol */
/* use mouse_def_???? macros instead */
mouse.type=ch-'a';
/* start a new server */
running=(mouse_init(&mouse)==0?1:0);
/* if running ...*/
if (running) {
/* set mouse limit */
mouse_limit(0,0,cons_columns-1,cons_rows-1);
/* enable autocursor */
mouse_txtcursor(ENABLE|AUTOOFF);
/* hook my function */
mouse_hook(my_mouse_hook);
/* show mouse cursor */
mouse_on();
}
}
break;
}
}
 
CRSR_STD();
sys_end();
return 0;
}
/demos/branches/pj/oldexamples/kernel/testo.c
0,0 → 1,99
/*
* 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: testo.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 24 (O):
 
This is the pcitest Hartik's example.
 
**/
 
/*
* 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 <drivers/keyb.h>
 
#include <drivers/llpci.h>
#include <drivers/pci.h>
 
void scan()
{
// int i, ndev;
// WORD Class;
// struct pci_regs *r;
BYTE bus, dev;
 
/* Scan the devices connected to the PCI bus */
if (pci_init() == 1) {
clear();
pci_show();
bus = 0; dev = 0;
if (pcibios_find_device(0x8086, 0x7000, 0, &bus, &dev) == NULL)
cprintf("Not found... %d %d\n", bus, dev);
else cprintf("Found: %d \t %d\n", bus, dev);
 
if (pcibios_find_class(0x300, 0, &bus, &dev) == NULL)
cprintf("Not found... %d %d\n", bus, dev);
else cprintf("Found: %d \t %d\n", bus, dev);
} else cprintf("PCI not found!!!\n");
}
 
void endfun(KEY_EVT *k)
{
sys_abort(60000);
}
 
int main (int argc, char *argv[])
{
KEY_EVT k;
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,endfun);
 
scan();
while(1);
sys_end();
return -1;
}
/demos/branches/pj/oldexamples/kernel/testp.c
0,0 → 1,227
/*
* 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: testp.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 25 (P):
 
This is the talkdx.c Hartik's example.
 
File: Talk.C
Revision: 1.00
Author: Luca Abeni
 
 
Simple Netlib demo: nothing of seriously real-time, only another Unix
Talk clone.
Read it to see how the UDP/IP layers of the networ library work.
 
**/
 
/*
* 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 <mem.h>
//#include <stdlib.h>
#include <string.h>
//#include <cons.h>
#include <drivers/crtwin.h>
#include <drivers/keyb.h>
 
#include <drivers/udpip.h>
 
 
WIN dbg;
BYTE esc = FALSE;
 
char talk_myipaddr[20];
char talk_toipaddr[20];
 
/*
This non real-time task reads UDP packets from the network and writes
them in a window
*/
TASK scrittore(void)
{
char str[2000];
UDP_ADDR from, local;
WIN displ;
int s,n;
 
/* Connect on the local port #100 */
local.s_port = 100;
s = udp_bind(&local, NULL);
 
/* Open the window */
win_init(&displ,0,0,79,6);
win_frame(&displ,BLACK,WHITE,"Remote",2);
 
while (1) {
/* Clear the buffer for receiving the packet...*/
memset(str, 0, 1999);
/*...and receive the packet (block until a packet arrives */
n = udp_recvfrom(s, str, &from);
win_puts(&displ, str);
}
}
 
/*
This non real-time task reads strings from the keyoard and sends them
to the remote host
*/
TASK write(void)
{
WIN wr;
UDP_ADDR to,local;
char str[80];
int s;
IP_ADDR bindlist[5];
 
/* Create a socket for transitting */
ip_str2addr(talk_myipaddr,&(local.s_addr));
local.s_port = 101;
 
/*
If we want the address of the remote host in the ARP table before
begginning the transmission (to eliminate a possible source of
unpredictability), we can use the bindlist, otherwise we set the
second parameter of udp_bind to NULL
*/
ip_str2addr(talk_toipaddr,&(bindlist[0]));
memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
s = udp_bind(&local, /*bindlist*/NULL);
 
win_init(&wr,0,7,79,6);
win_frame(&wr,BLACK,WHITE,"Local",2);
ip_str2addr(talk_toipaddr,&(to.s_addr));
to.s_port = 100;
sprintf(str,"Local IP address %d.%d.%d.%d\n", local.s_addr.ad[0],
local.s_addr.ad[1], local.s_addr.ad[2],
local.s_addr.ad[3]);
win_puts(&dbg,str);
sprintf(str,"Talk to %d.%d.%d.%d ",to.s_addr.ad[0],to.s_addr.ad[1],
to.s_addr.ad[2],to.s_addr.ad[3]);
win_puts(&dbg,str);
while (1) {
/* Get the string...*/
win_gets(&wr,str,78);
strcat(str,"\n");
/*...and send it!!! */
udp_sendto(s,str,strlen(str)+2,&to);
}
}
 
/* This function is called when the user presses CTRL-C (stops the systems) */
void esci(KEY_EVT *k)
{
esc = TRUE;
cprintf("Ctrl-Brk pressed!\n");
//sys_status(0xFFFF);
sys_abort(500);
//exit(1);
}
 
int main(void)
{
KEY_EVT k;
 
struct net_model m = net_base;
 
NRT_TASK_MODEL m_nrt;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,esci);
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,esci);
 
clear();
cprintf(" Hartik Talk! Ver. 1.00\n");
// strcpy(talk_myipaddr, "193.205.82.46");
// strcpy(talk_toipaddr, "193.205.82.44");
 
strcpy(talk_myipaddr, "193.205.82.44");
strcpy(talk_toipaddr, "193.205.82.46");
 
/* We want a task for TX mutual exclusion */
net_setmode(m, TXTASK);
/* We use UDP/IP stack */
net_setudpip(m, talk_myipaddr);
/* OK: let's start the NetLib! */
if (net_init(&m) == 1) {
cprintf("Net Init OK...\n");
} else {
cprintf("Net Init Failed...\n");
sys_abort(300);
}
 
 
//dump_irq();
cprintf("\n\n\n\tPress ENTER\n");
while (!esc) {
keyb_getcode(&k,BLOCK);
if (k.ascii == 13) esc = TRUE;
}
 
esc = FALSE;
clear();
win_init(&dbg,0,20,60,3);
win_frame(&dbg,BLACK,WHITE,"Debug",2);
/* Start the sender and receiver tasks...*/
//task_nopreempt();
nrt_task_default_model(m_nrt);
task_activate(task_create("aaa",scrittore,&m_nrt,NULL));
task_activate(task_create("bbb",write,&m_nrt,NULL));
//clear();
//task_preempt();
/*...and wait!!! */
while (!esc) {
}
sys_end();
//clear();
return 0;
}
/demos/branches/pj/oldexamples/kernel/testq.c
0,0 → 1,229
/*
* 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: testq.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 26 (Q):
 
This test verify the correctness of the task_join primitive.
 
There are 4 taks, J1, J2, J3, are created as joinable, J4 as detached
(the standard with hartik...)
 
The main task:
Creates J1 and J2, locks m1 (a PI mitex), creates C3.
at t=0.8 sec it calls a task_join on J3 (that returns EDEADLK),
it unlocks m1, then it makes task_join on J3 another time.
Next it creates J4 as detached and finally it does a task_join on J4
(that returns EINVAL).
 
J1:
at t=0.2 sec it calls task_join on J2, the it ends.
 
J2:
it simply waits t=0.4 sec and it ends.
 
J3:
First, it calls task_join on J1.
Then, at t=0.6 sec it locks m1, then unlocks it
 
J4:
it simply waits t=1 sec and it ends.
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
 
PID j0, j1, j2, j3, j4;
mutex_t m1;
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
TASK J1()
{
int err;
void *ret;
 
kern_printf("J1: started, waiting 0.2 sec\n");
 
while (sys_gettime(NULL) < 200000);
 
kern_printf("J1: 0.2 sec reached, joining J2\n");
 
err = task_join(j2, &ret);
 
kern_printf("J1: join J2 returns %d error %d, exiting\n",
(int)ret,err);
return (void *)11;
}
 
TASK J2()
{
kern_printf("J2: started, waiting 0.4 sec\n");
 
while (sys_gettime(NULL) < 400000);
 
kern_printf("J2: 0.4 sec reached, exiting\n");
 
return (void *)22;
}
 
TASK J3()
{
int err;
void *ret;
 
kern_printf("J3: started, joining J1\n");
 
err = task_join(j1, &ret);
 
kern_printf("J3: join J1 returns %d error %d, waiting 0.6sec\n", (int)ret, err);
 
while (sys_gettime(NULL) < 600000);
 
kern_printf("J1: 0.6 sec reached, locking m1\n");
 
mutex_lock(&m1);
 
kern_printf("J3: locked m1, unlocking m1\n");
 
mutex_unlock(&m1);
 
kern_printf("J3: unlocked m1, exiting\n");
 
return (void *)33;
}
 
TASK J4()
{
kern_printf("J4: started, waiting 1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
kern_printf("J4: 1 sec reached, exiting\n");
 
return (void *)44;
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
KEY_EVT emerg;
 
int err;
void *ret;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
j0 = exec_shadow;
nrt_task_default_model(m);
nrt_task_def_joinable(m);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
 
/* ---------------------------------------------------------------------
Let's go !!!!
--------------------------------------------------------------------- */
 
kern_printf("main: creating J1,J2,J3, locking m1\n");
 
j1 = task_create("J1", J1, &m, NULL);
if (j1 == NIL) { kern_printf("Can't create J1 task...\n"); return 1; }
task_activate(j1);
 
j2 = task_create("J2", J2, &m, NULL);
if (j2 == NIL) { kern_printf("Can't create J2 task...\n"); return 1; }
task_activate(j2);
 
mutex_lock(&m1);
 
j3 = task_create("J3", J3, &m, NULL);
if (j3 == NIL) { kern_printf("Can't create J3 task...\n"); return 1; }
task_activate(j3);
 
kern_printf("main: waiting t=0.8 sec\n");
 
while (sys_gettime(NULL) < 800000);
 
err = task_join(j3, NULL);
 
kern_printf("main: join J3 error %d, unlocking m1\n",err);
 
mutex_unlock(&m1);
 
err = task_join(j3, &ret);
 
kern_printf("main: join J3 returns %d error %d, unlocked m1, creating J4\n",
(int)ret,err);
 
nrt_task_def_unjoinable(m);
j4 = task_create("J4", J4, &m, NULL);
if (j4 == NIL) { kern_printf("Can't create J4 task...\n"); return 1; }
 
task_activate(j4);
 
err = task_join(j4,&ret);
 
kern_printf("main: join J4 returns %d error %d, exiting\n", (int)ret, err);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/test1.c
0,0 → 1,167
/*
* 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: test1.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 1:
 
this test is a simple main() function with other 2 task
 
This test has to be compiled with init1.c, that introduce 2 RR levels
with a timeslice of 300us (!)
 
This test can be useful to test functions like
 
task_nopreempt
task_preempt
task_create
task_activate
task_delay
group_activate
normal task termination (task_abort)
normal system termination (sys_end)
standard atexit functions (the keyboard...)
 
 
**/
 
/*
* 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"
 
// for min
#include "ll/stdlib.h"
 
#include "ll/stdio.h"
 
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
// int i;
struct timespec t;
int last = 0;
 
do {
//kern_printf("!");
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if ((t.tv_nsec/1000000) != last) { //ogni 7000
// kern_printf("Û%dÛ",t);
last = t.tv_nsec/1000000;
// task_delay(3000000);
}
 
} while (t.tv_nsec <= 20000000L);
}
 
TASK pippo2()
{
struct timespec t;
do {
// kern_printf("pippo2");
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
if (t.tv_nsec > 5000000 && t.tv_nsec <= 12000000) task_nopreempt();
if (t.tv_nsec > 12000000) task_preempt();
 
} while (t.tv_nsec <= 20000000L);
}
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_createn("pippo", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo task...\n"); return 1; }
 
p3 = task_createn("pippo2", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
group_activate(1);
 
 
kern_printf("DENTRO MAIN %d\n",ll_context_save());
 
// testactive = 1;
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// task_delay(14000);
 
} while (t.tv_nsec <= 40000000L);
testactive = 0;
 
// sys_status(0xFFFF);
// return 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<min(useds,20); i++)
kern_printf("%6d: pid %6d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
// sys_end();
 
kern_printf("DENTRO MAIN %d\n",ll_context_save());
return 0;
}
/demos/branches/pj/oldexamples/kernel/test2.c
0,0 → 1,161
/*
* 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: test2.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 2:
task_testcancel,
task_delay
task_setcancelstate
 
The task 2 disappear after time 10000 because we have reactivated
the cancelability and a testcancel is issued
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
int i;
struct timespec t;
// int last = 0;
 
task_setcancelstate(TASK_CANCEL_DISABLE,&i);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// printf_xy(10,8,WHITE,"%9d s%9d n%9d",exec_shadow,t.tv_sec,t.tv_nsec);
 
if (t.tv_nsec > 10000000)
{
task_setcancelstate(TASK_CANCEL_ENABLE,&i);
}
if (t.tv_nsec > 5000000)
{
// kern_printf("\n%d %dÄ", exec_shadow, proc_table[exec_shadow].control);
task_testcancel();
}
task_delay(1000);
// kern_printf("Dopo Delay %d ",exec_shadow);
 
} while (t.tv_nsec <= 30000000L);
}
 
TASK pippo2()
{
int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// printf_xy(10,9,WHITE,"%d s%9d n%9d\n",exec_shadow,t.tv_sec,t.tv_nsec);
// kern_printf("Û%dÛ",proc_table[exec_shadow].control);
 
if (t.tv_nsec > 15000000)
{
// kern_printf("XXXXXXXXXX");
task_setcanceltype(TASK_CANCEL_ASYNCHRONOUS,&i);
}
task_delay(1000);
 
} while (t.tv_nsec <= 30000000L);
}
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
PID p2,p3;
// int k=1;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_create("pippo2", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
p3 = task_create("pippo3", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo3 task...\n"); return 1; }
 
group_activate(1);
 
 
task_kill(p2);
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
task_kill(p3);
 
} while (t.tv_nsec <= 20000000L);
testactive = 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testr.c
0,0 → 1,231
/*
* 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: testr.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 27 (R):
 
This test verify the correctness of the condition variables.
(... it doesn't test all...)
 
The test uses 1 mutex
 
the main task (NRT) creates three tasks.
 
J0, J1, J3
starts, lock the mutex, and wait on a condition variable
 
J2
at t = 0.5 lock the mutex and call cond_signal
at t = 1 lock the mutex and call cond_signal
 
 
**/
 
/*
* 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 "drivers/keyb.h"
 
 
mutex_t m0;
cond_t c0;
 
int number = 0;
 
PID p0,p1,p2,p3;
 
TASK j0()
{
kern_printf("J0: before locking m0\n");
mutex_lock(&m0);
kern_printf("J0: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("J0: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
kern_printf("J0: unlocked m0, end task\n");
return 0;
}
 
 
TASK j1()
{
kern_printf("J1: before locking m0\n");
mutex_lock(&m0);
kern_printf("J1: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("J1: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
kern_printf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
// struct timespec t;
 
kern_printf("J2: started, waiting t=0.5 sec\n");
while (sys_gettime(NULL) < 500000);
 
kern_printf("J2: before locking m0\n");
mutex_lock(&m0);
kern_printf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
kern_printf("J2: unlocking m0\n");
mutex_unlock(&m0);
 
kern_printf("J2: waiting t=1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
kern_printf("J2: Killing J3\n");
task_kill(p3);
kern_printf("J2: before locking m0\n");
mutex_lock(&m0);
kern_printf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
kern_printf("J2: unlocking m0\n");
mutex_unlock(&m0);
kern_printf("J2: unlocked m0, end task\n");
return 0;
}
 
void cleanup_lock(void *arg)
{
kern_printf("J3: KILL!!!\n");
mutex_unlock(&m0);
kern_printf("J3: unlocked m0 by the cleanup function\n");
}
 
TASK j3()
{
kern_printf("J3: before locking m0\n");
mutex_lock(&m0);
kern_printf("J3: locked m0, waiting on c0, number =%d\n", number);
task_cleanup_push(cleanup_lock, (void *)&m0);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("J3: number = %d, if >0 unlocking m0\n",number);
}
task_cleanup_pop(0);
// I hope this task never reach this point... it is killed by J2!!!
number--;
mutex_unlock(&m0);
kern_printf("J3: unlocked m0, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
// struct timespec t;
 
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
p0 = task_create("J0", j0, &m, NULL);
if (p0 == NIL)
{ kern_printf("Can't create J0 task...\n"); return 1; }
 
p1 = task_create("J1", j1, &m, NULL);
if (p1 == NIL)
{ kern_printf("Can't create J1 task...\n"); return 1; }
 
p2 = task_create("J2", j2, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create J2 task...\n"); return 1; }
 
p3 = task_create("J3", j3, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create J3 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m0,&a);
 
cond_init(&c0);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
group_activate(1);
 
kern_printf("END main\n");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/tests.c
0,0 → 1,79
/*
* 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: tests.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
memtest.c:
 
try to allocate different regions of memory...
 
**/
 
/*
* 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"
 
int main(int argc, char **argv)
{
void *a;
 
kern_cli(); a = DOS_alloc(4500); kern_sti();
kern_printf("below 1 M: %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_UNDER_16M,10,0); kern_sti();
kern_printf("below 16M: %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_FROM_1M_TO_16M,2,0); kern_sti();
kern_printf(">1M <16M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc(10000); kern_sti();
kern_printf("normal : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(MEMORY_UNDER_1M); kern_sti();
kern_printf("page <1M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(MEMORY_FROM_1M_TO_16M); kern_sti();
kern_printf("p>1<16M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(0); kern_sti();
kern_printf("page : %ld\n", (DWORD)a);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/test3.c
0,0 → 1,137
/*
* 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: test3.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 3:
task_cleanup_push
task_cleanup_pop
 
It may print many 0 and then only one 1
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
void fun1(void *p)
{
kern_printf("ÛÛ %d ÛÛ",(int)p);
}
 
 
TASK pippo()
{
int i;
struct timespec t;
int last = 0;
task_cleanup_push(fun1,(void *)1);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (t.tv_nsec > 5000000)
{
task_testcancel();
 
task_cleanup_push(fun1,(void *)-1);
task_cleanup_push(fun1,(void *)0);
task_cleanup_pop(1);
task_cleanup_pop(0);
}
task_delay(1000);
 
} while (t.tv_nsec <= 30000000L);
task_cleanup_pop(1);
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
PID p2,p3;
int k=1;
int i;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_create("pippo2", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
group_activate(1);
 
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (t.tv_nsec > 10000000) task_kill(p2);
} while (t.tv_nsec <= 20000000L);
testactive = 0;
 
return 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %6d stime %6d reschedule %6d avail %6d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/test4.c
0,0 → 1,67
/*
* 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: test4.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 4:
 
this test is a simple main() function
 
This test has to be compiled with init1.c, that introduce 2 RR levels
with a timeslice of 300us (!)
 
This test can be useful to test functions like
 
perror
 
**/
 
/*
* 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"
 
int main(int argc, char **argv)
{
errno = EUNVALID_KILL; kern_printf("code: %d ",errno); perror("EUNVALID_KILL");
errno = EINVAL; kern_printf("code: %d ",errno); perror("EINVAL");
errno = ENOMEDIUM; kern_printf("code: %d ",errno); perror("ENOMEDIUM");
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/test5.c
0,0 → 1,165
/*
* 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: test5.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 5:
 
this test is a simple main() function with one other task
 
This test has to be compiled with init1.c, that introduce 2 RR levels
with a timeslice of 300us (!)
 
This test can be useful to test functions like
 
sigemptyset
sigaddset
hartik_deliver_pending_signals
sys_end
task_sigmask
sigaction
sigqueue
task_signal
 
 
**/
 
/*
* 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"
 
 
TASK pippo()
{
struct timespec t;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 20000000L);
cli(); kern_printf("pippo"); sti();
return 0;
}
 
void catchit(int signo, siginfo_t *info, void *extra)
{
kern_printf("\nÛ exec_shadow= %d signo=%d code=%d value=%d p=%d Û\n",
exec_shadow,
info->si_signo, info->si_code,
info->si_value.sival_int, info->si_task);
}
 
 
void catchit2(int signo)
{
kern_printf("\nSignal %d: AAARRRRRRGGGGHHHH!!!!\n",signo);
}
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
PID p2;
 
sigset_t newmask;
sigset_t oldmask;
struct sigaction action;
union sigval sval;
 
 
/* Set the signal action */
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = catchit;
action.sa_handler = 0;
action.sa_mask = 0;
 
if (sigaction(SIGUSR1, &action, NULL) == -1) {
perror("Errore");
return -1;
}
 
action.sa_flags = 0;
action.sa_handler = catchit2;
// action.sa_sigaction = SIG_DFL;
 
if (sigaction(SIGILL, &action, NULL) == -1) {
perror("Errore");
return -1;
}
 
/* create another task */
nrt_task_default_model(m);
nrt_task_def_level(m,1);
nrt_task_def_group(m,1);
 
p2 = task_create("pippo", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo task...\n"); return 1; }
 
group_activate(1);
 
/* block the signal for the main task */
sigemptyset(&newmask);
sigaddset(&newmask,SIGUSR1);
task_sigmask(SIG_BLOCK, &newmask, &oldmask);
 
sval.sival_int = 123;
sigqueue(0,SIGUSR1,sval);
sval.sival_int = 999;
sigqueue(0,SIGUSR1,sval);
 
cli();kern_printf("\n()()()()\n"); sti();
 
task_signal(0 /* main */, SIGILL);
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 50000000L);
 
cli();kern_printf("\n()*********()\n"); sti();
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testu.c
0,0 → 1,115
/*
* 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: testu.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number ?? (U):
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the internal_sem functions.
 
 
**/
 
/*
* 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 <kernel/int_sem.h>
 
internal_sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
kern_printf("before internal_sem_wait %d\n",(int)a);
internal_sem_wait(&s);
kern_printf("after internal_sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
kern_printf("before internal_sem_post %d\n",(int)a);
internal_sem_post(&s);
kern_printf("after internal_sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("pippo2", pippo, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
internal_sem_init(&s,1);
 
group_activate(1);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/test6.c
0,0 → 1,465
/*
* 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: test6.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 6:
 
this is a part of the classic Hartik demo Aster.
 
It checks:
- EDF module
. periodic tasks
- an high number of task executing concurrently
 
**/
 
/*
* 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
*
*/
 
/*
Well, this is only a stupid demo which intend to show many
HARTIK+ capabilities; the application is structured in the followig
way: there is an ASTER task wich randomly creates some ASTEROID tasks
which are displayed into the first window; each task is HARD/PERIODIC
and auto-kills itself when it reaches the window end!
An other couple of tasks, TITLE & PUT give an example of port
communication facility; the server task creates the port, the client
task connect to it and uses the server to accomplish some stuff.
Port can be declared READ/WRITE and can model ONE-TO-ONE communication
or MANY-TO-ONE communication.
Finally a second couple of tasks realizes a communiation through CABs;
each time a key is pressed, the ascii code is posted into the CAB by the
CCC task while the second task, WRITE, displays it on the screen and
perform other silly actions.
Finally a CLOCK task is implemented to test system clock.
Please note that usually the HARTIK+ application is made up of a task
group which interacts among them, while the main() function, which
became a task itself when the kernel is activated, is suspended until
the system is ready to terminate; the MAIN task can also be used to make
other background activities, but it should not be killed; when the
application terminates, the control is passed to MAIN which kills
everybody, shut down the system and can handle other operations using
the services available with the previou operating system (I.E. the DOS).
If you need to manage sudden abort/exception you should install your own
exception handler and raise it through the exc_raise() primitive to
make the system abort safely!
Remember that the exit functions posted through sys_atexit() will be
executed in both cases, to allow clean system shutdown.
*/
 
//#include <string.h>
//#include <stdlib.h>
 
//#include "hartik.h"
 
//#define __VPAGING__
/* #define __TRACE__ */
 
//#ifdef __TRACE__
//#include "sys\log.h"
//#endif
 
//#include "keyb.h"
//#include "cons.h"
//#include "crtwin.h"
 
#include "kernel/kern.h"
 
 
int num_aster = 0;
#define ASTER_LIM 67
#define ASTER_MAX 90
 
//CAB cc;
//BYTE esc = FALSE;
 
TASK asteroide(void)
{
int i = 1;
int y = rand() % 20 + 1;
while (i < ASTER_LIM) {
puts_xy(i,y,WHITE,"*");
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
num_aster--;
return 0;
}
 
DWORD taskCreated = 0;
 
TASK aster(void)
{
PID p;
 
// MODEL m = BASE_MODEL;
HARD_TASK_MODEL m;
int r;
// WIN w;
 
// win_init(&w,0,0,ASTER_LIM,8);
// win_frame(&w,BLACK,WHITE,"Asteroids",2);
 
 
hard_task_default_model(m);
hard_task_def_wcet(m,500);
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 50) - 25;
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (50+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
taskCreated++;
task_activate(p);
num_aster++;
}
 
task_endcycle();
}
}
 
TASK clock()
{
//WIN w;
int s = 0, m = 0;
 
//win_init(&w,68,0,11,2);
//win_frame(&w,BLACK,WHITE,"Clk",1);
 
while(1) {
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
}
}
 
/*
TASK title()
{
PORT t;
WIN w;
int i,pos = 77;
char msg[85],tmp[85],ss[2];
BYTE c;
win_init(&w,0,9,79,2);
win_frame(&w,BLACK,WHITE,"Title",2);
 
for (i=0; i < 77; i++) msg[i] = ' ';
msg[77] = 0;
 
t = port_connect("title",1,STREAM,READ);
 
while (1) {
port_receive(t,&c,BLOCK);
ss[0] = c;
ss[1] = 0;
strcat(msg,ss);
puts_xy(1,10,WHITE,msg);
pos++;
if (pos > 77) {
strcpy(tmp,&(msg[1]));
tmp[pos-1] = 0;
pos -= 1;
strcpy(msg,tmp);
}
task_endcycle();
}
}
 
#define STR "..................... Hartik+ ....................."\
" Guarantees hard tasks "\
" Includes soft periodic tasks "\
"TB server for decrementing the aperiodic response time "\
"SRP for both hard & soft aperiodic tasks "\
"Portability toward other compilers/system "\
"Support for different C compiler: Watcom C 16 bit & 32 bit"\
" -- GNU C (32 bit) -- Borland C (16 bit) -- MS C (16 bit)"\
" "\
"Programmers : Gerardo Lamastra (lamastra@sssup2.sssup.it) "\
" Giuseppe Lipari (lipari@sssup2.sssup.it) "\
"Alpha AXP PCI-33 porting by Antonino Casile "\
"(casile@sssup1.sssup.it) "\
"Research coordinator: Giorgio Buttazzo (giorgio@sssup1.sssup.it)"\
" "\
" "\
" "
 
static char GreetMsg[1600];
 
TASK put(void)
{
PORT p;
 
strcpy(GreetMsg,STR);
p = port_create("title",strlen(GreetMsg),1,STREAM,WRITE);
while(1) {
port_send(p,GreetMsg,BLOCK);
task_endcycle();
}
}
 
TASK ccc(void)
{
WIN w;
char *m;
 
win_init(&w,68,3,10,3);
win_frame(&w,BLACK,WHITE,"CCC",2);
puts_xy(70,4,WHITE,"Cab");
 
while(1) {
m = cab_getmes(cc);
puts_xy(72,5,WHITE,m);
cab_unget(cc,m);
task_endcycle();
}
}
TASK write()
{
BYTE c;
char *msg;
 
while (1) {
c = keyb_getchar();
if (c == ESC) {
esc = TRUE;
task_sleep();
}
else {
#ifdef __VPAGING__
if (c == 's') {
if (get_visual_page() == 0) set_visual_page(1);
else if (get_visual_page() == 1) set_visual_page(0);
}
#endif
msg = cab_reserve(cc);
msg[0] = c;
msg[1] = 0;
cab_putmes(cc,msg);
}
}
}
 
#define DELTA 200000.0
double carico(double rif,BYTE init)
{
double i;
DWORD t1 = 0,t2 = 1000;
double u;
 
i = 0.0;
do {
i += 1;
} while (i <= DELTA);
 
u = i / ((double) (t2 - t1));
 
if (init) return u;
else return (1.0 - u/rif);
}
 
void my_end(KEY_EVT *e)
{
sys_end();
cprintf("Ctrl-Brk pressed!\n");
l1_exit(1);
}
 
void res(void)
{
sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
}
*/
 
int main(int argc, char **argv)
{
PID p1,p2; //,p3,p4,p5,p6;
HARD_TASK_MODEL m;
 
/* MODEL m = BASE_MODEL;
SYS_PARMS sp = BASE_SYS;
KEY_EVT emerg;
double rif;
 
#ifdef __TRACE__
LOG_INFO li = BASE_LOG;
log_set_limit(li,9000);
log_set_name(li,"aster.hrt");
#endif
sys_def_nocheck(sp);
sys_init(&sp);
sys_atexit(res, BEFORE_EXIT);
 
#ifdef __TRACE__
log_init(&li);
#endif
 
keyb_init(NULL);
keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,my_end);
 
#ifdef __VPAGING__
set_active_page(1);
set_visual_page(1);
#endif
CRSR_OFF();
clear();
puts_xy(0,20,WHITE,"Press ESC to exit demo.");
cc = cab_create("Cab",2,2);
*/
 
hard_task_default_model(m);
hard_task_def_mit(m,10000);
hard_task_def_wcet(m,2000);
hard_task_def_group(m,1);
// periodic_task_def_ctrl_jet(m);
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("Aster.C(main): Could not create task <aster> ...");
sys_end();
l1_exit(-1);
}
 
hard_task_def_mit(m,500000);
p2 = task_create("Clock",clock,&m,NULL);
if (p2 == -1) {
perror("Aster.C(main): Could not create task <Clock> ...");
sys_end();
l1_exit(-1);
}
/* p3 = task_create("Title",title,SOFT,PERIODIC,50,&m);
if (p3 == -1) {
perror();
cprintf("Aster.C(main): Could not create task <Title>\n");
sys_end();
l1_exit(-1);
}
p4 = task_create("Put",put,SOFT,PERIODIC,1000,&m);
if (p4 == -1) {
perror();
cprintf("Aster.C(main): Could not create task <Put>\n");
sys_end();
l1_exit(-1);
}
p5 = task_create("Write",write,NRT,APERIODIC,10,&m);
if (p5 == -1) {
perror();
cprintf("Aster.C(main): Could not create task <Write>\n");
sys_end();
l1_exit(-1);
}
p6 = task_create("CabTask",ccc,HARD,PERIODIC,50,&m);
if (p6 == -1) {
perror();
cprintf("Aster.C(main): Could not create task <CabTask>\n");
sys_end();
l1_exit(-1);
}
#ifdef __TRACE__
log_loop();
#endif
 
task_activate(p1);
task_activate(p2);
task_activate(p3);
task_activate(p4);
task_activate(p5);
task_activate(p6);
 
group_activate(1);
 
while (!esc) {
printf_xy(0,21,WHITE,"Clock : %lu",sys_time());
}
 
#ifdef __TRACE__
log_fix();
#endif
group_kill(1);
clear();
CRSR_STD();
#ifdef __VPAGING__
set_active_page(0);
set_visual_page(0);
#endif
sys_end();
cprintf("System closed\n");
/ *
sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
sys_status(NORM_STATUS|SLEEP_STATUS);
*/
 
group_activate(1);
 
{
struct timespec t;
do {
kern_cli();
ll_gettime(TIME_EXACT,&t);
kern_sti();
} while (t.tv_sec < 6);
}
kern_cli();
sys_status(SCHED_STATUS);
sys_end();
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/sysend.c
0,0 → 1,143
/*
* 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: sysend.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
System termination:
 
the main task create J1, J2 and wait until 1 sec., then it calls sys_end
and cycles around a task_testcancel
 
J1 is a system task that ends at t=1.5 sec.
 
J2 is another user task that dies at t= 1.8 sec (it will not die!!!)
 
 
**/
 
/*
* 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 <sys/types.h>
#include <pthread.h>
#include <signal.h>
 
#include <kernel/kern.h>
#include <drivers/keyb.h>
 
void *J1(void *arg)
{
while (sys_gettime(NULL) < 1500000);
kern_printf("J1: t = 1.5 sec, ending...");
return 0;
}
 
void uscitaJ2(void *arg)
{
kern_printf("J2: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}
 
void *J2(void *arg)
{
task_cleanup_push(uscitaJ2,NULL);
 
while (sys_gettime(NULL) < 1800000);
kern_printf("J1: t = 1.8 sec, ending...");
 
task_cleanup_pop(0);
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
void uscitamain(void *arg)
{
kern_printf("main: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}
 
 
int main(int argc, char **argv)
{
PID err;
 
NRT_TASK_MODEL m1, m2;
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
 
nrt_task_default_model(m1);
nrt_task_def_system(m1);
nrt_task_def_level(m1,1);
nrt_task_default_model(m2);
nrt_task_def_level(m2,1);
 
kern_printf("main: creating J1\n");
err = task_create("J1", J1, (TASK_MODEL *)&m1, NULL);
if (err == -1) kern_printf("Error creating J1\n");
task_activate(err);
 
kern_printf("main: creating J2\n");
err = task_create("J2", J2, (TASK_MODEL *)&m2, NULL);
if (err == -1) kern_printf("Error creating J2\n");
task_activate(err);
 
kern_printf("main: waiting 1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
kern_printf("main: sys_end()\n");
 
sys_end();
 
task_cleanup_push(uscitamain,NULL);
 
while (1)
task_testcancel();
 
task_cleanup_pop(0);
 
return 0;
}
/demos/branches/pj/oldexamples/kernel/testw.c
0,0 → 1,42
//#include <string.h>
//#include <stdlib.h>
//#include <cons.h>
 
 
#include <kernel/kern.h>
#include <drivers/keyb.h>
 
int main(int argc, char **argv)
{
KEY_EVT k;
clear();
k.ascii = 0;
while (k.ascii != ESC) {
keyb_getcode(&k,BLOCK);
if (k.ascii == '2') {
keyb_set_map(itaMap);
cprintf("\nItalian Keymap set\n");
}
if (k.ascii == '3') {
keyb_set_map(engMap);
cprintf("\nEnglish Keymap set\n");
}
if (isLeftCtrl(k)) putc_xy(72+0,0,RED,'L');
else putc_xy(72+0,0,RED,' ');
if (isRightCtrl(k)) putc_xy(72+1,0,RED,'R');
else putc_xy(72+1,0,RED,' ');
if (isLeftAlt(k)) putc_xy(72+2,0,GREEN,'L');
else putc_xy(72+2,0,RED,' ');
if (isRightAlt(k)) putc_xy(72+3,0,GREEN,'R');
else putc_xy(72+3,0,RED,' ');
if (isLeftShift(k)) putc_xy(72+4,0,YELLOW,'L');
else putc_xy(72+4,0,RED,' ');
if (isRightShift(k)) putc_xy(72+5,0,YELLOW,'R');
else putc_xy(72+5,0,RED,' ');
cprintf("%d [%c]\t",k.scan,k.ascii);
 
}
sys_end();
return 0;
}
/demos/branches/pj/oldexamples/kernel/test7.c
0,0 → 1,253
/*
* 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: test7.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 7:
 
this is a part of the classic Hartik demo Aster.
 
It checks:
- jet functions
- The EDF level with many task, with almost full bandwidth used
 
**/
 
/*
* 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"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
// first numbers for wcet and periods are for a 486/25, the others for a
// celeron 366
 
#define PER_WCET 13000 /*6200*/
#define CLOCK_WCET 1200 /* 100*/
#define ASTER_WCET 1200 /* 100*/
 
#define ASTER_MEAN_PERIOD 64 /*64*/
 
#define END_TEST_TIME 50
 
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 = 1000; //10000; // 5000 + rand()%5000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = ASTER_MEAN_PERIOD;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",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,"U=%12u",EDF_usedbandwidth(0));
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,"U=%12u",EDF_usedbandwidth(0));
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) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
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++;
}
}
}
 
int main(int argc, char **argv)
{
PID p1,p2,p3; //,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
 
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);
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);
if (p2 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
group_activate(1);
 
{
struct timespec t;
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_sec < END_TEST_TIME);
}
//sys_status(SCHED_STATUS);
kern_printf("ora chiamo sys_end\n");
sys_end();
kern_printf("ho chiamato sys_end\n");
return 0;
}
 
 
 
 
/demos/branches/pj/oldexamples/kernel/test8.c
0,0 → 1,81
/*
* 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: test8.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 8:
 
timer test
 
**/
 
/*
* 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"
 
#define NT 10
 
int main(int argc, char **argv)
{
 
struct timespec t[NT];
int i;
 
kern_printf("Test di correttezza ll_gettime(). dura 1 secondo. ");
 
for (i=0; i<NT; i++) NULL_TIMESPEC(&t[i]);
 
do {
for (i=0; i<NT-1; i++) t[i+1] = t[i];
 
kern_cli();
ll_gettime(TIME_EXACT, &t[0]);
kern_sti();
 
if (TIMESPEC_A_LT_B(&t[0],&t[1])) {
for (i=0; i<NT; i++)
kern_printf("%d %ld\n",i, t[i].tv_nsec);
sys_end();
}
} while (t[0].tv_sec < 1);
 
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/test9.c
0,0 → 1,234
/*
* 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: test9.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 9:
 
same as Test 7, with 8 TBS tasks running
 
TBS test
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
TASK pippo()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_nsec <= 30000000L);
}
 
TASK pippo2()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 30000000L);
}
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
if (i==7) testactive = 0;
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
TASK aper(void *a)
{
int i;
int y;
 
int load1,j;
 
char s[2];
 
y = (int) a;
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 100000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_sleep();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_aper;
PID p1, p2, p3, p4, p5;
int k=1;
 
srand(7);
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p1 = task_create("pippo", pippo, &m, NULL);
if (p1 == NIL)
{ kern_printf("Can't create pippo task...\n"); sys_end(); }
 
p2 = task_create("pippo2", pippo2, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); sys_end(); }
 
hard_task_default_model(m_per);
hard_task_def_wcet(m_per,6200);
hard_task_def_mit(m_per,15000);
hard_task_def_group(m_per,1);
p3 = task_create("asteroide", asteroide, &m_per, NULL);
if (p3 == NIL)
{ kern_printf("Can't create asteroide task...\n"); sys_end(); }
 
soft_task_default_model(m_aper);
soft_task_def_wcet(m_aper,62000);
soft_task_def_group(m_aper,1);
soft_task_def_system(m_aper);
soft_task_def_arg(m_aper, 14);
soft_task_def_aperiodic(m_aper);
p4 = task_create("aper", aper, &m_aper, NULL);
if (p4 == NIL)
{ kern_printf("Can't create aper task...%d \n",errno); sys_end(); }
 
soft_task_def_arg(m_aper, 13);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); sys_end(); }
 
soft_task_def_arg(m_aper, 12);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); sys_end(); }
 
soft_task_def_arg(m_aper, 11);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); sys_end(); }
 
// kern_printf("p1=%d p2=%d p3=%d p4=%d\n",p1,p2,p3,p4);
group_activate(1);
 
 
// task_kill(p2);
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
// task_kill(p3);
} while (t.tv_sec < 1);
testactive = 0;
/*
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
*/
return 0;
}
/demos/branches/pj/oldexamples/kernel/testz.c
0,0 → 1,456
/*
* 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: testz.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Author: Gerardo Lamastra
Giuseppe Lipari
Date: 1/10/96
 
File: Aster.C
Revision: 1.6
 
**/
 
/*
* 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
*
*/
 
/*
Well, this is only a stupid demo which intend to show many
HARTIK+ capabilities; the application is structured in the followig
way: there is an ASTER task wich randomly creates some ASTEROID tasks
which are displayed into the first window; each task is HARD/PERIODIC
and auto-kills itself when it reaches the window end!
An other couple of tasks, TITLE & PUT give an example of port
communication facility; the server task creates the port, the client
task connect to it and uses the server to accomplish some stuff.
Port can be declared READ/WRITE and can model ONE-TO-ONE communication
or MANY-TO-ONE communication.
Finally a second couple of tasks realizes a communiation through CABs;
each time a key is pressed, the ascii code is posted into the CAB by the
CCC task while the second task, WRITE, displays it on the screen and
perform other silly actions.
Finally a CLOCK task is implemented to test system clock.
Please note that usually the HARTIK+ application is made up of a task
group which interacts among them, while the main() function, which
became a task itself when the kernel is activated, is suspended until
the system is ready to terminate; the MAIN task can also be used to make
other background activities, but it should not be killed; when the
application terminates, the control is passed to MAIN which kills
everybody, shut down the system and can handle other operations using
the services available with the previou operating system (I.E. the DOS).
If you need to manage sudden abort/exception you should install your own
exception handler and raise it through the exc_raise() primitive to
make the system abort safely!
Remember that the exit functions posted through sys_atexit() will be
executed in both cases, to allow clean system shutdown.
*/
 
//#include <string.h>
//#include <stdlib.h>
 
#include <kernel/kern.h>
#include <modules/sem.h>
#include <modules/hartport.h>
#include <modules/cabs.h>
#include <drivers/keyb.h>
#include <string.h>
 
 
#define __VPAGING__
 
 
#ifdef __TRACE__
#undef __TRACE__
#endif
 
/* #define __TRACE__ */
 
#ifdef __TRACE__
#include "sys\log.h"
#endif
 
#include <drivers/keyb.h>
//#include cons.h
#include <drivers/crtwin.h>
 
int num_aster = 0;
#define ASTER_LIM 67
 
CAB cc;
BYTE esc = FALSE;
 
TASK asteroide(void)
{
int i = 1;
int y = rand() % 7 + 1;
while (i < ASTER_LIM) {
puts_xy(i,y,WHITE,"*");
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
num_aster--;
return 0;
}
 
DWORD taskCreated = 0;
 
TASK aster(void)
{
PID p;
SOFT_TASK_MODEL m_soft;
int r;
WIN w;
 
win_init(&w,0,0,ASTER_LIM,8);
win_frame(&w,BLACK,WHITE,"Asteroids",2);
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,2000);
soft_task_def_ctrl_jet(m_soft);
 
srand(7);
while (1) {
if (num_aster < 5) {
r = (rand() % 50) - 25;
soft_task_def_arg(m_soft,(void *)((rand() % 7)+1));
soft_task_def_period(m_soft,(50 + r)*1000);
p = task_create("aaa",asteroide,(TASK_MODEL *)&m_soft,NULL);
taskCreated++;
task_activate(p);
num_aster++;
}
 
task_endcycle();
}
}
 
TASK clock()
{
WIN w;
int s = 0, m = 0;
 
win_init(&w,68,0,11,2);
win_frame(&w,BLACK,WHITE,"Clk",1);
 
while(1) {
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
}
}
 
TASK title()
{
PORT t;
WIN w;
int i,pos = 77;
char msg[85],tmp[85],ss[2];
BYTE c;
win_init(&w,0,9,79,2);
win_frame(&w,BLACK,WHITE,"Title",2);
 
for (i=0; i < 77; i++) msg[i] = ' ';
msg[77] = 0;
 
t = port_connect("title",1,STREAM,READ);
 
while (1) {
port_receive(t,&c,BLOCK);
ss[0] = c;
ss[1] = 0;
strcat(msg,ss);
puts_xy(1,10,WHITE,msg);
pos++;
if (pos > 77) {
strcpy(tmp,&(msg[1]));
tmp[pos-1] = 0;
pos -= 1;
strcpy(msg,tmp);
}
task_endcycle();
}
}
 
#define STR "..................... Hartik+ ....................."\
" Guarantees hard tasks "\
" Includes soft periodic tasks "\
"TB server for decrementing the aperiodic response time "\
"SRP for both hard & soft aperiodic tasks "\
"Portability toward other compilers/system "\
"Support for different C compiler: Watcom C 16 bit & 32 bit"\
" -- GNU C (32 bit) -- Borland C (16 bit) -- MS C (16 bit)"\
" "\
"Programmers : Gerardo Lamastra (lamastra@sssup2.sssup.it) "\
" Giuseppe Lipari (lipari@sssup2.sssup.it) "\
"Alpha AXP PCI-33 porting by Antonino Casile "\
"(casile@sssup1.sssup.it) "\
"Research coordinator: Giorgio Buttazzo (giorgio@sssup1.sssup.it)"\
" "\
" "\
" "
 
static char GreetMsg[1600];
 
TASK put(void)
{
PORT p;
 
strcpy(GreetMsg,STR);
p = port_create("title",strlen(GreetMsg),1,STREAM,WRITE);
while(1) {
port_send(p,GreetMsg,BLOCK);
task_endcycle();
}
}
 
TASK ccc(void)
{
WIN w;
char *m;
 
win_init(&w,68,3,10,3);
win_frame(&w,BLACK,WHITE,"CCC",2);
puts_xy(70,4,WHITE,"Cab");
 
while(1) {
m = cab_getmes(cc);
puts_xy(72,5,WHITE,m);
cab_unget(cc,m);
task_endcycle();
}
}
TASK write_keyb()
{
BYTE c;
char *msg;
 
while (1) {
c = keyb_getchar();
if (c == ESC) {
esc = TRUE;
task_sleep();
}
else {
#ifdef __VPAGING__
if (c == 's') {
if (get_visual_page() == 0) set_visual_page(1);
else if (get_visual_page() == 1) set_visual_page(0);
}
#endif
msg = cab_reserve(cc);
msg[0] = c;
msg[1] = 0;
cab_putmes(cc,msg);
}
}
}
 
#define DELTA 200000.0
double carico(double rif,BYTE init)
{
double i;
DWORD t1 = 0,t2 = 1000;
double u;
 
i = 0.0;
do {
i += 1;
} while (i <= DELTA);
 
u = i / ((double) (t2 - t1));
 
if (init) return u;
else return (1.0 - u/rif);
}
 
void my_end(KEY_EVT *e)
{
set_active_page(0);
set_visual_page(0);
cprintf("Ctrl-Brk pressed!\n");
sys_end();
}
 
void res(void *arg)
{
sys_status(CLOCK_STATUS|SCHED_STATUS);
}
 
int main(int argc, char **argv)
{
PID p1,p2,p3,p4,p5,p6;
 
HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_soft;
NRT_TASK_MODEL m_nrt;
 
KEY_EVT emerg;
// double rif;
struct timespec t;
#ifdef __TRACE__
LOG_INFO li = BASE_LOG;
log_set_limit(li,9000);
log_set_name(li,"aster.hrt");
#endif
 
sys_atrunlevel(res, NULL, RUNLEVEL_BEFORE_EXIT);
 
#ifdef __TRACE__
log_init(&li);
#endif
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,my_end);
 
#ifdef __VPAGING__
set_active_page(1);
set_visual_page(1);
#endif
CRSR_OFF();
clear();
puts_xy(0,20,WHITE,"Press ESC to exit demo.");
cc = cab_create("Cab",2,2);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,500000);
soft_task_def_met(m_soft,1000);
soft_task_def_group(m_soft, 1);
p1 = task_create("Aster",aster,&m_soft,NULL);
if (p1 == -1) {
perror("Aster.C(main): Could not create task <aster>");
sys_abort(-1);
}
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,500000);
hard_task_def_wcet(m_per,1000);
hard_task_def_group(m_per, 1);
p2 = task_create("Clock",clock,&m_per,NULL);
if (p2 == -1) {
perror("Aster.C(main): Could not create task <Clock>");
sys_abort(-1);
}
 
soft_task_def_period(m_soft, 50000);
p3 = task_create("Title",title,&m_soft, NULL);
if (p3 == -1) {
perror("Aster.C(main): Could not create task <Title>");
sys_abort(-1);
}
 
soft_task_def_period(m_soft, 1000000);
p4 = task_create("Put",put,&m_soft, NULL);
if (p4 == -1) {
perror("Aster.C(main): Could not create task <Put>");
sys_abort(-1);
}
 
nrt_task_default_model(m_nrt);
nrt_task_def_group(m_nrt, 1);
p5 = task_create("Write",write_keyb,&m_nrt,NULL);
if (p5 == -1) {
perror("Aster.C(main): Could not create task <Write>");
sys_abort(-1);
}
 
hard_task_def_mit(m_per, 50000);
p6 = task_create("CabTask",ccc,&m_per,NULL);
if (p6 == -1) {
perror("Aster.C(main): Could not create task <CabTask>\n");
sys_abort(-1);
}
#ifdef __TRACE__
log_loop();
#endif
/*
task_activate(p1);
task_activate(p2);
task_activate(p3);
task_activate(p4);
task_activate(p5);
task_activate(p6);
*/
group_activate(1);
 
while (!esc) {
kern_cli();
ll_gettime(TIME_EXACT,&t);
kern_sti();
 
printf_xy(0,21,WHITE,"Clock : %-9ds %-9dns",(int)t.tv_sec, (int)t.tv_nsec);
}
 
#ifdef __TRACE__
log_fix();
#endif
group_kill(1);
clear();
CRSR_STD();
#ifdef __VPAGING__
set_active_page(0);
set_visual_page(0);
#endif
cprintf("System closed\n");
sys_end();
/*
sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
sys_status(NORM_STATUS|SLEEP_STATUS);
*/
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/testss.c
0,0 → 1,547
/*
* 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: testss.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test for Sporadic Server (ss):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a sporadic server
There are two "dummy" tasks that increment a counter and print
the value. One uses a SOFT_TASK_MODEL served by sporadic server,
the other uses a NRT_TASK_MODEL handled by RR module.
 
**/
 
/*
* 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"
#include "modules/ss.h"
#include "drivers/keyb.h"
 
int num_aster = 0;
#define EDF_LEV 0
#define CBS_LEV 1
#define SS_LEV 2
 
#define ASTER_LIM 60
#define DISPLAY_MAX 8
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
#define PER_WCET 16000
#define APER_WCET 22000
#define JET_WCET 20000
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define PCMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 12000 /* 12000 */
#define CLOCK_WCET 300 /* 300*/
#define ASTER_WCET 300 /* 300*/
#else
#define SOFT_MET 5000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
PID p1,p2,p3,p4,p5;
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_unlock(&m1);
#endif
mutex_lock(&m1);
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
//mutex_lock(&m1);
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
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);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(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);
// soft_task_def_aperiodic(m_soft);
 
x = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
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;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
 
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
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) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 1)
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(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), 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, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, nact, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , last[3], last[4]);
mutex_unlock(&m1);
i++;
task_activate(p3);
task_endcycle();
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
void mydummyaper(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(1,24,RED,"dummyAPER pid=%d: %d",p4,i++);
mutex_unlock(&m1);
task_activate(p4);
task_endcycle();
}
}
 
void mydummynrt(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(40,24,RED,"dummyNRT pid=%d: %d",p5,i++);
mutex_unlock(&m1);
}
}
 
int main(int argc, char **argv)
{
// PID p1,p2,p5;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft;
struct timespec fineprg;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef PCMUTEX
PC_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
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_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,10000);
soft_task_def_met(m_soft,JET_WCET);
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,50000);
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_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
p4 = task_create("MyDummyAper",(void *(*)(void*))mydummyaper,&m_aper,NULL);
if (p4 == -1) {
perror("Could not create task <MyDummyAper> ...");
sys_end();
l1_exit(-1);
}
 
p5 = task_create("MyDummyNRT",(void *(*)(void*))mydummynrt,&m_nrt,NULL);
if (p5 == -1) {
perror("Could not create task <MyDummyNRT> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
 
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef PCMUTEX
PC_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
return 0;
}
 
/demos/branches/pj/oldexamples/kernel/makefile
0,0 → 1,97
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS= test4 test5 test6 test7 test8 testa testc testd teste testf testg
PROGS+= testh testi testj testk testl testm testn testo testp
PROGS+= testq testr tests testu testw testz testss
PROGS+= ptest1 ptest2 ptest3 ptest4 ptest5 ptest6 sysend
PROGS+= perf1 perf2 perf3 perf4
 
include $(BASE)/config/example.mk
 
test4:
make -f $(SUBMAKE) APP=test4 INIT=init1.o OTHEROBJS=
test5:
make -f $(SUBMAKE) APP=test5 INIT=init1.o OTHEROBJS=
test6:
make -f $(SUBMAKE) APP=test6 INIT=init2.o OTHEROBJS=
test7:
make -f $(SUBMAKE) APP=test7 INIT=init2.o OTHEROBJS=
test8:
make -f $(SUBMAKE) APP=test8 INIT=init2.o OTHEROBJS=
testa:
make -f $(SUBMAKE) APP=testa INIT=init3.o OTHEROBJS=
testc:
make -f $(SUBMAKE) APP=testc INIT=init4.o OTHEROBJS=
testd:
make -f $(SUBMAKE) APP=testd INIT=init5.o OTHEROBJS=
teste:
make -f $(SUBMAKE) APP=teste INIT=init6.o OTHEROBJS=
testf:
make -f $(SUBMAKE) APP=testf INIT=h3pi.o OTHEROBJS=
testg:
make -f $(SUBMAKE) APP=testg INIT=initg.o OTHEROBJS=
testh:
make -f $(SUBMAKE) APP=testh INIT=h3pi.o OTHEROBJS=
testi:
make -f $(SUBMAKE) APP=testi INIT=h3pi.o OTHEROBJS=
testj:
make -f $(SUBMAKE) APP=testj INIT=h3pi.o OTHEROBJS=
testk:
make -f $(SUBMAKE) APP=testk INIT=h3pi.o OTHEROBJS=
testl:
make -f $(SUBMAKE) APP=testl INIT=h3pips.o OTHEROBJS=
testm:
make -f $(SUBMAKE) APP=testm INIT=rm1.o OTHEROBJS=
testn:
make -f $(SUBMAKE) APP=testn INIT=hartik3.o OTHEROBJS=
testo:
make -f $(SUBMAKE) APP=testo INIT=hartik3.o OTHEROBJS=
testp:
make -f $(SUBMAKE) APP=testp INIT=hartik3.o OTHEROBJS=
testq:
make -f $(SUBMAKE) APP=testq INIT=h3pips.o OTHEROBJS=
testr:
make -f $(SUBMAKE) APP=testr INIT=h3pips.o OTHEROBJS=
tests:
make -f $(SUBMAKE) APP=tests INIT=hartik3.o OTHEROBJS=
testu:
make -f $(SUBMAKE) APP=testu INIT=h3pips.o OTHEROBJS=
testw:
make -f $(SUBMAKE) APP=testw INIT=pinit.o OTHEROBJS=
testz:
make -f $(SUBMAKE) APP=testz INIT=hartik3.o OTHEROBJS=
testss:
make -f $(SUBMAKE) APP=testss INIT=h3piss.o OTHEROBJS=
 
 
ptest1:
make -f $(SUBMAKE) APP=ptest1 INIT=pinit.o OTHEROBJS=
ptest2:
make -f $(SUBMAKE) APP=ptest2 INIT=pinit.o OTHEROBJS=
ptest3:
make -f $(SUBMAKE) APP=ptest3 INIT=pinit.o OTHEROBJS=
ptest4:
make -f $(SUBMAKE) APP=ptest4 INIT=pinit.o OTHEROBJS=
ptest5:
make -f $(SUBMAKE) APP=ptest5 INIT=pinit.o OTHEROBJS=
ptest6:
make -f $(SUBMAKE) APP=ptest6 INIT=pinit.o OTHEROBJS=
sysend:
make -f $(SUBMAKE) APP=sysend INIT=init1.o OTHEROBJS=
 
perf1:
make -f $(SUBMAKE) APP=perf1 INIT= OTHEROBJS=
perf2:
make -f $(SUBMAKE) APP=perf2 INIT=init5.o OTHEROBJS=
perf3:
make -f $(SUBMAKE) APP=perf3 INIT=init5.o OTHEROBJS=
perf4:
make -f $(SUBMAKE) APP=perf4 INIT= OTHEROBJS=
 
/demos/branches/pj/oldexamples/stdio/initfs.c
File deleted
/demos/branches/pj/oldexamples/stdio/makefile
13,16 → 13,16
include $(BASE)/config/example.mk
 
test0:
make -f $(SUBMAKE) BASE=$(BASE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
 
test1:
make -f $(SUBMAKE) BASE=$(BASE) APP=test1 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test1 INIT=initfs.o OTHEROBJS=common.o
 
test2:
make -f $(SUBMAKE) BASE=$(BASE) APP=test2 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test2 INIT=initfs.o OTHEROBJS=common.o
 
test3:
make -f $(SUBMAKE) BASE=$(BASE) APP=test3 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test3 INIT=initfs.o OTHEROBJS=common.o
 
test4:
make -f $(SUBMAKE) BASE=$(BASE) APP=test4 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test4 INIT=initfs.o OTHEROBJS=common.o
/demos/branches/pj/oldexamples/fs/initfs.c
File deleted
/demos/branches/pj/oldexamples/fs/makefile
21,25 → 21,25
#
 
hello:
make -f $(SUBMAKE) BASE=$(BASE) APP=hello INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=hello INIT=initfs.o OTHEROBJS=common.o
 
test0:
make -f $(SUBMAKE) BASE=$(BASE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
 
test1:
make -f $(SUBMAKE) BASE=$(BASE) APP=test1 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=test1 INIT=initfs.o OTHEROBJS=common.o
 
testu:
make -f $(SUBMAKE) BASE=$(BASE) APP=testu INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=testu INIT=initfs.o OTHEROBJS=common.o
 
testw0:
make -f $(SUBMAKE) BASE=$(BASE) APP=testw0 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=testw0 INIT=initfs.o OTHEROBJS=common.o
 
testw1:
make -f $(SUBMAKE) BASE=$(BASE) APP=testw1 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=testw1 INIT=initfs.o OTHEROBJS=common.o
 
tree1:
make -f $(SUBMAKE) BASE=$(BASE) APP=tree1 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=tree1 INIT=initfs.o OTHEROBJS=common.o
 
tree2:
make -f $(SUBMAKE) BASE=$(BASE) APP=tree2 INIT=initfs.o OTHEROBJS=common.o
make -f $(SUBMAKE) APP=tree2 INIT=initfs.o OTHEROBJS=common.o
/demos/branches/pj/oldexamples/mpeg/initfs.c
File deleted
/demos/branches/pj/oldexamples/block/idetest0.c
0,0 → 1,15
/*
*
*
*
*/
 
#include <fs/bdev.h>
 
#include "common.h"
 
int main(int argc,char *argv[])
{
showmessage("Have ide devices been found?\n");
return 0;
}
/demos/branches/pj/oldexamples/block/idetest1.c
0,0 → 1,20
/*
*
*
*
*/
 
#include <fs/bdev.h>
 
#include "common.h"
 
int main(int argc,char *argv[])
{
 
showmessage("This test try to identify the partions of all hard disks\n");
bdev_dump_names();
 
waitend();
return 0;
}
/demos/branches/pj/oldexamples/block/idetest2.c
0,0 → 1,77
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
 
__uint8_t buffer[2048] __attribute__ ((aligned (4)));
__dev_t dev;
 
extern char *ide_error_msg[];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int c;
 
showmessage("This test try to read some blocks from first hard disk\n");
 
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("Can't find device to operate with\n");
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
 
blk=0;
for (;;) {
cprintf("Commands: x-exit r-read n-next block p-prev block\n");
c = keyb_getchar();
switch(c) {
case 'x':
return 0;
 
case 'n':
blk++;
cprintf("Block %li\n",(long)blk);
break;
 
case 'p':
if (blk>=0) blk--;
cprintf("Block %li\n",(long)blk);
break;
case 'r':
cprintf("Reading block %li...\n",(long)blk);
memset(buffer,0xff,sizeof(buffer));
res=bdev_read(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
}
debug_dump_buffer(buffer,64);
break;
 
default:
cprintf("Invalid command!\n");
break;
}
cprintf("\n");
}
return 0;
}
/demos/branches/pj/oldexamples/block/idelin.c
0,0 → 1,71
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <stdlib.h>
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda"
 
#define TEST_MB 16
 
#define NUMBLOCK (TEST_MB*1024l*1024l/512l)
 
__dev_t dev;
 
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int errors;
TIME sttime,etime;
 
showmessage("\n"
"This test read data from first hard disk to test\n"
"disk throughtput.\n"
"Remeber that the reads are made block by block so\n"
"don't worry if you see a low throughtput.\n"
);
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("\nCan't find device to operate with\n");
return -1;
}
cprintf("\nUsing device %s (dev=%04x)\n",DISKDEVICE,dev);
 
cprintf("Please wait (reading %i MB linearly?!?)...",TEST_MB);
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<NUMBLOCK;blk++) {
res=bdev_read(dev,blk,buffer);
//res=bdev_seek(dev,blk);
if (res!=0) errors++;
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("throughtput : %6.3f MB/s\n",
NUMBLOCK*512.0/1024.0/1024.0/etime*1000000.0);
//cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/branches/pj/oldexamples/block/idetest3.c
0,0 → 1,66
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
#define BLOCKNUMBER 58549
 
__uint8_t buffer[2048] __attribute__ ((aligned (4)));
 
extern char *ide_error_msg[];
 
int main(int argc,char *argv[])
{
__dev_t dev;
__blkcnt_t blk;
int res;
// int c;
 
showmessage("This test tries to read a block from the first hard disk\n"
"and then it tries to write it to disk\n"
"Press [CTRL-C] to abort...");
dev=bdev_find_byname(DISKDEVICE);
if ((int)dev<0) {
cprintf("Can't find device to operate with\n");
cprintf("%s not present!\n",DISKDEVICE);
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
blk=BLOCKNUMBER;
 
cprintf("Reading block %li...\n",(long)blk);
memset(buffer,0xff,sizeof(buffer));
res=bdev_read(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
return -1;
}
debug_dump_buffer(buffer,64);
 
cprintf("Writing block %li...\n",(long)blk);
res=bdev_write(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
}
 
waitend();
return 0;
}
/demos/branches/pj/oldexamples/block/idetx430.c
0,0 → 1,79
/*
*
*
*
*/
 
#include <ll/ll.h>
#include <ll/stdlib.h>
#include <kernel/func.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/util.h>
#include <fs/bdev.h>
 
#include "../ide.h"
#include "../debug.h"
 
#define DISKDEVICE "ide/hda1"
 
#define NUMBLOCK 1000
 
__dev_t dev;
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,TRUE);
bdev_init(&bdev);
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("Can't find device to operate with\n");
sys_end();
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
return 0;
}
 
int __fs_sub_init(void)
{
return 0;
}
 
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int c,i,errors;
TIME sttime,etime;
cprintf("Press a key to continue\n\n");
c=keyb_getchar();
cprintf("Please wait (reading 100 blocks for 10 times)...");
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<100;blk++) {
for (i=0;i<10;i++) {
res=bdev_read(dev,blk,buffer);
if (res!=0) errors++;
}
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/branches/pj/oldexamples/block/idernd.c
0,0 → 1,68
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <stdlib.h>
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
 
#define NUMBLOCK 1000
 
__dev_t dev;
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int errors;
TIME sttime,etime;
showmessage("\n"
"This test read RAMDOMLY data from first hard disk to test\n"
"disk throughtput.\n"
"Remeber that the reads are made RANDOMLY block by block so\n"
"don't worry if you see a VERY low throughtput.\n"
);
srand(7);
 
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("\nCan't find device to operate with\n");
return -1;
}
cprintf("\nUsing device %s (dev=%04x)\n",DISKDEVICE,dev);
 
cprintf("Please wait (reading %i KB ramdomly)...",NUMBLOCK/2);
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<NUMBLOCK;blk++) {
res=bdev_read(dev,rand()%5000,buffer);
if (res!=0) errors++;
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("throughtput : %6.3f KB/s\n",
NUMBLOCK*512.0/1024.0/etime*1000000.0);
//cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/branches/pj/oldexamples/block/common.c
0,0 → 1,75
 
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <sys/mount.h>
 
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
 
/* -- */
 
int __register_sub_init(void)
{
return 0;
}
 
/* -- */
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,TRUE);
bdev_init(&bdev);
 
return 0;
}
 
/* -- */
 
void ctrlc_exit(KEY_EVT *k)
{
//sys_status(SCHED_STATUS);
cprintf("CTRL-C pressed!\n");
sys_end();
}
 
/* -- */
 
void showmessage(char *s)
{
cputs(s);
cprintf("Press [x] to begin...");
while (keyb_getchar()!='x');
cprintf("\n");
}
 
void waitend(void)
{
int c;
cprintf("Press [x] to exit...");
while ((c=keyb_getchar())!='x');
cprintf("\n");
}
 
/* -- */
 
void debug_dump_buffer(char *buf, int size)
{
int i;
for (i=0;i<size;i++) {
if (i%16==0) {
if (i!=0) cprintf("\n");
cprintf("%04x: ",i);
}
cprintf("%02x ",(unsigned char)*(buf+i));
}
cprintf("\n");
}
/demos/branches/pj/oldexamples/block/makefile
0,0 → 1,35
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS=idetest0 idetest1 idetest2 idetest3 idelin idernd
OBJS=common.o
 
include $(BASE)/config/example.mk
 
#
#
#
 
idetest0:
make -f $(SUBMAKE) APP=idetest0 INIT=initblk.o OTHEROBJS=common.o
 
idetest1:
make -f $(SUBMAKE) APP=idetest1 INIT=initblk.o OTHEROBJS=common.o
 
idetest2:
make -f $(SUBMAKE) APP=idetest2 INIT=initblk.o OTHEROBJS=common.o
 
idetest3:
make -f $(SUBMAKE) APP=idetest3 INIT=initblk.o OTHEROBJS=common.o
 
idelin:
make -f $(SUBMAKE) APP=idelin INIT=initblk.o OTHEROBJS=common.o
 
idernd:
make -f $(SUBMAKE) APP=idernd INIT=initblk.o OTHEROBJS=common.o
/demos/branches/pj/oldexamples/block/common.h
0,0 → 1,11
 
#ifndef __COMMON_H
#define __COMMON_H
 
void showmessage(char *s);
void waitend(void);
 
void debug_dump_buffer(char *buf, int size);
 
#endif