Subversion Repositories shark

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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 <trace/types.h>
27
#include <trace/trace.h>
28
#include <trace/queues.h>
29
 
30
#include <fs/fs.h>
31
 
32
#include <unistd.h>
33
#include <fcntl.h>
34
#include <limits.h>
35
 
5 pj 36
/* this file implement a fixed queue, that is simply an array that
37
is filled with the events until it is full. After that, all the other
38
events are discarded. */
39
 
40
 
41
 
42
 
2 pj 43
typedef struct TAGfixed_queue_t {
44
  int         size;
45
  int         index;
46
  char        *filename;
47
  int         uniq;
48
 
5 pj 49
  trc_event_t table[0];
50
  /* Yes, 0!... the elements are allocated
51
     in a dirty way into the kern_alloc into fixed_create */
2 pj 52
} fixed_queue_t;
53
 
5 pj 54
/* This function simply return an event to fill (only if the fixed table
55
is not yet full) */
2 pj 56
static trc_event_t *fixed_get(fixed_queue_t *queue)
57
{
58
  if (queue->index>=queue->size) return NULL;
59
  return &queue->table[queue->index++];
60
}
61
 
5 pj 62
/* since get returns the correct event address,
63
the post function does nothing... */
2 pj 64
static int fixed_post(fixed_queue_t *queue)
65
{
66
  return 0;
67
}
68
 
69
static TRC_FIXED_PARMS defaultargs;
70
static int once=0;
71
 
72
static int fixed_create(trc_queue_t *queue, TRC_FIXED_PARMS *args)
73
{
74
  fixed_queue_t *ptr;
75
 
5 pj 76
  /* initialize the default arguments for the fixed queue */
2 pj 77
  if (!once) {
78
    /* well... this func is called when the system is not running! */
79
    once=1;
80
    trc_fixed_default_parms(defaultargs);
81
  }
82
  if (args==NULL) args=&defaultargs;
83
 
5 pj 84
  /* allocate the fixed queue data structure plus the array of events */
2 pj 85
  ptr=(fixed_queue_t*)kern_alloc(sizeof(fixed_queue_t)+
86
                                 sizeof(trc_event_t)*(args->size+1));
87
  if (ptr==NULL) return -1;
88
 
5 pj 89
  /* set the current queue pointers and data */
2 pj 90
  queue->get=(trc_event_t*(*)(void*))fixed_get;
91
  queue->post=(int(*)(void*))fixed_post;
92
  queue->data=ptr;
93
 
94
  ptr->size=args->size;
95
  ptr->index=0;
96
  ptr->filename=args->filename;
97
  return 0;
98
}
99
 
100
static TASK fixed_shutdown(fixed_queue_t *queue)
101
{
102
  char pathname[PATH_MAX];
103
  int h;
104
 
105
  printk(KERN_DEBUG "<fixed queuesize:%i>",queue->index);
106
 
107
  if (queue->filename==NULL) trc_create_name("fix",queue->uniq,pathname);
108
  else trc_create_name(queue->filename,0,pathname);
109
 
110
  h=open("/TEMP/FIX1",O_CREAT|O_TRUNC|O_WRONLY);
111
  if (h!=-1) {
112
    write(h,queue->table,queue->index*sizeof(trc_event_t));
113
    close(h);
114
    printk(KERN_NOTICE "tracer file %s created!",pathname);
115
  }  else {
116
    printk(KERN_NOTICE "tracer file %s not created!",pathname);
117
  }
118
 
119
  resume_fs_shutdown();
120
  return NULL;
121
}
122
 
123
static int fixed_activate(fixed_queue_t *queue, int uniq)
124
{
125
  queue->uniq=uniq;
126
  return 0;
127
}
128
 
129
static int fixed_terminate(fixed_queue_t *queue)
130
{
131
  SOFT_TASK_MODEL model;
132
  PID pid;
133
 
134
  suspend_fs_shutdown();
135
 
136
  //nrt_task_default_model(model);
137
  //nrt_task_def_system(model);
138
  //nrt_task_def_arg(model,queue);
139
 
140
  soft_task_default_model(model);
141
  soft_task_def_system(model);
142
  soft_task_def_notrace(model);
143
  soft_task_def_periodic(model);
144
  soft_task_def_period(model,50000);
145
  soft_task_def_met(model,10000);
146
  soft_task_def_wcet(model,10000);
147
  soft_task_def_arg(model,queue);
148
 
149
  pid=task_create("ShutTrcFix",fixed_shutdown,&model,NULL);
150
  if (pid==-1) {
151
    printk(KERN_ERR "can't start tracer shutdown task (fixed)");
152
    return -1;
153
  } else
154
    task_activate(pid);
155
 
156
  return 0;
157
}
158
 
159
int trc_register_fixed_queue(void)
160
{
161
  int res;
162
 
163
  res=trc_register_queuetype(TRC_FIXED_QUEUE,
164
                             (int(*)(trc_queue_t*,void*))fixed_create,
165
                             (int(*)(void*,int))fixed_activate,
166
                             (int(*)(void*))fixed_terminate
167
                             );
168
 
169
  if (res!=0) printk(KERN_WARNING "can't register tracer fixed queue");
170
  return res;
171
}