3888436c |
1 | /* |
2 | |
3 | genevent.c: Generate helper declarations and functions to trace events |
4 | from an event description file. |
5 | |
6 | Copyright (C) 2002, Xianxiu Yang |
7 | Copyright (C) 2002, Michel Dagenais |
8 | |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by |
11 | the Free Software Foundation; version 2 of the License. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ |
22 | |
23 | /* This program reads the ".event" event definitions input files |
24 | specified as command line arguments and generates corresponding |
25 | ".c" and ".h" files required to trace such events in the kernel. |
26 | |
27 | The program uses a very simple tokenizer, called from a hand written |
28 | recursive descent parser to fill a data structure describing the events. |
29 | The result is a sequence of events definitions which refer to type |
30 | definitions. |
31 | |
32 | A table of named types is maintained to allow refering to types by name |
33 | when the same type is used at several places. Finally a sequence of |
34 | all types is maintained to facilitate the freeing of all type |
35 | information when the processing of an ".event" file is finished. */ |
36 | |
37 | #include <stdlib.h> |
38 | #include <string.h> |
31cbc5d3 |
39 | #include <ctype.h> |
3888436c |
40 | #include <stdio.h> |
41 | #include <stdarg.h> |
42 | #include <linux/errno.h> |
d7ed29cd |
43 | #include <assert.h> |
3888436c |
44 | |
45 | #include "parser.h" |
46 | #include "genevent.h" |
47 | |
48 | /* Named types may be referenced from anywhere */ |
49 | |
50 | facility * fac; |
51 | |
52 | int main(int argc, char** argv) |
53 | { |
54 | char *token; |
55 | parse_file in; |
56 | char buffer[BUFFER_SIZE]; |
57 | int i; |
58 | |
59 | if(argc < 2){ |
60 | printf("At least one event definition file is needed\n"); |
61 | exit(1); |
62 | } |
63 | |
64 | in.buffer = buffer; |
65 | in.error = error_callback; |
66 | |
67 | for(i = 1 ; i < argc ; i++) { |
68 | in.lineno = 0; |
69 | in.name = allocAndCopy(argv[i]); |
70 | |
71 | in.fp = fopen(in.name, "r"); |
72 | if(!in.fp ){ |
73 | in.error(&in,"cannot open facility input file"); |
74 | } |
75 | |
76 | while(1){ |
77 | token = getToken(&in); |
78 | if(in.type == ENDFILE) break; |
79 | |
80 | if(strcmp(token, "<")) in.error(&in,"not a facility file"); |
81 | token = getName(&in); |
82 | |
83 | if(strcmp("facility",token) == 0) { |
a8f6f123 |
84 | fac = memAlloc(sizeof(facility)); |
85 | fac->name = NULL; |
86 | fac->description = NULL; |
87 | sequence_init(&(fac->events)); |
88 | table_init(&(fac->named_types)); |
89 | sequence_init(&(fac->unnamed_types)); |
90 | |
91 | parseFacility(&in, fac); |
92 | |
93 | //check if any namedType is not defined |
94 | checkNamedTypesImplemented(&fac->named_types); |
31cbc5d3 |
95 | } |
a8f6f123 |
96 | else in.error(&in,"facility token was expected"); |
3888436c |
97 | |
98 | generateFile(argv[i]); |
99 | |
100 | free(fac->name); |
101 | free(fac->description); |
102 | freeEvents(&fac->events); |
103 | sequence_dispose(&fac->events); |
104 | freeNamedType(&fac->named_types); |
105 | table_dispose(&fac->named_types); |
106 | freeTypes(&fac->unnamed_types); |
107 | sequence_dispose(&fac->unnamed_types); |
108 | free(fac); |
109 | } |
110 | |
111 | free(in.name); |
112 | fclose(in.fp); |
113 | |
114 | } |
115 | return 0; |
116 | } |
117 | |
118 | |
119 | /***************************************************************************** |
120 | *Function name |
121 | * generateFile : generate .c and .h file |
122 | *Input Params |
123 | * name : name of event definition file |
124 | ****************************************************************************/ |
125 | void generateFile(char *name){ |
a8f6f123 |
126 | char *loadName, *hName, *hIdName, *cName, *tmp, *tmp2; |
127 | FILE * lFp, *hFp, *iFp, *cFp; |
3888436c |
128 | int nbEvent; |
129 | unsigned long checksum=0; |
130 | |
131 | //remove .xml if it exists |
132 | tmp = &name[strlen(name)-4]; |
133 | if(strcmp(tmp, ".xml") == 0){ |
134 | *tmp = '\0'; |
135 | } |
136 | |
137 | tmp = strrchr(name,'/'); |
138 | if(tmp){ |
139 | tmp++; |
140 | }else{ |
141 | tmp = name; |
142 | } |
6d387597 |
143 | |
144 | loadName = appendString("ltt-facility-loader-", tmp); |
145 | tmp2 = appendString(loadName,".h"); |
146 | free(loadName); |
147 | loadName = tmp2; |
148 | hName = appendString("ltt-facility-", tmp); |
149 | tmp2 = appendString(hName,".h"); |
150 | free(hName); |
151 | hName = tmp2; |
a8f6f123 |
152 | hIdName = appendString("ltt-facility-id-", tmp); |
153 | tmp2 = appendString(hIdName,".h"); |
154 | free(hIdName); |
155 | hIdName = tmp2; |
156 | cName = appendString("ltt-facility-loader-", tmp); |
157 | tmp2 = appendString(cName,".c"); |
158 | free(cName); |
159 | cName = tmp2; |
6d387597 |
160 | lFp = fopen(loadName,"w"); |
161 | if(!lFp){ |
162 | printf("Cannot open the file : %s\n",loadName); |
3888436c |
163 | exit(1); |
164 | } |
165 | |
166 | hFp = fopen(hName,"w"); |
167 | if(!hFp){ |
168 | printf("Cannot open the file : %s\n",hName); |
169 | exit(1); |
170 | } |
a8f6f123 |
171 | |
172 | iFp = fopen(hIdName,"w"); |
173 | if(!iFp){ |
174 | printf("Cannot open the file : %s\n",hIdName); |
175 | exit(1); |
176 | } |
177 | |
178 | cFp = fopen(cName,"w"); |
179 | if(!cFp){ |
180 | printf("Cannot open the file : %s\n",cName); |
181 | exit(1); |
182 | } |
3888436c |
183 | |
6d387597 |
184 | free(loadName); |
3888436c |
185 | free(hName); |
a8f6f123 |
186 | free(hIdName); |
187 | free(cName); |
3888436c |
188 | |
189 | generateChecksum(fac->name, &checksum, &(fac->events)); |
190 | |
191 | /* generate .h file, event enumeration then structures and functions */ |
a8f6f123 |
192 | fprintf(iFp, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname); |
193 | fprintf(iFp, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname); |
1bedc199 |
194 | fprintf(iFp, "#ifdef CONFIG_LTT\n"); |
a8f6f123 |
195 | generateEnumEvent(iFp, fac->name, &nbEvent, checksum); |
1bedc199 |
196 | fprintf(iFp, "#endif //CONFIG_LTT\n"); |
a8f6f123 |
197 | fprintf(iFp, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname); |
198 | |
199 | |
200 | fprintf(hFp, "#ifndef _LTT_FACILITY_%s_H_\n",fac->capname); |
201 | fprintf(hFp, "#define _LTT_FACILITY_%s_H_\n\n",fac->capname); |
1bedc199 |
202 | //fprintf(hFp, "#ifdef CONFIG_LTT\n"); |
a8f6f123 |
203 | generateTypeDefs(hFp, fac->name); |
31cbc5d3 |
204 | generateStructFunc(hFp, fac->name,checksum); |
1bedc199 |
205 | //fprintf(hFp, "#endif //CONFIG_LTT\n"); |
a8f6f123 |
206 | fprintf(hFp, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname); |
3888436c |
207 | |
6d387597 |
208 | /* generate .h file, calls to register the facility at init time */ |
8c6ca411 |
209 | generateLoaderfile(lFp,fac->name,nbEvent,checksum,fac->capname); |
3888436c |
210 | |
a8f6f123 |
211 | // create ltt-facility-loader-facname.c |
212 | generateCfile(cFp, tmp); |
213 | |
3888436c |
214 | fclose(hFp); |
a8f6f123 |
215 | fclose(iFp); |
6d387597 |
216 | fclose(lFp); |
a8f6f123 |
217 | fclose(cFp); |
218 | |
3888436c |
219 | } |
220 | |
221 | |
222 | /***************************************************************************** |
223 | *Function name |
224 | * generateEnumEvent : output event enum to .h file |
225 | *Input Params |
226 | * fp : file to be written to |
227 | * facName : name of facility |
228 | *Output Params |
229 | * nbEvent : number of events in the facility |
230 | ****************************************************************************/ |
31cbc5d3 |
231 | void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long checksum) { |
3888436c |
232 | int pos = 0; |
233 | |
a8f6f123 |
234 | fprintf(fp,"#include <linux/ltt-facilities.h>\n\n"); |
3888436c |
235 | |
236 | fprintf(fp,"/**** facility handle ****/\n\n"); |
a8f6f123 |
237 | fprintf(fp,"extern ltt_facility_t ltt_facility_%s_%X;\n",facName, checksum); |
238 | fprintf(fp,"extern ltt_facility_t ltt_facility_%s;\n\n\n",facName, checksum); |
3888436c |
239 | |
240 | fprintf(fp,"/**** event type ****/\n\n"); |
241 | fprintf(fp,"enum %s_event {\n",facName); |
242 | |
243 | for(pos = 0; pos < fac->events.position;pos++) { |
a8f6f123 |
244 | fprintf(fp,"\tevent_%s", ((event *)(fac->events.array[pos]))->name); |
3888436c |
245 | if(pos != fac->events.position-1) fprintf(fp,",\n"); |
246 | } |
247 | fprintf(fp,"\n};\n\n\n"); |
248 | |
249 | // fprintf(fp,"/**** number of events in the facility ****/\n\n"); |
250 | // fprintf(fp,"int nbEvents_%s = %d;\n\n\n",facName, fac->events.position); |
251 | *nbEvent = fac->events.position; |
252 | } |
253 | |
254 | |
31cbc5d3 |
255 | /***************************************************************************** |
256 | *Function name |
257 | * printStruct : Generic struct printing function |
258 | *Input Params |
259 | * fp : file to be written to |
260 | * len : number of fields |
261 | * array : array of field info |
262 | * name : basic struct name |
263 | * facName : name of facility |
264 | * whichTypeFirst : struct or array/sequence first |
265 | * hasStrSeq : string or sequence present? |
266 | * structCount : struct postfix |
267 | ****************************************************************************/ |
cb1eb7ce |
268 | |
31cbc5d3 |
269 | static void |
270 | printStruct(FILE * fp, int len, void ** array, char * name, char * facName, |
9774b764 |
271 | int * whichTypeFirst, int * hasStrSeq, int * structCount, |
272 | type_descriptor *type) |
31cbc5d3 |
273 | { |
274 | int flag = 0; |
275 | int pos; |
276 | field * fld; |
277 | type_descriptor * td; |
278 | |
279 | for (pos = 0; pos < len; pos++) { |
280 | fld = (field *)array[pos]; |
281 | td = fld->type; |
a8f6f123 |
282 | if( td->type == STRING || td->type == SEQUENCE || |
283 | td->type == ARRAY) { |
284 | (*hasStrSeq)++; |
285 | } |
286 | // if (*whichTypeFirst == 0) { |
287 | // *whichTypeFirst = 1; //struct first |
288 | // } |
31cbc5d3 |
289 | if (flag == 0) { |
290 | flag = 1; |
291 | |
cb1eb7ce |
292 | fprintf(fp,"struct %s_%s",name, facName); |
293 | if (structCount) { |
a8f6f123 |
294 | fprintf(fp, "_%d {\n",++*structCount); |
cb1eb7ce |
295 | } else { |
296 | fprintf(fp, " {\n"); |
297 | } |
31cbc5d3 |
298 | } |
cb1eb7ce |
299 | fprintf(fp, "\t%s %s; /* %s */\n", |
300 | getTypeStr(td),fld->name,fld->description ); |
a8f6f123 |
301 | #if 0 |
31cbc5d3 |
302 | } else { |
cb1eb7ce |
303 | if (*whichTypeFirst == 0) { |
31cbc5d3 |
304 | //string or sequence or array first |
cb1eb7ce |
305 | *whichTypeFirst = 2; |
306 | } |
307 | (*hasStrSeq)++; |
308 | if(flag) { |
309 | fprintf(fp,"} __attribute__ ((packed));\n\n"); |
310 | } |
311 | flag = 0; |
31cbc5d3 |
312 | } |
a8f6f123 |
313 | #endif //0 |
31cbc5d3 |
314 | } |
315 | |
316 | if(flag) { |
9774b764 |
317 | if(type->alignment == 0) |
318 | fprintf(fp,"} __attribute__ ((packed));\n\n"); |
319 | else { |
320 | if(type->alignment != 1 && type->alignment != 2 |
321 | && type->alignment != 4 && type->alignment != 8) { |
322 | printf("Wrong alignment %i, using packed.\n", type->alignment); |
323 | fprintf(fp,"} __attribute__ ((packed));\n\n"); |
324 | } else |
325 | fprintf(fp,"} __attribute__ ((aligned(%i)));\n\n", type->alignment); |
326 | } |
31cbc5d3 |
327 | } |
328 | } |
329 | |
330 | |
331 | /***************************************************************************** |
332 | *Function name |
333 | * generateHfile : Create the typedefs |
334 | *Input Params |
335 | * fp : file to be written to |
336 | ****************************************************************************/ |
337 | void |
a8f6f123 |
338 | generateTypeDefs(FILE * fp, char *facName) |
31cbc5d3 |
339 | { |
340 | int pos, tmp = 1; |
341 | |
a8f6f123 |
342 | fprintf(fp,"#include <linux/types.h>\n"); |
343 | fprintf(fp,"#include <linux/spinlock.h>\n"); |
344 | fprintf(fp,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n", facName); |
345 | fprintf(fp,"#include <linux/ltt-core.h>\n"); |
346 | |
9774b764 |
347 | #if 0 //broken |
31cbc5d3 |
348 | fprintf(fp, "/**** Basic Type Definitions ****/\n\n"); |
349 | |
350 | for (pos = 0; pos < fac->named_types.values.position; pos++) { |
351 | type_descriptor * type = |
352 | (type_descriptor*)fac->named_types.values.array[pos]; |
353 | printStruct(fp, type->fields.position, type->fields.array, |
354 | "", type->type_name, &tmp, &tmp, NULL); |
355 | fprintf(fp, "typedef struct _%s %s;\n\n", |
356 | type->type_name, type->type_name); |
357 | } |
9774b764 |
358 | #endif //0 |
31cbc5d3 |
359 | } |
360 | |
361 | |
3888436c |
362 | /***************************************************************************** |
363 | *Function name |
364 | * generateEnumDefinition: generate enum definition if it exists |
365 | *Input Params |
366 | * fp : file to be written to |
367 | * fHead : enum type |
368 | ****************************************************************************/ |
369 | void generateEnumDefinition(FILE * fp, type_descriptor * type){ |
370 | int pos; |
371 | |
a8f6f123 |
372 | if(type->already_printed) return; |
373 | |
3888436c |
374 | fprintf(fp,"enum {\n"); |
375 | for(pos = 0; pos < type->labels.position; pos++){ |
a8f6f123 |
376 | fprintf(fp,"\tLTT_ENUM_%s", type->labels.array[pos]); |
8c6ca411 |
377 | if (pos != type->labels.position - 1) fprintf(fp,","); |
a8f6f123 |
378 | if(type->labels_description.array[pos] != NULL) |
379 | fprintf(fp,"\t/* %s */\n",type->labels_description.array[pos]); |
380 | else |
381 | fprintf(fp,"\n"); |
3888436c |
382 | } |
8c6ca411 |
383 | fprintf(fp,"};\n\n\n"); |
44cac8a9 |
384 | |
a8f6f123 |
385 | type->already_printed = 1; |
3888436c |
386 | } |
387 | |
388 | /***************************************************************************** |
389 | *Function name |
390 | * generateStrucTFunc: output structure and function to .h file |
391 | *Input Params |
392 | * fp : file to be written to |
393 | * facName : name of facility |
394 | ****************************************************************************/ |
31cbc5d3 |
395 | void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ |
3888436c |
396 | event * ev; |
397 | field * fld; |
398 | type_descriptor * td; |
399 | int pos, pos1; |
400 | int hasStrSeq, flag, structCount, seqCount,strCount, whichTypeFirst=0; |
401 | |
402 | for(pos = 0; pos < fac->events.position; pos++){ |
403 | ev = (event *) fac->events.array[pos]; |
404 | //yxx if(ev->nested)continue; |
d7ed29cd |
405 | fprintf(fp,"/**** structure and trace function for event: %s ****/\n\n", |
406 | ev->name); |
a8f6f123 |
407 | //if(ev->type == 0){ // event without type |
408 | // fprintf(fp,"static inline void trace_%s_%s(void){\n",facName,ev->name); |
409 | // fprintf(fp,"\tltt_log_event(ltt_facility_%s_%X, event_%s, 0, NULL);\n", |
410 | // facName,checksum,ev->name); |
411 | // fprintf(fp,"};\n\n\n"); |
412 | // continue; |
413 | //} |
3888436c |
414 | |
415 | //if fields contain enum, print out enum definition |
d7ed29cd |
416 | //MD : fixed in generateEnumDefinition to do not print the same enum |
417 | //twice. |
a8f6f123 |
418 | if(ev->type != 0) |
419 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
420 | fld = (field *)ev->type->fields.array[pos1]; |
421 | if(fld->type->type == ENUM) generateEnumDefinition(fp, fld->type); |
422 | } |
3888436c |
423 | |
424 | //default: no string, array or sequence in the event |
425 | hasStrSeq = 0; |
426 | whichTypeFirst = 0; |
3888436c |
427 | structCount = 0; |
31cbc5d3 |
428 | |
429 | //structure for kernel |
a8f6f123 |
430 | if(ev->type != 0) |
431 | printStruct(fp, ev->type->fields.position, ev->type->fields.array, |
9774b764 |
432 | ev->name, facName, &whichTypeFirst, &hasStrSeq, &structCount, |
433 | ev->type); |
3888436c |
434 | |
1bedc199 |
435 | |
436 | //trace function : function name and parameters : stub function. |
437 | seqCount = 0; |
438 | strCount = 0; |
439 | fprintf(fp, "#ifndef CONFIG_LTT\n"); |
440 | fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name); |
441 | if(ev->type == 0) |
442 | fprintf(fp, "void"); |
443 | else |
444 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
445 | fld = (field *)ev->type->fields.array[pos1]; |
446 | td = fld->type; |
447 | if(td->type == ARRAY ){ |
448 | fprintf(fp,"%s * %s",getTypeStr(td), fld->name); |
449 | }else if(td->type == STRING){ |
450 | fprintf(fp,"short int strlength_%d, %s * %s", |
451 | ++strCount, getTypeStr(td), fld->name); |
452 | }else if(td->type == SEQUENCE){ |
453 | fprintf(fp,"%s seqlength_%d, %s * %s", |
454 | uintOutputTypes[td->size], ++seqCount,getTypeStr(td), fld->name); |
455 | }else fprintf(fp,"%s %s",getTypeStr(td), fld->name); |
456 | if(pos1 != ev->type->fields.position - 1) fprintf(fp,", "); |
457 | } |
458 | fprintf(fp,")\n{\n"); |
459 | fprintf(fp,"}\n"); |
460 | fprintf(fp,"#else\n"); |
461 | |
3888436c |
462 | //trace function : function name and parameters |
463 | seqCount = 0; |
464 | strCount = 0; |
465 | fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name); |
a8f6f123 |
466 | if(ev->type == 0) |
467 | fprintf(fp, "void"); |
468 | else |
469 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
470 | fld = (field *)ev->type->fields.array[pos1]; |
471 | td = fld->type; |
472 | if(td->type == ARRAY ){ |
473 | fprintf(fp,"%s * %s",getTypeStr(td), fld->name); |
474 | }else if(td->type == STRING){ |
475 | fprintf(fp,"short int strlength_%d, %s * %s", |
476 | ++strCount, getTypeStr(td), fld->name); |
477 | }else if(td->type == SEQUENCE){ |
478 | fprintf(fp,"%s seqlength_%d, %s * %s", |
479 | uintOutputTypes[td->size], ++seqCount,getTypeStr(td), fld->name); |
480 | }else fprintf(fp,"%s %s",getTypeStr(td), fld->name); |
481 | if(pos1 != ev->type->fields.position - 1) fprintf(fp,", "); |
482 | } |
d7ed29cd |
483 | fprintf(fp,")\n{\n"); |
3888436c |
484 | |
1bedc199 |
485 | |
486 | |
3888436c |
487 | //allocate buffer |
d7ed29cd |
488 | // MD no more need. fprintf(fp,"\tchar buff[buflength];\n"); |
489 | // write directly to the channel |
0f5d12e9 |
490 | fprintf(fp, "\tint length;\n"); |
d7ed29cd |
491 | fprintf(fp, "\tunsigned int index;\n"); |
492 | fprintf(fp, "\tstruct ltt_channel_struct *channel;\n"); |
493 | fprintf(fp, "\tstruct ltt_trace_struct *trace;\n"); |
a8f6f123 |
494 | fprintf(fp, "\tunsigned long _flags;\n"); |
2f74104a |
495 | fprintf(fp, "\tvoid *buff;\n"); |
0f5d12e9 |
496 | fprintf(fp, "\tvoid *offset_ptr;\n"); |
2f74104a |
497 | fprintf(fp, "\tunsigned int header_length;\n"); |
498 | fprintf(fp, "\tunsigned int event_length;\n"); |
499 | fprintf(fp, "\tint resret;\n"); |
1bedc199 |
500 | fprintf(fp, "\tunsigned char _offset;\n"); |
0f5d12e9 |
501 | fprintf(fp, "\tunsigned char length_offset;\n"); |
1bedc199 |
502 | fprintf(fp, "\tstruct rchan_buf *buf;\n"); |
2f74104a |
503 | |
a8f6f123 |
504 | if(ev->type != 0) |
505 | fprintf(fp, "\tstruct %s_%s_1* __1;\n\n", ev->name, facName); |
d7ed29cd |
506 | |
1bedc199 |
507 | /* Warning : this is done prior to taking locks : |
508 | * setting this value must be done at the end of the trace activation. |
509 | * (we don't care for trace removal, as the list of traces is protected : it |
510 | * just won't iterate on any trace). */ |
511 | fprintf(fp, |
512 | "\tif(ltt_traces.num_active_traces == 0) return;\n\n"); |
513 | |
2f74104a |
514 | fprintf(fp, "\t/* Disable interrupts. */\n"); |
515 | fprintf(fp, "\tlocal_irq_save(_flags);\n"); |
516 | fprintf(fp, "\tpreempt_disable();\n\n"); |
517 | |
518 | fprintf(fp, "\tltt_nesting[smp_processor_id()]++;\n"); |
1bedc199 |
519 | fprintf(fp, "\tbarrier();\n"); |
520 | fprintf(fp, "\tif(ltt_nesting[smp_processor_id()] > 1) goto unlock;\n"); |
2f74104a |
521 | fprintf(fp, "\tspin_lock(<t_traces.locks[smp_processor_id()]);\n\n"); |
522 | |
d7ed29cd |
523 | fprintf(fp, |
524 | "\tindex = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\ |
a8f6f123 |
525 | "\t\t\t\tevent_%s);\n", |
d7ed29cd |
526 | facName, checksum, ev->name); |
527 | fprintf(fp,"\n"); |
528 | |
a8f6f123 |
529 | /* For each trace */ |
d7ed29cd |
530 | fprintf(fp, "\tlist_for_each_entry(trace, <t_traces.head, list) {\n"); |
a8f6f123 |
531 | fprintf(fp, "\t\tif(!trace->active) continue;\n\n"); |
0f5d12e9 |
532 | |
533 | //length of buffer : length of all structures |
534 | fprintf(fp,"\t\tlength = 0;\n"); |
535 | fprintf(fp,"\t\tlength_offset = 0;\n"); |
536 | // if(ev->type == 0) fprintf(fp, "0"); |
537 | |
1bedc199 |
538 | fprintf(fp, "\t\tchannel = ltt_get_channel_from_index(trace, index);\n"); |
539 | fprintf(fp, "\t\tbuf = channel->rchan->buf[smp_processor_id()];\n"); |
540 | /* Warning : not atomic reservation : event size depends on the current |
541 | * address for alignment */ |
0f5d12e9 |
542 | // Replaces _offset |
2f74104a |
543 | fprintf(fp, "\t\theader_length = " |
1bedc199 |
544 | "ltt_get_event_header_size(trace, channel," |
545 | "buf->data + buf->offset, &_offset);\n"); |
0f5d12e9 |
546 | |
547 | for(pos1=0;pos1<structCount;pos1++){ |
548 | |
549 | if(ev->type->alignment > 1) { |
550 | fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1) ;\n", |
551 | ev->type->alignment, ev->type->alignment, ev->type->alignment); |
552 | } |
553 | fprintf(fp,"\t\tlength+=sizeof(struct %s_%s_%d);\n",ev->name, |
554 | facName,pos1+1); |
555 | // if(pos1 != structCount-1) fprintf(fp," + "); |
556 | } |
557 | |
558 | //length of buffer : length of all arrays, sequences and strings |
559 | seqCount = 0; |
560 | strCount = 0; |
561 | flag = 0; |
562 | if(ev->type != 0) |
563 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
564 | fld = (field *)ev->type->fields.array[pos1]; |
565 | td = fld->type; |
566 | if(td->type == SEQUENCE || td->type==STRING || td->type==ARRAY){ |
567 | if(td->type == SEQUENCE) { |
568 | if(td->alignment > 1) { |
569 | fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1)) ;\n", |
570 | td->alignment, td->alignment, td->alignment); |
571 | } |
572 | fprintf(fp, |
573 | "\t\tlength+=sizeof(%s) + (sizeof(%s) * seqlength_%d);\n", |
574 | uintOutputTypes[td->size], getTypeStr(td), ++seqCount); |
575 | } else if(td->type==STRING) { |
576 | if(td->alignment > 1) { |
577 | fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1)) ;\n", |
578 | td->alignment, td->alignment, td->alignment); |
579 | } |
580 | fprintf(fp,"length+=strlength_%d + 1;\n", |
581 | ++strCount); |
582 | } |
583 | else if(td->type==ARRAY) { |
584 | if(td->alignment > 1) { |
585 | fprintf(fp,"\t\tlength_offset+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
586 | td->alignment, td->alignment, td->alignment); |
587 | } |
588 | fprintf(fp,"\t\tlength+=sizeof(%s) * %d;\n", |
589 | getTypeStr(td),td->size); |
590 | if(structCount == 0) flag = 1; |
591 | } |
592 | } |
593 | } |
594 | fprintf(fp,";\n"); |
595 | |
596 | fprintf(fp, "\t\tevent_length = _offset + header_length + " |
597 | "length_offset + length;\n"); |
d7ed29cd |
598 | |
599 | /* Reserve the channel */ |
2f74104a |
600 | fprintf(fp, "\t\tbuff = relay_reserve(channel->rchan, event_length, &resret);\n"); |
a8f6f123 |
601 | fprintf(fp, "\t\tif(buff == NULL) {\n"); |
602 | fprintf(fp, "\t\t\t/* Buffer is full*/\n"); |
603 | fprintf(fp, "\t\t\t/* for debug BUG(); */\n"); // DEBUG! |
604 | fprintf(fp, "\t\t\tchannel->events_lost[smp_processor_id()]++;\n"); |
e3cc790d |
605 | fprintf(fp, "\t\t\tbreak;\n"); /* don't commit a NULL reservation! */ |
a8f6f123 |
606 | fprintf(fp, "\t\t}\n"); |
d7ed29cd |
607 | |
a8f6f123 |
608 | /* DEBUG */ |
2f74104a |
609 | fprintf(fp, "\t\tif(resret == 1) {\n"); |
610 | fprintf(fp, "printk(\"f%%lu e\%%u \", ltt_facility_%s_%X, event_%s);", |
a8f6f123 |
611 | facName, checksum, ev->name); |
2f74104a |
612 | fprintf(fp, "\t\t}\n"); |
a8f6f123 |
613 | |
614 | /* Write the header */ |
615 | fprintf(fp, "\n"); |
616 | fprintf(fp, "\t\tltt_write_event_header(trace, channel, buff, \n" |
1bedc199 |
617 | "\t\t\t\tltt_facility_%s_%X, event_%s, length, _offset);\n", |
a8f6f123 |
618 | facName, checksum, ev->name); |
619 | fprintf(fp, "\n"); |
0f5d12e9 |
620 | fprintf(fp, "\t\tchar *ptr = (char*)buff + _offset + header_length;\n"); |
621 | |
622 | |
d7ed29cd |
623 | //declare a char pointer if needed : starts at the end of the structs. |
0f5d12e9 |
624 | //if(structCount + hasStrSeq > 1) { |
625 | // fprintf(fp,"\t\tchar * ptr = (char*)buff + header_length"); |
626 | // for(pos1=0;pos1<structCount;pos1++){ |
627 | // fprintf(fp," + sizeof(struct %s_%s_%d)",ev->name, facName,pos1+1); |
628 | // } |
629 | // if(structCount + hasStrSeq > 1) fprintf(fp,";\n"); |
630 | //} |
d7ed29cd |
631 | |
632 | // Declare an alias pointer of the struct type to the beginning |
633 | // of the reserved area, just after the event header. |
0f5d12e9 |
634 | if(ev->type != 0) { |
635 | if(ev->type->alignment > 1) { |
636 | fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
637 | ev->type->alignment, ev->type->alignment, ev->type->alignment); |
638 | } |
639 | |
640 | fprintf(fp, "\t\t__1 = (struct %s_%s_1 *)(ptr);\n", |
a8f6f123 |
641 | ev->name, facName); |
0f5d12e9 |
642 | } |
d7ed29cd |
643 | //allocate memory for new struct and initialize it |
644 | //if(whichTypeFirst == 1){ //struct first |
a8f6f123 |
645 | //for(pos1=0;pos1<structCount;pos1++){ |
646 | // if(pos1==0) fprintf(fp, |
d7ed29cd |
647 | // "\tstruct %s_%s_1 * __1 = (struct %s_%s_1 *)buff;\n", |
648 | // ev->name, facName,ev->name, facName); |
649 | //MD disabled else fprintf(fp, |
650 | // "\tstruct %s_%s_%d __%d;\n", |
651 | // ev->name, facName,pos1+1,pos1+1); |
652 | //} |
653 | //}else if(whichTypeFirst == 2){ |
654 | // for(pos1=0;pos1<structCount;pos1++) |
a8f6f123 |
655 | // fprintf(fp,"\tstruct %s_%s_%d __%d;\n", |
d7ed29cd |
656 | // ev->name, facName,pos1+1,pos1+1); |
657 | //} |
3888436c |
658 | fprintf(fp,"\n"); |
659 | |
d7ed29cd |
660 | if(structCount) fprintf(fp,"\t\t//initialize structs\n"); |
661 | //flag = 0; |
662 | //structCount = 0; |
a8f6f123 |
663 | if(ev->type != 0) |
664 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
665 | fld = (field *)ev->type->fields.array[pos1]; |
666 | td = fld->type; |
667 | if(td->type != ARRAY && td->type != SEQUENCE && td->type != STRING){ |
668 | //if(flag == 0){ |
669 | // flag = 1; |
670 | // structCount++; |
671 | // if(structCount > 1) fprintf(fp,"\n"); |
672 | //} |
673 | fprintf(fp, "\t\t__1->%s = %s;\n", fld->name, fld->name ); |
674 | |
675 | //if(structCount == 1 && whichTypeFirst == 1) |
676 | // fprintf(fp, "\t__1->%s = %s;\n",fld->name,fld->name ); |
677 | //else |
678 | // fprintf(fp, "\t__%d.%s = %s;\n",structCount ,fld->name,fld->name); |
679 | } |
680 | //else flag = 0; |
681 | } |
682 | if(structCount) fprintf(fp,"\n"); |
3888436c |
683 | //set ptr to the end of first struct if needed; |
1bedc199 |
684 | //if(structCount + hasStrSeq > 1){ |
685 | // fprintf(fp,"\n\t\t//set ptr to the end of the first struct\n"); |
686 | // fprintf(fp,"\t\tptr += sizeof(struct %s_%s_1);\n\n",ev->name, facName); |
687 | //} |
3888436c |
688 | |
689 | //copy struct, sequence and string to buffer |
690 | seqCount = 0; |
691 | strCount = 0; |
692 | flag = 0; |
693 | structCount = 0; |
a8f6f123 |
694 | if(ev->type != 0) |
695 | for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ |
696 | fld = (field *)ev->type->fields.array[pos1]; |
697 | td = fld->type; |
698 | // if(td->type != STRING && td->type != SEQUENCE && td->type != ARRAY){ |
699 | // if(flag == 0) structCount++; |
700 | // flag++; |
701 | // if((structCount > 1 || whichTypeFirst == 2) && flag == 1){ |
702 | // assert(0); // MD : disabled ! |
703 | // fprintf(fp,"\t//copy struct to buffer\n"); |
704 | // fprintf(fp,"\tmemcpy(ptr, &__%d, sizeof(struct %s_%s_%d));\n", |
705 | // structCount, ev->name, facName,structCount); |
706 | // fprintf(fp,"\tptr += sizeof(struct %s_%s_%d);\n\n", |
707 | // ev->name, facName,structCount); |
708 | // } |
709 | // } |
710 | //else if(td->type == SEQUENCE){ |
711 | if(td->type == SEQUENCE){ |
712 | flag = 0; |
713 | fprintf(fp,"\t\t//copy sequence length and sequence to buffer\n"); |
0f5d12e9 |
714 | |
715 | if(td->alignment > 1) { |
716 | fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
717 | td->alignment, td->alignment, td->alignment); |
718 | } |
a8f6f123 |
719 | fprintf(fp,"\t\t*ptr = seqlength_%d;\n",++seqCount); |
720 | fprintf(fp,"\t\tptr += sizeof(%s);\n",uintOutputTypes[td->size]); |
0f5d12e9 |
721 | if(td->alignment > 1) { |
722 | fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
723 | td->alignment, td->alignment, td->alignment); |
724 | } |
a8f6f123 |
725 | fprintf(fp,"\t\tmemcpy(ptr, %s, sizeof(%s) * seqlength_%d);\n", |
726 | fld->name, getTypeStr(td), seqCount); |
0f5d12e9 |
727 | fprintf(fp,"\t\tptr += sizeof(%s) * seqlength_%d;\n\n", |
a8f6f123 |
728 | getTypeStr(td), seqCount); |
729 | } |
730 | else if(td->type==STRING){ |
731 | flag = 0; |
732 | fprintf(fp,"\t\t//copy string to buffer\n"); |
733 | fprintf(fp,"\t\tif(strlength_%d > 0){\n",++strCount); |
0f5d12e9 |
734 | if(td->alignment > 1) { |
735 | fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
736 | td->alignment, td->alignment, td->alignment); |
737 | } |
a8f6f123 |
738 | fprintf(fp,"\t\t\tmemcpy(ptr, %s, strlength_%d + 1);\n", |
739 | fld->name, strCount); |
740 | fprintf(fp,"\t\t\tptr += strlength_%d + 1;\n",strCount); |
741 | fprintf(fp,"\t\t}else{\n"); |
742 | fprintf(fp,"\t\t\t*ptr = '\\0';\n"); |
743 | fprintf(fp,"\t\t\tptr += 1;\n"); |
744 | fprintf(fp,"\t\t}\n\n"); |
745 | }else if(td->type==ARRAY){ |
746 | flag = 0; |
747 | fprintf(fp,"\t//copy array to buffer\n"); |
0f5d12e9 |
748 | if(td->alignment > 1) { |
749 | fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", |
750 | td->alignment, td->alignment, td->alignment); |
751 | } |
a8f6f123 |
752 | fprintf(fp,"\tmemcpy(ptr, %s, sizeof(%s) * %d);\n", |
753 | fld->name, getTypeStr(td), td->size); |
754 | fprintf(fp,"\tptr += sizeof(%s) * %d;\n\n", getTypeStr(td), td->size); |
755 | } |
756 | } |
3888436c |
757 | if(structCount + seqCount > 1) fprintf(fp,"\n"); |
758 | |
d7ed29cd |
759 | fprintf(fp,"\n"); |
760 | fprintf(fp, "\t\t/* Commit the work */\n"); |
a8f6f123 |
761 | fprintf(fp, "\t\trelay_commit(channel->rchan->buf[smp_processor_id()],\n" |
762 | "\t\t\t\tbuff, event_length);\n"); |
1bedc199 |
763 | fprintf(fp, "\t\tltt_write_commit_counter(" |
764 | "channel->rchan->buf[smp_processor_id()],\n" |
765 | "\t\t\t\tbuff);\n"); |
d7ed29cd |
766 | |
767 | /* End of traces iteration */ |
768 | fprintf(fp, "\t}\n\n"); |
769 | |
a8f6f123 |
770 | fprintf(fp, "\n"); |
1bedc199 |
771 | // The generated preempt_check_resched is not dangerous because |
772 | // interrupts are disabled. |
773 | fprintf(fp, "\tspin_unlock(<t_traces.locks[smp_processor_id()]);\n"); |
2f74104a |
774 | |
775 | fprintf(fp, "unlock:\n"); |
1bedc199 |
776 | fprintf(fp, "\tbarrier();\n"); |
2f74104a |
777 | fprintf(fp, "\tltt_nesting[smp_processor_id()]--;\n"); |
778 | fprintf(fp, "\t/* Re-enable interrupts */\n"); |
779 | fprintf(fp, "\tlocal_irq_restore(_flags);\n"); |
1bedc199 |
780 | fprintf(fp, "\tpreempt_enable_no_resched();\n"); |
2f74104a |
781 | //fprintf(fp, "\tpreempt_check_resched();\n"); |
782 | |
3888436c |
783 | //call trace function |
d7ed29cd |
784 | //fprintf(fp,"\n\t//call trace function\n"); |
785 | //fprintf(fp,"\tltt_log_event(ltt_facility_%s_%X, %s, bufLength, buff);\n",facName,checksum,ev->name); |
1bedc199 |
786 | fprintf(fp,"}\n"); |
787 | fprintf(fp, "#endif //CONFIG_LTT\n\n"); |
3888436c |
788 | } |
789 | |
790 | } |
791 | |
792 | /***************************************************************************** |
793 | *Function name |
794 | * getTypeStr : generate type string |
795 | *Input Params |
796 | * td : a type descriptor |
797 | *Return Values |
798 | * char * : type string |
799 | ****************************************************************************/ |
800 | char * getTypeStr(type_descriptor * td){ |
801 | type_descriptor * t ; |
802 | |
803 | switch(td->type){ |
804 | case INT: |
805 | return intOutputTypes[td->size]; |
806 | case UINT: |
807 | return uintOutputTypes[td->size]; |
31cbc5d3 |
808 | case POINTER: |
809 | return "void *"; |
810 | case LONG: |
811 | return "long"; |
812 | case ULONG: |
813 | return "unsigned long"; |
814 | case SIZE_T: |
815 | return "size_t"; |
816 | case SSIZE_T: |
817 | return "ssize_t"; |
818 | case OFF_T: |
819 | return "off_t"; |
3888436c |
820 | case FLOAT: |
821 | return floatOutputTypes[td->size]; |
822 | case STRING: |
a8f6f123 |
823 | return "const char"; |
3888436c |
824 | case ENUM: |
825 | return uintOutputTypes[td->size]; |
826 | case ARRAY: |
827 | case SEQUENCE: |
828 | t = td->nested_type; |
829 | switch(t->type){ |
830 | case INT: |
a8f6f123 |
831 | return intOutputTypes[t->size]; |
3888436c |
832 | case UINT: |
a8f6f123 |
833 | return uintOutputTypes[t->size]; |
31cbc5d3 |
834 | case POINTER: |
835 | return "void *"; |
836 | case LONG: |
837 | return "long"; |
838 | case ULONG: |
839 | return "unsigned long"; |
840 | case SIZE_T: |
841 | return "size_t"; |
842 | case SSIZE_T: |
843 | return "ssize_t"; |
844 | case OFF_T: |
845 | return "off_t"; |
3888436c |
846 | case FLOAT: |
a8f6f123 |
847 | return floatOutputTypes[t->size]; |
3888436c |
848 | case STRING: |
a8f6f123 |
849 | return "const char"; |
3888436c |
850 | case ENUM: |
a8f6f123 |
851 | return uintOutputTypes[t->size]; |
3888436c |
852 | default : |
a8f6f123 |
853 | error_callback(NULL,"Nested struct is not supportted"); |
854 | break; |
3888436c |
855 | } |
856 | break; |
857 | case STRUCT: //for now we do not support nested struct |
858 | error_callback(NULL,"Nested struct is not supportted"); |
859 | break; |
860 | default: |
861 | error_callback(NULL,"No type information"); |
862 | break; |
863 | } |
864 | return NULL; |
865 | } |
866 | |
867 | /***************************************************************************** |
868 | *Function name |
6d387597 |
869 | * generateLoaderfile: generate a facility loaded .h file |
3888436c |
870 | *Input Params |
871 | * fp : file to be written to |
872 | * facName : name of facility |
873 | * nbEvent : number of events in the facility |
874 | * checksum : checksum for the facility |
875 | ****************************************************************************/ |
8c6ca411 |
876 | void generateLoaderfile(FILE * fp, char * facName, int nbEvent, unsigned long checksum, char *capname){ |
a8f6f123 |
877 | fprintf(fp, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n",capname); |
878 | fprintf(fp, "#define _LTT_FACILITY_LOADER_%s_H_\n\n",capname); |
8c6ca411 |
879 | fprintf(fp,"#include <linux/ltt-facilities.h>\n", facName, checksum); |
44cac8a9 |
880 | fprintf(fp,"ltt_facility_t\tltt_facility_%s;\n", facName, checksum); |
6d387597 |
881 | fprintf(fp,"ltt_facility_t\tltt_facility_%s_%X;\n\n", facName, checksum); |
882 | |
a8f6f123 |
883 | fprintf(fp,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n", |
44cac8a9 |
884 | facName); |
a8f6f123 |
885 | fprintf(fp,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n", |
6d387597 |
886 | facName, checksum); |
a8f6f123 |
887 | fprintf(fp,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", checksum); |
888 | fprintf(fp,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", facName); |
889 | fprintf(fp,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\t%d\n\n", nbEvent); |
890 | fprintf(fp, "#endif //_LTT_FACILITY_LOADER_%s_H_\n",capname); |
891 | } |
892 | |
893 | void generateCfile(FILE * fp, char * filefacname){ |
894 | |
895 | fprintf(fp, "/*\n"); |
896 | fprintf(fp, " * ltt-facility-loader-%s.c\n", filefacname); |
897 | fprintf(fp, " *\n"); |
898 | fprintf(fp, " * (C) Copyright 2005 - \n"); |
899 | fprintf(fp, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n"); |
900 | fprintf(fp, " *\n"); |
901 | fprintf(fp, " * Contains the LTT facility loader.\n"); |
902 | fprintf(fp, " *\n"); |
903 | fprintf(fp, " */\n"); |
904 | fprintf(fp, "\n"); |
905 | fprintf(fp, "\n"); |
906 | fprintf(fp, "#include <linux/ltt-facilities.h>\n"); |
907 | fprintf(fp, "#include <linux/module.h>\n"); |
908 | fprintf(fp, "#include <linux/init.h>\n"); |
909 | fprintf(fp, "#include <linux/config.h>\n"); |
910 | fprintf(fp, "#include \"ltt-facility-loader-%s.h\"\n", filefacname); |
911 | fprintf(fp, "\n"); |
912 | fprintf(fp, "\n"); |
913 | fprintf(fp, "#ifdef CONFIG_LTT\n"); |
914 | fprintf(fp, "\n"); |
915 | fprintf(fp, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n"); |
916 | fprintf(fp, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n"); |
917 | fprintf(fp, "\n"); |
918 | fprintf(fp, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n"); |
919 | fprintf(fp, "\n"); |
920 | fprintf(fp, "#define SYMBOL_STRING(sym) #sym\n"); |
921 | fprintf(fp, "\n"); |
922 | fprintf(fp, "static struct ltt_facility facility = {\n"); |
923 | fprintf(fp, "\t.name = ltt_facility_name,\n"); |
924 | fprintf(fp, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n"); |
925 | fprintf(fp, "\t.checksum = LTT_FACILITY_CHECKSUM,\n"); |
926 | fprintf(fp, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL)\n"); |
927 | fprintf(fp, "};\n"); |
928 | fprintf(fp, "\n"); |
929 | fprintf(fp, "#ifndef MODULE\n"); |
930 | fprintf(fp, "\n"); |
931 | fprintf(fp, "/* Built-in facility. */\n"); |
932 | fprintf(fp, "\n"); |
933 | fprintf(fp, "static int __init facility_init(void)\n"); |
934 | fprintf(fp, "{\n"); |
935 | fprintf(fp, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", filefacname); |
936 | fprintf(fp, "\n"); |
937 | fprintf(fp, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n"); |
938 | fprintf(fp, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n"); |
939 | fprintf(fp, "\t\n"); |
940 | fprintf(fp, "\treturn LTT_FACILITY_SYMBOL;\n"); |
941 | fprintf(fp, "}\n"); |
942 | fprintf(fp, "__initcall(facility_init);\n"); |
943 | fprintf(fp, "\n"); |
944 | fprintf(fp, "\n"); |
945 | fprintf(fp, "\n"); |
946 | fprintf(fp, "#else \n"); |
947 | fprintf(fp, "\n"); |
948 | fprintf(fp, "/* Dynamic facility. */\n"); |
949 | fprintf(fp, "\n"); |
950 | fprintf(fp, "static int __init facility_init(void)\n"); |
951 | fprintf(fp, "{\n"); |
952 | fprintf(fp, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", filefacname); |
953 | fprintf(fp, "\n"); |
954 | fprintf(fp, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n"); |
955 | fprintf(fp, "\tLTT_FACILITY_SYMBOL_CHECKSUM = LTT_FACILITY_SYMBOL;\n"); |
956 | fprintf(fp, "\n"); |
957 | fprintf(fp, "\treturn LTT_FACILITY_SYMBOL;\n"); |
958 | fprintf(fp, "}\n"); |
959 | fprintf(fp, "\n"); |
960 | fprintf(fp, "static void __exit facility_exit(void)\n"); |
961 | fprintf(fp, "{\n"); |
962 | fprintf(fp, "\tint err;\n"); |
963 | fprintf(fp, "\n"); |
964 | fprintf(fp, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n"); |
965 | fprintf(fp, "\tif(err != 0)\n"); |
966 | fprintf(fp, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n"); |
967 | fprintf(fp, "\n"); |
968 | fprintf(fp, "}\n"); |
969 | fprintf(fp, "\n"); |
970 | fprintf(fp, "module_init(facility_init)\n"); |
971 | fprintf(fp, "module_exit(facility_exit)\n"); |
972 | fprintf(fp, "\n"); |
973 | fprintf(fp, "\n"); |
974 | fprintf(fp, "MODULE_LICENSE(\"GPL\");\n"); |
975 | fprintf(fp, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n"); |
976 | fprintf(fp, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n"); |
977 | fprintf(fp, "\n"); |
978 | fprintf(fp, "#endif //MODULE\n"); |
979 | fprintf(fp, "\n"); |
980 | fprintf(fp, "#endif //CONFIG_LTT\n"); |
3888436c |
981 | } |
982 | |
983 | |