Subversion Repositories shark

Rev

Rev 352 | Go to most recent revision | Details | Compare with Previous | 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
 
1063 tullio 19
/*
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
352 giacomo 36
#include <ll/sys/types.h>
37
#include <ll/stdlib.h>
38
 
39
#include <kernel/func.h>
40
#include <kernel/mem.h>
41
#include <kernel/log.h>
42
 
43
#include <types.h>
44
#include <trace.h>
45
#include <queues.h>
46
 
47
#include <fs/fs.h>
48
 
49
#include <unistd.h>
50
#include <fcntl.h>
51
#include <limits.h>
52
 
53
/* this file implement a fixed queue, that is simply an array that
54
is filled with the events until it is full. After that, all the other
55
events are discarded. */
56
 
57
 
58
 
59
 
60
typedef struct TAGfixed_queue_t {
61
  int         size;
62
  int         index;
63
  char        *filename;
64
  int         uniq;
65
 
66
  trc_event_t table[0];
67
  /* Yes, 0!... the elements are allocated
68
     in a dirty way into the kern_alloc into fixed_create */
69
} fixed_queue_t;
70
 
71
/* This function simply return an event to fill (only if the fixed table
72
is not yet full) */
73
static trc_event_t *fixed_get(fixed_queue_t *queue)
74
{
75
  if (queue->index>=queue->size) return NULL;
76
  return &queue->table[queue->index++];
77
}
78
 
79
/* since get returns the correct event address,
80
the post function does nothing... */
81
static int fixed_post(fixed_queue_t *queue)
82
{
83
  return 0;
84
}
85
 
86
static TRC_FIXED_PARMS defaultargs;
87
static int once=0;
88
 
89
static int fixed_create(trc_queue_t *queue, TRC_FIXED_PARMS *args)
90
{
91
  fixed_queue_t *ptr;
92
 
93
  /* initialize the default arguments for the fixed queue */
94
  if (!once) {
95
    /* well... this func is called when the system is not running! */
96
    once=1;
97
    trc_fixed_default_parms(defaultargs);
98
  }
99
  if (args==NULL) args=&defaultargs;
100
 
101
  /* allocate the fixed queue data structure plus the array of events */
102
  ptr=(fixed_queue_t*)kern_alloc(sizeof(fixed_queue_t)+
103
                                 sizeof(trc_event_t)*(args->size+1));
104
  if (ptr==NULL) return -1;
105
 
106
  /* set the current queue pointers and data */
107
  queue->get=(trc_event_t*(*)(void*))fixed_get;
108
  queue->post=(int(*)(void*))fixed_post;
109
  queue->data=ptr;
110
 
111
  ptr->size=args->size;
112
  ptr->index=0;
113
  ptr->filename=args->filename;
114
  return 0;
115
}
116
 
117
static TASK fixed_shutdown(fixed_queue_t *queue)
118
{
119
  char pathname[PATH_MAX];
120
  int h;
121
 
122
  printk(KERN_DEBUG "<fixed queuesize:%i>",queue->index);
123
 
124
  if (queue->filename==NULL) trc_create_name("fix",queue->uniq,pathname);
125
  else trc_create_name(queue->filename,0,pathname);
126
 
127
  h=open("/TEMP/FIX1",O_CREAT|O_TRUNC|O_WRONLY);
128
  if (h!=-1) {
129
    write(h,queue->table,queue->index*sizeof(trc_event_t));
130
    close(h);
131
    printk(KERN_NOTICE "tracer file %s created!",pathname);
132
  }  else {
133
    printk(KERN_NOTICE "tracer file %s not created!",pathname);
134
  }
135
 
136
  resume_fs_shutdown();
137
  return NULL;
138
}
139
 
140
static int fixed_activate(fixed_queue_t *queue, int uniq)
141
{
142
  queue->uniq=uniq;
143
  return 0;
144
}
145
 
146
static int fixed_terminate(fixed_queue_t *queue)
147
{
148
  SOFT_TASK_MODEL model;
149
  PID pid;
150
 
151
  suspend_fs_shutdown();
152
 
153
  //nrt_task_default_model(model);
154
  //nrt_task_def_system(model);
155
  //nrt_task_def_arg(model,queue);
156
 
157
  soft_task_default_model(model);
158
  soft_task_def_system(model);
159
  soft_task_def_notrace(model);
160
  soft_task_def_periodic(model);
161
  soft_task_def_period(model,50000);
162
  soft_task_def_met(model,10000);
163
  soft_task_def_wcet(model,10000);
164
  soft_task_def_arg(model,queue);
165
 
166
  pid=task_create("ShutTrcFix",fixed_shutdown,&model,NULL);
167
  if (pid==-1) {
168
    printk(KERN_ERR "can't start tracer shutdown task (fixed)");
169
    return -1;
170
  } else
171
    task_activate(pid);
172
 
173
  return 0;
174
}
175
 
176
int trc_register_fixed_queue(void)
177
{
178
  int res;
179
 
180
  res=trc_register_queuetype(TRC_FIXED_QUEUE,
181
                             (int(*)(trc_queue_t*,void*))fixed_create,
182
                             (int(*)(void*,int))fixed_activate,
183
                             (int(*)(void*))fixed_terminate
184
                             );
185
 
186
  if (res!=0) printk(KERN_WARNING "can't register tracer fixed queue");
187
  return res;
188
}