Subversion Repositories shark

Rev

Rev 3 | Go to most recent revision | 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
  //sys_status(SCHED_STATUS);  
111
  //task_delay(250000);
112
 
113
  h=open("/TEMP/FIX1",O_CREAT|O_TRUNC|O_WRONLY);
114
  if (h!=-1) {
115
    write(h,queue->table,queue->index*sizeof(trc_event_t));
116
    close(h);
117
    printk(KERN_NOTICE "tracer file %s created!",pathname);
118
  }  else {
119
    printk(KERN_NOTICE "tracer file %s not created!",pathname);
120
  }
121
 
122
  resume_fs_shutdown();
123
  return NULL;
124
}
125
 
126
static int fixed_activate(fixed_queue_t *queue, int uniq)
127
{
128
  queue->uniq=uniq;
129
  return 0;
130
}
131
 
132
static int fixed_terminate(fixed_queue_t *queue)
133
{
134
  SOFT_TASK_MODEL model;
135
  PID pid;
136
 
137
  suspend_fs_shutdown();
138
 
139
  //nrt_task_default_model(model);
140
  //nrt_task_def_system(model);
141
  //nrt_task_def_arg(model,queue);
142
 
143
  soft_task_default_model(model);
144
  soft_task_def_system(model);
145
  soft_task_def_notrace(model);
146
  soft_task_def_periodic(model);
147
  soft_task_def_period(model,50000);
148
  soft_task_def_met(model,10000);
149
  soft_task_def_wcet(model,10000);
150
  soft_task_def_arg(model,queue);
151
 
152
  pid=task_create("ShutTrcFix",fixed_shutdown,&model,NULL);
153
  if (pid==-1) {
154
    printk(KERN_ERR "can't start tracer shutdown task (fixed)");
155
    return -1;
156
  } else
157
    task_activate(pid);
158
 
159
  return 0;
160
}
161
 
162
int trc_register_fixed_queue(void)
163
{
164
  int res;
165
 
166
  res=trc_register_queuetype(TRC_FIXED_QUEUE,
167
                             (int(*)(trc_queue_t*,void*))fixed_create,
168
                             (int(*)(void*,int))fixed_activate,
169
                             (int(*)(void*))fixed_terminate
170
                             );
171
 
172
  if (res!=0) printk(KERN_WARNING "can't register tracer fixed queue");
173
  return res;
174
}