Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1092 → Rev 1093

/demos/trunk/tracer/utils/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 2002-10-21 09:12:35 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1 $
* Last update: $Date: 2002-10-21 09:12:35 $
*/
 
#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"
 
/*
*
* This filter converts trace file formats from SHARK to JTRACER
*
*/
 
/* 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 SHARKtracefilename 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/trunk/tracer/utils/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/trunk/tracer/utils/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"
 
/* this file prints the distribution of (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/trunk/tracer/utils/wait.c
0,0 → 1,56
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
/* This demo computes the distribution of the wait times on disk requests */
 
#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/trunk/tracer/utils/road.c
0,0 → 1,57
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include <trace.h>
#include "util.h"
 
 
/* this test prints the distribution of the HD seeks */
 
#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/trunk/tracer/utils/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/trunk/tracer/utils/tdump.c
0,0 → 1,75
 
/* this example simply prints a Shark trace file */
 
#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/trunk/tracer/utils/types.h
0,0 → 1,14
#ifndef __TYPES_H__
#define __TYPES_H__
 
#include <sys/types.h>
 
/* when compiling under MSDOS, uncomment this three typedefs!!! */
 
//typedef unsigned char u_int8_t;
//typedef unsigned short u_int16_t;
//typedef unsigned long u_int32_t;
 
#include <types.h>
#endif
 
/demos/trunk/tracer/utils/readme
0,0 → 1,13
This directory contains a set of utilities that can be used to interpret
the tracer output:
 
- tdump this example simply prints a Shark trace file
- jdump converts trace file formats from SHARK to JTRACER
- sa prints the distribution of (schedule_time - arrival_time)
- road prints the distribution of the HD seeks
- wait computes the distribution of the wait times on disk requests
 
Under Linux: to compile, type "make util_linux"
Under MSDOS: uncomment the three lines into types.h, then type "make util_dos"
 
PJ
/demos/trunk/tracer/utils/makefile
0,0 → 1,63
#
# util -> compiles the tracer utilities under MSDOS/DJGPP
# util_linux -> compiles the tracer utilities under Linux
#
 
ifndef BASE
BASE=../../..
endif
 
.PHONY: util_dos util_linux clean
 
util_dos: 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
 
 
 
 
util_linux: jdump tdump sa road wait
 
jdump: jdump.c util.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace jdump.c util.c -o jdump
 
tdump: tdump.c util.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace tdump.c util.c -o tdump
 
sa: sa.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace sa.c util.c -o sa
 
road: road.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace road.c util.c -o road
 
wait: wait.c util.c distr.c
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace wait.c util.c -o wait
 
 
clean:
rm -rf *.o jdump tdump sa road wait tdump.exe jdump.exe sa.exe road.exe wait.exe
 
 
/demos/trunk/tracer/utils/util.c
0,0 → 1,123
#include <stdio.h>
#include <string.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/trunk/tracer/dfixed/initfile.c
0,0 → 1,115
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* 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
*
*/
 
/*
* CVS : $Id: initfile.c,v 1.1 2002-10-21 09:12:35 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1 $
* Last update: $Date: 2002-10-21 09:12:35 $
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/rr.h"
#include "modules/cbs.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
#include "modules/pi.h"
#include "modules/pc.h"
#include "modules/srp.h"
#include "modules/npp.h"
#include "modules/nop.h"
#include "modules/nopm.h"
 
#include "drivers/keyb.h"
 
/*+ sysyem tick in us +*/
#define TICK 1000
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
void mytracer_prologue(void);
void mytracer_epilogue(void);
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
mytracer_prologue();
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, 0);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
NOPM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
KEYB_PARMS keyb = BASE_KEYB;
extern void ctrlc_exit(KEY_EVT *k);
HARTPORT_init();
keyb_def_ctrlC(keyb, ctrlc_exit);
KEYB_init(&keyb);
 
mytracer_epilogue();
__call_main__(mb);
 
return (void *)0;
}
 
/demos/trunk/tracer/dfixed/dfixed.c
0,0 → 1,133
/*
* 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: dfixed.c,v 1.1 2002-10-21 09:12:35 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1 $
* Last update: $Date: 2002-10-21 09:12:35 $
*/
 
/*
* 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>
 
 
void mytracer_prologue(void)
{
int myqueue;
TRC_PARMS p;
TRC_FIXED_PARMS f;
 
trc_default_parms(p);
trc_def_path(p,"");
 
trc_fixed_default_parms(f);
trc_fixed_def_filename(f,"fixed");
 
/* Tracer Initialization */
/* the first functions to call... parameters can be passed */
TRC_init_phase1(&p);
 
/* all the tracer queue types must be registered */
trc_register_dosfs_fixed_queue();
 
/* then, we create all the queues we need */
myqueue = trc_create_queue(TRC_DOSFS_FIXED_QUEUE,&f);
 
/* Then, we say that events must be sent to a particular queue */
trc_trace_class(TRC_CLASS_SYSTEM);
trc_assign_class_to_queue(TRC_CLASS_SYSTEM, myqueue);
}
 
void mytracer_epilogue(void)
{
TRC_init_phase2();
}
 
void ctrlc_exit(KEY_EVT *k)
{
sys_end();
}
 
void *mytask(void *arg)
{
int i;
 
for(i=0; i<10; i++) {
cprintf("%d ", i);
task_endcycle();
}
 
return 0;
}
 
int main(int argc,char *argv[])
{
SOFT_TASK_MODEL mp;
 
PID pid;
 
soft_task_default_model(mp);
soft_task_def_met(mp, 10000);
soft_task_def_period(mp,50000);
soft_task_def_usemath(mp);
 
cprintf("\nHello, world!\n");
 
pid = task_create("mytask", mytask, &mp, NULL);
 
if (pid != NIL) task_activate(pid);
 
return 0;
}
/demos/trunk/tracer/dfixed/makefile
0,0 → 1,21
#
#
#
 
ifndef BASE
BASE=../../..
endif
 
include $(BASE)/config/config.mk
 
PROGS= dfixed
 
include $(BASE)/config/example.mk
 
dfixed:
make -f $(SUBMAKE) BASE=$(BASE) APP=dfixed INIT= OTHEROBJS=initfile.o
 
 
 
 
 
/demos/trunk/tracer/dfixed/readme
0,0 → 1,8
This is a simple test that uses the tracer.
 
The example simply creates a soft task that does 10 instances and then dies.
It uses a DOSFS Fixed queue to write the output on a file.
 
Enjoy,
 
PJ
/demos/trunk/tracer/small/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/trunk/tracer/small/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 2002-10-21 09:12:35 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1 $
* Last update: $Date: 2002-10-21 09:12:35 $
*/
 
/*
* 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/trunk/tracer/small/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/trunk/tracer/small/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/trunk/tracer/small/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/trunk/tracer/small/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/trunk/tracer/small/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/trunk/tracer/small/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/trunk/tracer/small/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 2002-10-21 09:12:35 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.1 $
* Last update: $Date: 2002-10-21 09:12:35 $
*/
 
/*
* 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/trunk/tracer/small/readme
0,0 → 1,27
This directory contains a set of tests that uses the Shark Filesystem and the tracer
 
treef1 - the test shows all filenames of a directory of an hardisk
recursively using a soft task for every directory.
The tracer with a circular queue is activated.
 
treec2 - the test shows all filenames of a directory of an hardisk
recursively using a soft task for every directory.
The tracer with a circular queue is activated that write
on hardisk online (while the system is running).
 
treec1 - This test show all filenames of a directory of an hardisk
recursively using a soft task for every directory.
The tracer with a circular queue is activated.
 
test0 - A file is opened for reading while the tracerwith a fixed
queue is runnig.
 
simple - Simple hello world (with tracer)!
 
hello - another hello world...
 
hello1 - another hello world with a dummy queue...
 
hello2 - another hello world with a fixed queue...
 
PJ
/demos/trunk/tracer/small/makefile
0,0 → 1,29
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS= simple hello hello1 hello2 test0 treef1 treec1 treec2
 
include $(BASE)/config/example.mk
 
simple:
make -f $(SUBMAKE) BASE=$(BASE) APP=simple INIT=initfs.o OTHEROBJS=
hello:
make -f $(SUBMAKE) BASE=$(BASE) APP=hello INIT=initfs.o OTHEROBJS=
hello1:
make -f $(SUBMAKE) BASE=$(BASE) APP=hello1 INIT=initfs.o OTHEROBJS=common.o
hello2:
make -f $(SUBMAKE) BASE=$(BASE) APP=hello2 INIT=initfs.o OTHEROBJS=common.o
test0:
make -f $(SUBMAKE) BASE=$(BASE) APP=test0 INIT=initfs.o OTHEROBJS=common.o
treef1:
make -f $(SUBMAKE) BASE=$(BASE) APP=treef1 INIT=initfs.o OTHEROBJS=common.o
treec1:
make -f $(SUBMAKE) BASE=$(BASE) APP=treec1 INIT=initfs.o OTHEROBJS=common.o
treec2:
make -f $(SUBMAKE) BASE=$(BASE) APP=treec2 INIT=initfs.o OTHEROBJS=common.o
/demos/trunk/tracer/small/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/trunk/tracer/readme
0,0 → 1,13
This directory contains a set of sub directories containing all the tracer
examples and utilities.
 
Here a short description of the contents
 
utils - some small utilities that can read tracer files
dfixed - a small applications that defines a tracer queue.
At the end a file is written (using DOSFS).
small - a set of small examples of tracer usage (using the Shark Filesystem)
 
Enjoy
 
PJ