1 #ifndef _LTT_FACILITY_TESTS_H_
2 #define _LTT_FACILITY_TESTS_H_
4 #include <linux/types.h>
5 #include "ltt-facility-id-tests.h"
6 #include <linux/ltt-core.h>
10 /* Event write_4bytes structures */
12 /* Event write_4bytes logging function */
13 static inline void trace_tests_write_4bytes(
15 #if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS))
21 struct ltt_channel_struct
*channel
;
22 struct ltt_trace_struct
*trace
;
23 struct rchan_buf
*relayfs_buf
;
25 size_t real_to_base
= 0; /* The buffer is allocated on arch_size alignment */
26 size_t *to_base
= &real_to_base
;
28 size_t *to
= &real_to
;
30 size_t *len
= &real_len
;
34 const void *real_from
;
35 const void **from
= &real_from
;
37 size_t before_hdr_pad
, after_hdr_pad
, header_size
;
39 if(ltt_traces
.num_active_traces
== 0) return;
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. */
46 *from
= <tng_param_data
;
50 *to
+= ltt_align(*to
, align
); /* align output */
52 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
57 reserve_size
= *to_base
+ *to
+ *len
;
59 ltt_nesting
[smp_processor_id()]++;
60 index
= ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB
,
61 event_tests_write_4bytes
);
63 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
) {
64 if(!trace
->active
) continue;
66 channel
= ltt_get_channel_from_index(trace
, index
);
67 relayfs_buf
= channel
->rchan
->buf
[smp_processor_id()];
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 */
75 *to_base
= *to
= *len
= 0;
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
;
82 *from
= <tng_param_data
;
86 *to
+= ltt_align(*to
, align
); /* align output */
88 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
93 /* Flush pending memcpy */
95 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
100 ltt_commit_slot(relayfs_buf
, buffer
, slot_size
);
104 ltt_nesting
[smp_processor_id()]--;
105 preempt_enable_no_resched();
107 #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS))
110 /* Event write_string structures */
111 static inline void lttng_write_string_tests_write_string_data(
122 /* Flush pending memcpy */
125 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
130 align
= sizeof(char);
133 *to
+= ltt_align(*to
, align
); /* align output */
135 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
138 /* Contains variable sized fields : must explode the structure */
140 size
= strlen(obj
) + 1; /* Include final NULL char. */
142 memcpy(buffer
+*to_base
+*to
, obj
, size
);
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
;
150 /* Put source *from just after the C string */
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))
164 struct ltt_channel_struct
*channel
;
165 struct ltt_trace_struct
*trace
;
166 struct rchan_buf
*relayfs_buf
;
168 size_t real_to_base
= 0; /* The buffer is allocated on arch_size alignment */
169 size_t *to_base
= &real_to_base
;
171 size_t *to
= &real_to
;
173 size_t *len
= &real_len
;
176 const void *real_from
;
177 const void **from
= &real_from
;
179 size_t before_hdr_pad
, after_hdr_pad
, header_size
;
181 if(ltt_traces
.num_active_traces
== 0) return;
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. */
188 *from
= lttng_param_data
;
189 lttng_write_string_tests_write_string_data(buffer
, to_base
, to
, from
, len
, lttng_param_data
);
191 reserve_size
= *to_base
+ *to
+ *len
;
193 ltt_nesting
[smp_processor_id()]++;
194 index
= ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB
,
195 event_tests_write_string
);
197 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
) {
198 if(!trace
->active
) continue;
200 channel
= ltt_get_channel_from_index(trace
, index
);
201 relayfs_buf
= channel
->rchan
->buf
[smp_processor_id()];
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 */
209 *to_base
= *to
= *len
= 0;
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
;
216 *from
= lttng_param_data
;
217 lttng_write_string_tests_write_string_data(buffer
, to_base
, to
, from
, len
, lttng_param_data
);
219 /* Flush pending memcpy */
221 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
226 ltt_commit_slot(relayfs_buf
, buffer
, slot_size
);
230 ltt_nesting
[smp_processor_id()]--;
231 preempt_enable_no_resched();
233 #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS))
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
{
240 const int64_t *array
;
243 struct lttng_tests_write_struct_data2
{
246 lttng_sequence_tests_write_struct_data2_data5 data5
;
250 static inline size_t lttng_get_alignment_sequence_tests_write_struct_data2_data5(
251 lttng_sequence_tests_write_struct_data2_data5
*obj
)
253 size_t align
=0, localign
;
254 localign
= sizeof(unsigned int);
255 align
= max(align
, localign
);
257 localign
= sizeof(int64_t);
258 align
= max(align
, localign
);
263 static inline size_t lttng_get_alignment_struct_tests_write_struct_data2(
264 struct lttng_tests_write_struct_data2
*obj
)
266 size_t align
=0, localign
;
267 localign
= sizeof(char);
268 align
= max(align
, localign
);
270 localign
= sizeof(int);
271 align
= max(align
, localign
);
273 localign
= lttng_get_alignment_sequence_tests_write_struct_data2_data5(&obj
->data5
);
274 align
= max(align
, localign
);
276 localign
= sizeof(int);
277 align
= max(align
, localign
);
282 static inline void lttng_write_string_tests_write_struct_data2_data3(
293 /* Flush pending memcpy */
296 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
301 align
= sizeof(char);
304 *to
+= ltt_align(*to
, align
); /* align output */
306 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
309 /* Contains variable sized fields : must explode the structure */
311 size
= strlen(obj
) + 1; /* Include final NULL char. */
313 memcpy(buffer
+*to_base
+*to
, obj
, size
);
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
;
321 /* Put source *from just after the C string */
325 static inline void lttng_write_sequence_tests_write_struct_data2_data5(
331 lttng_sequence_tests_write_struct_data2_data5
*obj
)
335 /* Flush pending memcpy */
338 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
343 align
= lttng_get_alignment_sequence_tests_write_struct_data2_data5(obj
);
346 *to
+= ltt_align(*to
, align
); /* align output */
348 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
351 /* Contains variable sized fields : must explode the structure */
354 align
= sizeof(unsigned int);
357 *to
+= ltt_align(*to
, align
); /* align output */
359 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
362 *len
+= sizeof(unsigned int);
365 memcpy(buffer
+*to_base
+*to
, &obj
->len
, *len
);
369 align
= sizeof(int64_t);
372 *to
+= ltt_align(*to
, align
); /* align output */
374 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
377 *len
+= sizeof(int64_t);
379 *len
= obj
->len
* (*len
);
381 memcpy(buffer
+*to_base
+*to
, obj
->array
, *len
);
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
;
391 /* Put source *from just after the C sequence */
395 static inline void lttng_write_struct_tests_write_struct_data2(
401 struct lttng_tests_write_struct_data2
*obj
)
405 align
= lttng_get_alignment_struct_tests_write_struct_data2(obj
);
408 *to
+= ltt_align(*to
, align
); /* align output */
410 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
413 /* Contains variable sized fields : must explode the structure */
415 lttng_write_string_tests_write_struct_data2_data3(buffer
, to_base
, to
, from
, len
, obj
->data3
);
420 *to
+= ltt_align(*to
, align
); /* align output */
422 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
427 lttng_write_sequence_tests_write_struct_data2_data5(buffer
, to_base
, to
, from
, len
, &obj
->data5
);
431 *to
+= ltt_align(*to
, align
); /* align output */
433 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
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))
451 struct ltt_channel_struct
*channel
;
452 struct ltt_trace_struct
*trace
;
453 struct rchan_buf
*relayfs_buf
;
455 size_t real_to_base
= 0; /* The buffer is allocated on arch_size alignment */
456 size_t *to_base
= &real_to_base
;
458 size_t *to
= &real_to
;
460 size_t *len
= &real_len
;
464 const void *real_from
;
465 const void **from
= &real_from
;
467 size_t before_hdr_pad
, after_hdr_pad
, header_size
;
469 if(ltt_traces
.num_active_traces
== 0) return;
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. */
476 *from
= <tng_param_data1
;
480 *to
+= ltt_align(*to
, align
); /* align output */
482 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
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
;
491 ltt_nesting
[smp_processor_id()]++;
492 index
= ltt_get_index_from_facility(ltt_facility_tests_2F06D8DB
,
493 event_tests_write_struct
);
495 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
) {
496 if(!trace
->active
) continue;
498 channel
= ltt_get_channel_from_index(trace
, index
);
499 relayfs_buf
= channel
->rchan
->buf
[smp_processor_id()];
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 */
507 *to_base
= *to
= *len
= 0;
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
;
514 *from
= <tng_param_data1
;
518 *to
+= ltt_align(*to
, align
); /* align output */
520 *len
+= ltt_align(*to
+*len
, align
); /* alignment, ok to do a memcpy of it */
525 /* Flush pending memcpy */
527 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
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 */
536 memcpy(buffer
+*to_base
+*to
, *from
, *len
);
541 ltt_commit_slot(relayfs_buf
, buffer
, slot_size
);
545 ltt_nesting
[smp_processor_id()]--;
546 preempt_enable_no_resched();
548 #endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_TESTS))
551 #endif //_LTT_FACILITY_TESTS_H_