abbd00d3 |
1 | #ifndef _LTT_FACILITY_TESTS_H_ |
2 | #define _LTT_FACILITY_TESTS_H_ |
3 | |
4 | #include <linux/types.h> |
5 | #include "ltt-facility-id-tests.h" |
6 | #include <linux/ltt-core.h> |
7 | |
8 | /* Named types */ |
9 | |
10 | /* Event write_4bytes structures */ |
11 | |
12 | /* Event write_4bytes logging function */ |
13 | static inline void trace_tests_write_4bytes( |
14 | int lttng_param_data) |
15 | #if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
16 | { |
17 | } |
18 | #else |
19 | { |
20 | unsigned int index; |
21 | struct ltt_channel_struct *channel; |
22 | struct ltt_trace_struct *trace; |
23 | struct rchan_buf *relayfs_buf; |
24 | void *buffer = NULL; |
25 | size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */ |
26 | size_t *to_base = &real_to_base; |
27 | size_t real_to = 0; |
28 | size_t *to = &real_to; |
29 | size_t real_len = 0; |
30 | size_t *len = &real_len; |
31 | size_t reserve_size; |
32 | size_t slot_size; |
33 | size_t align; |
34 | const void *real_from; |
35 | const void **from = &real_from; |
36 | u64 tsc; |
37 | size_t before_hdr_pad, after_hdr_pad, header_size; |
38 | |
39 | if(ltt_traces.num_active_traces == 0) return; |
40 | |
41 | /* For each field, calculate the field size. */ |
42 | /* size = *to_base + *to + *len */ |
43 | /* Assume that the padding for alignment starts at a |
44 | * sizeof(void *) address. */ |
45 | |
46 | *from = <tng_param_data; |
47 | align = sizeof(int); |
48 | |
49 | if(*len == 0) { |
50 | *to += ltt_align(*to, align); /* align output */ |
51 | } else { |
52 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
53 | } |
54 | |
55 | *len += sizeof(int); |
56 | |
57 | reserve_size = *to_base + *to + *len; |
58 | preempt_disable(); |
59 | ltt_nesting[smp_processor_id()]++; |
60 | index = ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB, |
61 | event_tests_write_4bytes); |
62 | |
63 | list_for_each_entry_rcu(trace, <t_traces.head, list) { |
64 | if(!trace->active) continue; |
65 | |
66 | channel = ltt_get_channel_from_index(trace, index); |
67 | relayfs_buf = channel->rchan->buf[smp_processor_id()]; |
68 | |
69 | slot_size = 0; |
70 | buffer = ltt_reserve_slot(trace, relayfs_buf, |
71 | reserve_size, &slot_size, &tsc, |
72 | &before_hdr_pad, &after_hdr_pad, &header_size); |
73 | if(!buffer) continue; /* buffer full */ |
74 | |
75 | *to_base = *to = *len = 0; |
76 | |
77 | ltt_write_event_header(trace, channel, buffer, |
78 | ltt_facility_tests_2F06D8DB, event_tests_write_4bytes, |
79 | reserve_size, before_hdr_pad, tsc); |
80 | *to_base += before_hdr_pad + after_hdr_pad + header_size; |
81 | |
82 | *from = <tng_param_data; |
83 | align = sizeof(int); |
84 | |
85 | if(*len == 0) { |
86 | *to += ltt_align(*to, align); /* align output */ |
87 | } else { |
88 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
89 | } |
90 | |
91 | *len += sizeof(int); |
92 | |
93 | /* Flush pending memcpy */ |
94 | if(*len != 0) { |
95 | memcpy(buffer+*to_base+*to, *from, *len); |
96 | *to += *len; |
97 | *len = 0; |
98 | } |
99 | |
100 | ltt_commit_slot(relayfs_buf, buffer, slot_size); |
101 | |
102 | } |
103 | |
104 | ltt_nesting[smp_processor_id()]--; |
105 | preempt_enable_no_resched(); |
106 | } |
107 | #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
108 | |
109 | |
110 | /* Event write_string structures */ |
111 | static inline void lttng_write_string_tests_write_string_data( |
112 | void *buffer, |
113 | size_t *to_base, |
114 | size_t *to, |
115 | const void **from, |
116 | size_t *len, |
117 | const char * obj) |
118 | { |
119 | size_t size; |
120 | size_t align; |
121 | |
122 | /* Flush pending memcpy */ |
123 | if(*len != 0) { |
124 | if(buffer != NULL) |
125 | memcpy(buffer+*to_base+*to, *from, *len); |
126 | } |
127 | *to += *len; |
128 | *len = 0; |
129 | |
130 | align = sizeof(char); |
131 | |
132 | if(*len == 0) { |
133 | *to += ltt_align(*to, align); /* align output */ |
134 | } else { |
135 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
136 | } |
137 | |
138 | /* Contains variable sized fields : must explode the structure */ |
139 | |
140 | size = strlen(obj) + 1; /* Include final NULL char. */ |
141 | if(buffer != NULL) |
142 | memcpy(buffer+*to_base+*to, obj, size); |
143 | *to += size; |
144 | |
145 | /* Realign the *to_base on arch size, set *to to 0 */ |
146 | *to += ltt_align(*to, sizeof(void *)); |
147 | *to_base = *to_base+*to; |
148 | *to = 0; |
149 | |
150 | /* Put source *from just after the C string */ |
151 | *from += size; |
152 | } |
153 | |
154 | |
155 | /* Event write_string logging function */ |
156 | static inline void trace_tests_write_string( |
157 | const char * lttng_param_data) |
158 | #if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
159 | { |
160 | } |
161 | #else |
162 | { |
163 | unsigned int index; |
164 | struct ltt_channel_struct *channel; |
165 | struct ltt_trace_struct *trace; |
166 | struct rchan_buf *relayfs_buf; |
167 | void *buffer = NULL; |
168 | size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */ |
169 | size_t *to_base = &real_to_base; |
170 | size_t real_to = 0; |
171 | size_t *to = &real_to; |
172 | size_t real_len = 0; |
173 | size_t *len = &real_len; |
174 | size_t reserve_size; |
175 | size_t slot_size; |
176 | const void *real_from; |
177 | const void **from = &real_from; |
178 | u64 tsc; |
179 | size_t before_hdr_pad, after_hdr_pad, header_size; |
180 | |
181 | if(ltt_traces.num_active_traces == 0) return; |
182 | |
183 | /* For each field, calculate the field size. */ |
184 | /* size = *to_base + *to + *len */ |
185 | /* Assume that the padding for alignment starts at a |
186 | * sizeof(void *) address. */ |
187 | |
188 | *from = lttng_param_data; |
189 | lttng_write_string_tests_write_string_data(buffer, to_base, to, from, len, lttng_param_data); |
190 | |
191 | reserve_size = *to_base + *to + *len; |
192 | preempt_disable(); |
193 | ltt_nesting[smp_processor_id()]++; |
194 | index = ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB, |
195 | event_tests_write_string); |
196 | |
197 | list_for_each_entry_rcu(trace, <t_traces.head, list) { |
198 | if(!trace->active) continue; |
199 | |
200 | channel = ltt_get_channel_from_index(trace, index); |
201 | relayfs_buf = channel->rchan->buf[smp_processor_id()]; |
202 | |
203 | slot_size = 0; |
204 | buffer = ltt_reserve_slot(trace, relayfs_buf, |
205 | reserve_size, &slot_size, &tsc, |
206 | &before_hdr_pad, &after_hdr_pad, &header_size); |
207 | if(!buffer) continue; /* buffer full */ |
208 | |
209 | *to_base = *to = *len = 0; |
210 | |
211 | ltt_write_event_header(trace, channel, buffer, |
212 | ltt_facility_tests_2F06D8DB, event_tests_write_string, |
213 | reserve_size, before_hdr_pad, tsc); |
214 | *to_base += before_hdr_pad + after_hdr_pad + header_size; |
215 | |
216 | *from = lttng_param_data; |
217 | lttng_write_string_tests_write_string_data(buffer, to_base, to, from, len, lttng_param_data); |
218 | |
219 | /* Flush pending memcpy */ |
220 | if(*len != 0) { |
221 | memcpy(buffer+*to_base+*to, *from, *len); |
222 | *to += *len; |
223 | *len = 0; |
224 | } |
225 | |
226 | ltt_commit_slot(relayfs_buf, buffer, slot_size); |
227 | |
228 | } |
229 | |
230 | ltt_nesting[smp_processor_id()]--; |
231 | preempt_enable_no_resched(); |
232 | } |
233 | #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
234 | |
235 | |
236 | /* Event write_struct structures */ |
237 | typedef struct lttng_sequence_tests_write_struct_data2_data5 lttng_sequence_tests_write_struct_data2_data5; |
238 | struct lttng_sequence_tests_write_struct_data2_data5 { |
239 | unsigned int len; |
240 | const int64_t *array; |
241 | }; |
242 | |
243 | struct lttng_tests_write_struct_data2 { |
244 | const char * data3; |
245 | int data4; |
246 | lttng_sequence_tests_write_struct_data2_data5 data5; |
247 | int data6; |
248 | } LTT_ALIGN; |
249 | |
250 | static inline size_t lttng_get_alignment_sequence_tests_write_struct_data2_data5( |
251 | lttng_sequence_tests_write_struct_data2_data5 *obj) |
252 | { |
253 | size_t align=0, localign; |
254 | localign = sizeof(unsigned int); |
255 | align = max(align, localign); |
256 | |
257 | localign = sizeof(int64_t); |
258 | align = max(align, localign); |
259 | |
260 | return align; |
261 | } |
262 | |
263 | static inline size_t lttng_get_alignment_struct_tests_write_struct_data2( |
264 | struct lttng_tests_write_struct_data2 *obj) |
265 | { |
266 | size_t align=0, localign; |
267 | localign = sizeof(char); |
268 | align = max(align, localign); |
269 | |
270 | localign = sizeof(int); |
271 | align = max(align, localign); |
272 | |
273 | localign = lttng_get_alignment_sequence_tests_write_struct_data2_data5(&obj->data5); |
274 | align = max(align, localign); |
275 | |
276 | localign = sizeof(int); |
277 | align = max(align, localign); |
278 | |
279 | return align; |
280 | } |
281 | |
282 | static inline void lttng_write_string_tests_write_struct_data2_data3( |
283 | void *buffer, |
284 | size_t *to_base, |
285 | size_t *to, |
286 | const void **from, |
287 | size_t *len, |
288 | const char * obj) |
289 | { |
290 | size_t size; |
291 | size_t align; |
292 | |
293 | /* Flush pending memcpy */ |
294 | if(*len != 0) { |
295 | if(buffer != NULL) |
296 | memcpy(buffer+*to_base+*to, *from, *len); |
297 | } |
298 | *to += *len; |
299 | *len = 0; |
300 | |
301 | align = sizeof(char); |
302 | |
303 | if(*len == 0) { |
304 | *to += ltt_align(*to, align); /* align output */ |
305 | } else { |
306 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
307 | } |
308 | |
309 | /* Contains variable sized fields : must explode the structure */ |
310 | |
311 | size = strlen(obj) + 1; /* Include final NULL char. */ |
312 | if(buffer != NULL) |
313 | memcpy(buffer+*to_base+*to, obj, size); |
314 | *to += size; |
315 | |
316 | /* Realign the *to_base on arch size, set *to to 0 */ |
317 | *to += ltt_align(*to, sizeof(void *)); |
318 | *to_base = *to_base+*to; |
319 | *to = 0; |
320 | |
321 | /* Put source *from just after the C string */ |
322 | *from += size; |
323 | } |
324 | |
325 | static inline void lttng_write_sequence_tests_write_struct_data2_data5( |
326 | void *buffer, |
327 | size_t *to_base, |
328 | size_t *to, |
329 | const void **from, |
330 | size_t *len, |
331 | lttng_sequence_tests_write_struct_data2_data5 *obj) |
332 | { |
333 | size_t align; |
334 | |
335 | /* Flush pending memcpy */ |
336 | if(*len != 0) { |
337 | if(buffer != NULL) |
338 | memcpy(buffer+*to_base+*to, *from, *len); |
339 | } |
340 | *to += *len; |
341 | *len = 0; |
342 | |
343 | align = lttng_get_alignment_sequence_tests_write_struct_data2_data5(obj); |
344 | |
345 | if(*len == 0) { |
346 | *to += ltt_align(*to, align); /* align output */ |
347 | } else { |
348 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
349 | } |
350 | |
351 | /* Contains variable sized fields : must explode the structure */ |
352 | |
353 | /* Copy members */ |
354 | align = sizeof(unsigned int); |
355 | |
356 | if(*len == 0) { |
357 | *to += ltt_align(*to, align); /* align output */ |
358 | } else { |
359 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
360 | } |
361 | |
362 | *len += sizeof(unsigned int); |
363 | |
364 | if(buffer != NULL) |
365 | memcpy(buffer+*to_base+*to, &obj->len, *len); |
366 | *to += *len; |
367 | *len = 0; |
368 | |
369 | align = sizeof(int64_t); |
370 | |
371 | if(*len == 0) { |
372 | *to += ltt_align(*to, align); /* align output */ |
373 | } else { |
374 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
375 | } |
376 | |
377 | *len += sizeof(int64_t); |
378 | |
379 | *len = obj->len * (*len); |
380 | if(buffer != NULL) |
381 | memcpy(buffer+*to_base+*to, obj->array, *len); |
382 | *to += *len; |
383 | *len = 0; |
384 | |
385 | |
386 | /* Realign the *to_base on arch size, set *to to 0 */ |
387 | *to += ltt_align(*to, sizeof(void *)); |
388 | *to_base = *to_base+*to; |
389 | *to = 0; |
390 | |
391 | /* Put source *from just after the C sequence */ |
392 | *from = obj+1; |
393 | } |
394 | |
395 | static inline void lttng_write_struct_tests_write_struct_data2( |
396 | void *buffer, |
397 | size_t *to_base, |
398 | size_t *to, |
399 | const void **from, |
400 | size_t *len, |
401 | struct lttng_tests_write_struct_data2 *obj) |
402 | { |
403 | size_t align; |
404 | |
405 | align = lttng_get_alignment_struct_tests_write_struct_data2(obj); |
406 | |
407 | if(*len == 0) { |
408 | *to += ltt_align(*to, align); /* align output */ |
409 | } else { |
410 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
411 | } |
412 | |
413 | /* Contains variable sized fields : must explode the structure */ |
414 | |
415 | lttng_write_string_tests_write_struct_data2_data3(buffer, to_base, to, from, len, obj->data3); |
416 | |
417 | align = sizeof(int); |
418 | |
419 | if(*len == 0) { |
420 | *to += ltt_align(*to, align); /* align output */ |
421 | } else { |
422 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
423 | } |
424 | |
425 | *len += sizeof(int); |
426 | |
427 | lttng_write_sequence_tests_write_struct_data2_data5(buffer, to_base, to, from, len, &obj->data5); |
428 | align = sizeof(int); |
429 | |
430 | if(*len == 0) { |
431 | *to += ltt_align(*to, align); /* align output */ |
432 | } else { |
433 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
434 | } |
435 | |
436 | *len += sizeof(int); |
437 | |
438 | } |
439 | |
440 | |
441 | /* Event write_struct logging function */ |
442 | static inline void trace_tests_write_struct( |
443 | int lttng_param_data1, |
444 | struct lttng_tests_write_struct_data2 * lttng_param_data2) |
445 | #if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
446 | { |
447 | } |
448 | #else |
449 | { |
450 | unsigned int index; |
451 | struct ltt_channel_struct *channel; |
452 | struct ltt_trace_struct *trace; |
453 | struct rchan_buf *relayfs_buf; |
454 | void *buffer = NULL; |
455 | size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */ |
456 | size_t *to_base = &real_to_base; |
457 | size_t real_to = 0; |
458 | size_t *to = &real_to; |
459 | size_t real_len = 0; |
460 | size_t *len = &real_len; |
461 | size_t reserve_size; |
462 | size_t slot_size; |
463 | size_t align; |
464 | const void *real_from; |
465 | const void **from = &real_from; |
466 | u64 tsc; |
467 | size_t before_hdr_pad, after_hdr_pad, header_size; |
468 | |
469 | if(ltt_traces.num_active_traces == 0) return; |
470 | |
471 | /* For each field, calculate the field size. */ |
472 | /* size = *to_base + *to + *len */ |
473 | /* Assume that the padding for alignment starts at a |
474 | * sizeof(void *) address. */ |
475 | |
476 | *from = <tng_param_data1; |
477 | align = sizeof(int); |
478 | |
479 | if(*len == 0) { |
480 | *to += ltt_align(*to, align); /* align output */ |
481 | } else { |
482 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
483 | } |
484 | |
485 | *len += sizeof(int); |
486 | |
487 | *from = lttng_param_data2; |
488 | lttng_write_struct_tests_write_struct_data2(buffer, to_base, to, from, len, lttng_param_data2); |
489 | reserve_size = *to_base + *to + *len; |
490 | preempt_disable(); |
491 | ltt_nesting[smp_processor_id()]++; |
492 | index = ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB, |
493 | event_tests_write_struct); |
494 | |
495 | list_for_each_entry_rcu(trace, <t_traces.head, list) { |
496 | if(!trace->active) continue; |
497 | |
498 | channel = ltt_get_channel_from_index(trace, index); |
499 | relayfs_buf = channel->rchan->buf[smp_processor_id()]; |
500 | |
501 | slot_size = 0; |
502 | buffer = ltt_reserve_slot(trace, relayfs_buf, |
503 | reserve_size, &slot_size, &tsc, |
504 | &before_hdr_pad, &after_hdr_pad, &header_size); |
505 | if(!buffer) continue; /* buffer full */ |
506 | |
507 | *to_base = *to = *len = 0; |
508 | |
509 | ltt_write_event_header(trace, channel, buffer, |
510 | ltt_facility_tests_2F06D8DB, event_tests_write_struct, |
511 | reserve_size, before_hdr_pad, tsc); |
512 | *to_base += before_hdr_pad + after_hdr_pad + header_size; |
513 | |
514 | *from = <tng_param_data1; |
515 | align = sizeof(int); |
516 | |
517 | if(*len == 0) { |
518 | *to += ltt_align(*to, align); /* align output */ |
519 | } else { |
520 | *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */ |
521 | } |
522 | |
523 | *len += sizeof(int); |
524 | |
525 | /* Flush pending memcpy */ |
526 | if(*len != 0) { |
527 | memcpy(buffer+*to_base+*to, *from, *len); |
528 | *to += *len; |
529 | *len = 0; |
530 | } |
531 | |
532 | *from = lttng_param_data2; |
533 | lttng_write_struct_tests_write_struct_data2(buffer, to_base, to, from, len, lttng_param_data2); |
534 | /* Flush pending memcpy */ |
535 | if(*len != 0) { |
536 | memcpy(buffer+*to_base+*to, *from, *len); |
537 | *to += *len; |
538 | *len = 0; |
539 | } |
540 | |
541 | ltt_commit_slot(relayfs_buf, buffer, slot_size); |
542 | |
543 | } |
544 | |
545 | ltt_nesting[smp_processor_id()]--; |
546 | preempt_enable_no_resched(); |
547 | } |
548 | #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS)) |
549 | |
550 | |
551 | #endif //_LTT_FACILITY_TESTS_H_ |