1 #ifndef LINUX_POWERPC_PERF_REQ_GEN_PERF_H_
2 #define LINUX_POWERPC_PERF_REQ_GEN_PERF_H_
4 #include <linux/perf_event.h>
7 #error "REQUEST_FILE must be defined before including"
11 #error "NAME_LOWER must be defined before including"
15 #error "NAME_UPPER must be defined before including"
18 #define BE_TYPE_b1 __u8
19 #define BE_TYPE_b2 __be16
20 #define BE_TYPE_b4 __be32
21 #define BE_TYPE_b8 __be64
23 #define BYTES_TO_BE_TYPE(bytes) \
26 #define CAT2_(a, b) a ## b
27 #define CAT2(a, b) CAT2_(a, b)
28 #define CAT3_(a, b, c) a ## b ## c
29 #define CAT3(a, b, c) CAT3_(a, b, c)
32 * enumerate the request values as
33 * <NAME_UPPER>_<request name> = <request value>
35 #define REQUEST_VALUE__(name_upper, r_name) name_upper ## _ ## r_name
36 #define REQUEST_VALUE_(name_upper, r_name) REQUEST_VALUE__(name_upper, r_name)
37 #define REQUEST_VALUE(r_name) REQUEST_VALUE_(NAME_UPPER, r_name)
40 #define REQUEST_(r_name, r_value, r_idx_1, r_fields) \
41 REQUEST_VALUE(r_name) = r_value,
42 enum CAT2(NAME_LOWER
, _requests
) {
48 * struct <NAME_LOWER>_<request name> {
53 #define STRUCT_NAME__(name_lower, r_name) name_lower ## _ ## r_name
54 #define STRUCT_NAME_(name_lower, r_name) STRUCT_NAME__(name_lower, r_name)
55 #define STRUCT_NAME(r_name) STRUCT_NAME_(NAME_LOWER, r_name)
56 #define REQUEST_(r_name, r_value, r_idx_1, r_fields) \
57 struct STRUCT_NAME(r_name) { \
60 #define __field_(r_name, r_value, r_idx_1, f_offset, f_bytes, f_name) \
61 BYTES_TO_BE_TYPE(f_bytes) f_name;
62 #define __count_(r_name, r_value, r_idx_1, f_offset, f_bytes, f_name) \
63 __field_(r_name, r_value, r_idx_1, f_offset, f_bytes, f_name)
64 #define __array_(r_name, r_value, r_idx_1, a_offset, a_bytes, a_name) \
70 * Generate a check of the field offsets
71 * <NAME_LOWER>_assert_offsets_correct()
74 #define REQUEST_(r_name, r_value, index, r_fields) \
76 #define __field_(r_name, r_value, r_idx_1, f_offset, f_size, f_name) \
77 BUILD_BUG_ON(offsetof(struct STRUCT_NAME(r_name), f_name) != f_offset);
78 #define __count_(r_name, r_value, r_idx_1, c_offset, c_size, c_name) \
79 __field_(r_name, r_value, r_idx_1, c_offset, c_size, c_name)
80 #define __array_(r_name, r_value, r_idx_1, a_offset, a_size, a_name) \
81 __field_(r_name, r_value, r_idx_1, a_offset, a_size, a_name)
83 static inline void CAT2(NAME_LOWER
, _assert_offsets_correct
)(void)
89 * Generate event attributes:
90 * PMU_EVENT_ATTR_STRING(<request name>_<field name>,
91 * <NAME_LOWER>_event_attr_<request name>_<field name>,
92 * "request=<request value>"
93 * "starting_index=<starting index type>"
94 * "counter_info_version=CURRENT_COUNTER_INFO_VERSION"
96 * "offset=<f_offset>")
98 * TODO: counter_info_version may need to vary, we should interperate the
99 * value to some extent
101 #define EVENT_ATTR_NAME__(name, r_name, c_name) \
102 name ## _event_attr_ ## r_name ## _ ## c_name
103 #define EVENT_ATTR_NAME_(name, r_name, c_name) \
104 EVENT_ATTR_NAME__(name, r_name, c_name)
105 #define EVENT_ATTR_NAME(r_name, c_name) \
106 EVENT_ATTR_NAME_(NAME_LOWER, r_name, c_name)
109 #define __field_(r_name, r_value, r_idx_1, f_offset, f_size, f_name)
110 #define __array_(r_name, r_value, r_idx_1, a_offset, a_size, a_name)
111 #define __count_(r_name, r_value, r_idx_1, c_offset, c_size, c_name) \
112 PMU_EVENT_ATTR_STRING( \
113 CAT3(r_name, _, c_name), \
114 EVENT_ATTR_NAME(r_name, c_name), \
115 "request=" __stringify(r_value) "," \
117 "counter_info_version=" \
118 __stringify(COUNTER_INFO_VERSION_CURRENT) "," \
119 "length=" #c_size "," \
121 #define REQUEST_(r_name, r_value, r_idx_1, r_fields) \
124 #include REQUEST_FILE
127 * Define event attribute array
128 * static struct attribute *hv_gpci_event_attrs[] = {
129 * &<NAME_LOWER>_event_attr_<request name>_<field name>.attr,
133 #define __field_(r_name, r_value, r_idx_1, f_offset, f_size, f_name)
134 #define __count_(r_name, r_value, r_idx_1, c_offset, c_size, c_name) \
135 &EVENT_ATTR_NAME(r_name, c_name).attr.attr,
136 #define __array_(r_name, r_value, r_idx_1, a_offset, a_size, a_name)
137 #define REQUEST_(r_name, r_value, r_idx_1, r_fields) \
140 static __maybe_unused
struct attribute
*hv_gpci_event_attrs
[] = {
141 #include REQUEST_FILE
147 #undef EVENT_ATTR_NAME
148 #undef EVENT_ATTR_NAME_
153 #undef REQUEST_VALUE_