abbd00d3 |
1 | #ifndef _LTT_FACILITY_TESTS_H_ |
2 | #define _LTT_FACILITY_TESTS_H_ |
3 | |
d4c8882b |
4 | |
abbd00d3 |
5 | #include <linux/types.h> |
6 | #include "ltt-facility-id-tests.h" |
d4c8882b |
7 | #include <ltt/ltt-tracer.h> |
8 | |
9 | #define ltt_get_index_from_facility_tests ltt_get_index_from_facility |
abbd00d3 |
10 | |
11 | /* Named types */ |
12 | |
13 | /* Event write_4bytes structures */ |
14 | |
15 | /* Event write_4bytes logging function */ |
16 | static inline void trace_tests_write_4bytes( |
d4c8882b |
17 | unsigned int lttng_param_value) |
abbd00d3 |
18 | { |
19 | unsigned int index; |
20 | struct ltt_channel_struct *channel; |
21 | struct ltt_trace_struct *trace; |
d4c8882b |
22 | void *transport_data; |
23 | char *buffer = NULL; |
abbd00d3 |
24 | size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */ |
25 | size_t *to_base = &real_to_base; |
26 | size_t real_to = 0; |
27 | size_t *to = &real_to; |
28 | size_t real_len = 0; |
29 | size_t *len = &real_len; |
30 | size_t reserve_size; |
31 | size_t slot_size; |
32 | size_t align; |
d4c8882b |
33 | const char *real_from; |
34 | const char **from = &real_from; |
abbd00d3 |
35 | u64 tsc; |
36 | size_t before_hdr_pad, after_hdr_pad, header_size; |
37 | |
d4c8882b |
38 | if (ltt_traces.num_active_traces == 0) |
39 | return; |
abbd00d3 |
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 | |
d4c8882b |
46 | *from = (const char*)<tng_param_value; |
abbd00d3 |
47 | align = sizeof(unsigned int); |
48 | |
d4c8882b |
49 | if (*len == 0) { |
abbd00d3 |
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(unsigned int); |
56 | |
abbd00d3 |
57 | reserve_size = *to_base + *to + *len; |
58 | preempt_disable(); |
59 | ltt_nesting[smp_processor_id()]++; |
d4c8882b |
60 | index = ltt_get_index_from_facility_tests( event_tests_write_4bytes); |
abbd00d3 |
61 | |
62 | list_for_each_entry_rcu(trace, <t_traces.head, list) { |
d4c8882b |
63 | if (!trace->active) |
64 | continue; |
abbd00d3 |
65 | |
66 | channel = ltt_get_channel_from_index(trace, index); |
abbd00d3 |
67 | |
68 | slot_size = 0; |
d4c8882b |
69 | buffer = ltt_reserve_slot(trace, channel, &transport_data, |
abbd00d3 |
70 | reserve_size, &slot_size, &tsc, |
71 | &before_hdr_pad, &after_hdr_pad, &header_size); |
d4c8882b |
72 | if (!buffer) |
73 | continue; /* buffer full */ |
abbd00d3 |
74 | |
75 | *to_base = *to = *len = 0; |
76 | |
77 | ltt_write_event_header(trace, channel, buffer, |
d4c8882b |
78 | ltt_facility_tests_CA7F1536, event_tests_write_4bytes, |
abbd00d3 |
79 | reserve_size, before_hdr_pad, tsc); |
80 | *to_base += before_hdr_pad + after_hdr_pad + header_size; |
81 | |
d4c8882b |
82 | *from = (const char*)<tng_param_value; |
83 | align = sizeof(unsigned int); |
abbd00d3 |
84 | |
d4c8882b |
85 | if (*len == 0) { |
abbd00d3 |
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 | |
d4c8882b |
91 | *len += sizeof(unsigned int); |
abbd00d3 |
92 | |
93 | /* Flush pending memcpy */ |
d4c8882b |
94 | if (*len != 0) { |
abbd00d3 |
95 | memcpy(buffer+*to_base+*to, *from, *len); |
96 | *to += *len; |
97 | *len = 0; |
98 | } |
99 | |
d4c8882b |
100 | ltt_commit_slot(channel, &transport_data, buffer, slot_size); |
abbd00d3 |
101 | |
102 | } |
103 | |
104 | ltt_nesting[smp_processor_id()]--; |
105 | preempt_enable_no_resched(); |
106 | } |
abbd00d3 |
107 | |
108 | #endif //_LTT_FACILITY_TESTS_H_ |