Rev 1618 | 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> |
1621 | fabio | 37 | #include <arch/stdlib.h> |
352 | giacomo | 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 <ll/i386/x-dos.h> |
||
48 | |||
49 | /* this file implement a fixed queue, that is simply an array that |
||
50 | is filled with the events until it is full. After that, all the other |
||
51 | events are discarded. It uses the DOSFS Filesystem to write all the data |
||
52 | |||
53 | This file is derived from the trcfixed.c file; I used a different file |
||
54 | because including trcfixed.c in the executable would have implied the |
||
55 | linking of all the filesystem... |
||
56 | */ |
||
57 | |||
58 | |||
59 | |||
60 | |||
61 | typedef struct TAGfixed_queue_t { |
||
62 | int size; |
||
63 | int index; |
||
64 | char *filename; |
||
65 | int uniq; |
||
66 | |||
67 | trc_event_t table[0]; |
||
68 | /* Yes, 0!... the elements are allocated |
||
69 | in a dirty way into the kern_alloc into fixed_create */ |
||
70 | } dosfs_fixed_queue_t; |
||
71 | |||
72 | /* This function simply return an event to fill (only if the fixed table |
||
73 | is not yet full) */ |
||
74 | static trc_event_t *dosfs_fixed_get(dosfs_fixed_queue_t *queue) |
||
75 | { |
||
76 | if (queue->index>=queue->size) return NULL; |
||
77 | return &queue->table[queue->index++]; |
||
78 | } |
||
79 | |||
80 | /* since get returns the correct event address, |
||
81 | the post function does nothing... */ |
||
82 | static int dosfs_fixed_post(dosfs_fixed_queue_t *queue) |
||
83 | { |
||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | static TRC_FIXED_PARMS defaultargs; |
||
88 | static int once=0; |
||
89 | |||
90 | static void dosfs_fixed_flush(void *arg); |
||
91 | |||
92 | static int dosfs_fixed_create(trc_queue_t *queue, TRC_FIXED_PARMS *args) |
||
93 | { |
||
94 | dosfs_fixed_queue_t *ptr; |
||
95 | |||
96 | /* initialize the default arguments for the fixed queue */ |
||
97 | if (!once) { |
||
98 | /* well... this func is called when the system is not running! */ |
||
99 | once=1; |
||
100 | trc_fixed_default_parms(defaultargs); |
||
101 | } |
||
102 | if (args==NULL) args=&defaultargs; |
||
103 | |||
104 | /* allocate the fixed queue data structure plus the array of events */ |
||
105 | ptr=(dosfs_fixed_queue_t*)kern_alloc(sizeof(dosfs_fixed_queue_t)+ |
||
106 | sizeof(trc_event_t)*(args->size+1)); |
||
107 | if (ptr==NULL) return -1; |
||
108 | |||
109 | /* set the current queue pointers and data */ |
||
110 | queue->get=(trc_event_t*(*)(void*))dosfs_fixed_get; |
||
111 | queue->post=(int(*)(void*))dosfs_fixed_post; |
||
112 | queue->data=ptr; |
||
113 | |||
114 | ptr->size=args->size; |
||
115 | ptr->index=0; |
||
116 | ptr->filename=args->filename; |
||
117 | |||
118 | /* prepare for shutdown ;-) */ |
||
119 | sys_atrunlevel(dosfs_fixed_flush, (void *)ptr, RUNLEVEL_AFTER_EXIT); |
||
120 | |||
121 | return 0; |
||
122 | } |
||
123 | |||
124 | static void dosfs_fixed_flush(void *arg) |
||
125 | { |
||
126 | DOS_FILE *f; |
||
127 | dosfs_fixed_queue_t *queue = (dosfs_fixed_queue_t *)arg; |
||
128 | |||
129 | char pathname[100]; /* it should be PATH_MAX, but we do not use the |
||
130 | filesystem, so the symbol is not defined */ |
||
131 | |||
132 | if (queue->filename==NULL) trc_create_name("fix",queue->uniq,pathname); |
||
133 | else trc_create_name(queue->filename,0,pathname); |
||
134 | |||
135 | printk(KERN_DEBUG "tracer flush index= %d pathname=%s\n", |
||
136 | queue->index, pathname); |
||
137 | |||
138 | f = DOS_fopen(pathname,"w"); |
||
139 | |||
140 | DOS_fwrite(queue->table,1,queue->index*sizeof(trc_event_t),f); |
||
141 | |||
142 | DOS_fclose(f); |
||
143 | |||
144 | } |
||
145 | |||
146 | static int dosfs_fixed_activate(dosfs_fixed_queue_t *queue, int uniq) |
||
147 | { |
||
148 | queue->uniq=uniq; |
||
149 | return 0; |
||
150 | } |
||
151 | |||
152 | static int dosfs_fixed_terminate(dosfs_fixed_queue_t *queue) |
||
153 | { |
||
154 | return 0; |
||
155 | } |
||
156 | |||
157 | int trc_register_dosfs_fixed_queue(void) |
||
158 | { |
||
159 | int res; |
||
160 | |||
161 | res=trc_register_queuetype(TRC_DOSFS_FIXED_QUEUE, |
||
162 | (int(*)(trc_queue_t*,void*))dosfs_fixed_create, |
||
163 | (int(*)(void*,int))dosfs_fixed_activate, |
||
164 | (int(*)(void*))dosfs_fixed_terminate |
||
165 | ); |
||
166 | |||
167 | if (res!=0) printk(KERN_WARNING "can't register tracer DOSFS fixed queue"); |
||
168 | return res; |
||
169 | } |