Subversion Repositories shark

Rev

Rev 1063 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
#include <ll/sys/types.h>
20
#include <ll/stdlib.h>
21
 
22
#include <kernel/func.h>
23
#include <kernel/mem.h>
24
#include <kernel/log.h>
25
 
26
#include <types.h>
27
#include <trace.h>
28
#include <queues.h>
29
 
30
#include <ll/i386/x-dos.h>
31
 
32
/* this file implement a fixed queue, that is simply an array that
33
is filled with the events until it is full. After that, all the other
34
events are discarded. It uses the DOSFS Filesystem to write all the data
35
 
36
This file is derived from the trcfixed.c file; I used a different file
37
because including trcfixed.c in the executable would have implied the
38
linking of all the filesystem...
39
*/
40
 
41
 
42
 
43
 
44
typedef struct TAGfixed_queue_t {
45
  int         size;
46
  int         index;
47
  char        *filename;
48
  int         uniq;
49
 
50
  trc_event_t table[0];
51
  /* Yes, 0!... the elements are allocated
52
     in a dirty way into the kern_alloc into fixed_create */
53
} dosfs_fixed_queue_t;
54
 
55
/* This function simply return an event to fill (only if the fixed table
56
is not yet full) */
57
static trc_event_t *dosfs_fixed_get(dosfs_fixed_queue_t *queue)
58
{
59
  if (queue->index>=queue->size) return NULL;
60
  return &queue->table[queue->index++];
61
}
62
 
63
/* since get returns the correct event address,
64
the post function does nothing... */
65
static int dosfs_fixed_post(dosfs_fixed_queue_t *queue)
66
{
67
  return 0;
68
}
69
 
70
static TRC_FIXED_PARMS defaultargs;
71
static int once=0;
72
 
73
static void dosfs_fixed_flush(void *arg);
74
 
75
static int dosfs_fixed_create(trc_queue_t *queue, TRC_FIXED_PARMS *args)
76
{
77
  dosfs_fixed_queue_t *ptr;
78
 
79
  /* initialize the default arguments for the fixed queue */
80
  if (!once) {
81
    /* well... this func is called when the system is not running! */
82
    once=1;
83
    trc_fixed_default_parms(defaultargs);
84
  }
85
  if (args==NULL) args=&defaultargs;
86
 
87
  /* allocate the fixed queue data structure plus the array of events */
88
  ptr=(dosfs_fixed_queue_t*)kern_alloc(sizeof(dosfs_fixed_queue_t)+
89
                                 sizeof(trc_event_t)*(args->size+1));
90
  if (ptr==NULL) return -1;
91
 
92
  /* set the current queue pointers and data */
93
  queue->get=(trc_event_t*(*)(void*))dosfs_fixed_get;
94
  queue->post=(int(*)(void*))dosfs_fixed_post;
95
  queue->data=ptr;
96
 
97
  ptr->size=args->size;
98
  ptr->index=0;
99
  ptr->filename=args->filename;
100
 
101
  /* prepare for shutdown ;-) */
102
  sys_atrunlevel(dosfs_fixed_flush, (void *)ptr, RUNLEVEL_AFTER_EXIT);
103
 
104
  return 0;
105
}
106
 
107
static void dosfs_fixed_flush(void *arg)
108
{
109
  DOS_FILE *f;
110
  dosfs_fixed_queue_t *queue = (dosfs_fixed_queue_t *)arg;
111
 
112
  char pathname[100]; /* it should be PATH_MAX, but we do not use the
113
                         filesystem, so the symbol is not defined */
114
 
115
  if (queue->filename==NULL) trc_create_name("fix",queue->uniq,pathname);
116
  else trc_create_name(queue->filename,0,pathname);
117
 
118
  printk(KERN_DEBUG "tracer flush index= %d pathname=%s\n",
119
         queue->index, pathname);
120
 
121
  f = DOS_fopen(pathname,"w");
122
 
123
  DOS_fwrite(queue->table,1,queue->index*sizeof(trc_event_t),f);
124
 
125
  DOS_fclose(f);
126
 
127
}
128
 
129
static int dosfs_fixed_activate(dosfs_fixed_queue_t *queue, int uniq)
130
{
131
  queue->uniq=uniq;
132
  return 0;
133
}
134
 
135
static int dosfs_fixed_terminate(dosfs_fixed_queue_t *queue)
136
{
137
  return 0;
138
}
139
 
140
int trc_register_dosfs_fixed_queue(void)
141
{
142
  int res;
143
 
144
  res=trc_register_queuetype(TRC_DOSFS_FIXED_QUEUE,
145
                             (int(*)(trc_queue_t*,void*))dosfs_fixed_create,
146
                             (int(*)(void*,int))dosfs_fixed_activate,
147
                             (int(*)(void*))dosfs_fixed_terminate
148
                             );
149
 
150
  if (res!=0) printk(KERN_WARNING "can't register tracer DOSFS fixed queue");
151
  return res;
152
}