--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 1 definitions for creating trace events */
+
+ #undef __field
+ #define __field(type, item) type item;
+
+ #undef __field_ext
+ #define __field_ext(type, item, filter_type) type item;
+
+ #undef __field_struct
+ #define __field_struct(type, item) type item;
+
+ #undef __field_struct_ext
+ #define __field_struct_ext(type, item, filter_type) type item;
+
+ #undef __array
+ #define __array(type, item, len) type item[len];
+
+ #undef __dynamic_array
+ #define __dynamic_array(type, item, len) u32 __data_loc_##item;
+
+ #undef __string
+ #define __string(item, src) __dynamic_array(char, item, -1)
+
+ #undef __string_len
+ #define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
+ #undef __bitmask
+ #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
+
++#undef __sockaddr
++#define __sockaddr(field, len) __dynamic_array(u8, field, len)
++
+ #undef __rel_dynamic_array
+ #define __rel_dynamic_array(type, item, len) u32 __rel_loc_##item;
+
+ #undef __rel_string
+ #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_string_len
+ #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_bitmask
+ #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1)
+
++#undef __rel_sockaddr
++#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
++
+ #undef TP_STRUCT__entry
+ #define TP_STRUCT__entry(args...) args
--- /dev/null
-#undef __string_len
-#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 2 definitions for creating trace events */
+
+ #undef TRACE_DEFINE_ENUM
+ #define TRACE_DEFINE_ENUM(a)
+
+ #undef TRACE_DEFINE_SIZEOF
+ #define TRACE_DEFINE_SIZEOF(a)
+
+ #undef __field
+ #define __field(type, item)
+
+ #undef __field_ext
+ #define __field_ext(type, item, filter_type)
+
+ #undef __field_struct
+ #define __field_struct(type, item)
+
+ #undef __field_struct_ext
+ #define __field_struct_ext(type, item, filter_type)
+
+ #undef __array
+ #define __array(type, item, len)
+
+ #undef __dynamic_array
+ #define __dynamic_array(type, item, len) u32 item;
+
+ #undef __string
+ #define __string(item, src) __dynamic_array(char, item, -1)
+
++#undef __string_len
++#define __string_len(item, src, len) __dynamic_array(char, item, -1)
++
+ #undef __bitmask
+ #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
+
++#undef __sockaddr
++#define __sockaddr(field, len) __dynamic_array(u8, field, len)
+
+ #undef __rel_dynamic_array
+ #define __rel_dynamic_array(type, item, len) u32 item;
+
+ #undef __rel_string
+ #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_string_len
+ #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_bitmask
+ #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
++
++#undef __rel_sockaddr
++#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 3 definitions for creating trace events */
+
+ #undef __entry
+ #define __entry field
+
+ #undef TP_printk
+ #define TP_printk(fmt, args...) fmt "\n", args
+
+ #undef __get_dynamic_array
+ #define __get_dynamic_array(field) \
+ ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
+
+ #undef __get_dynamic_array_len
+ #define __get_dynamic_array_len(field) \
+ ((__entry->__data_loc_##field >> 16) & 0xffff)
+
+ #undef __get_str
+ #define __get_str(field) ((char *)__get_dynamic_array(field))
+
+ #undef __get_rel_dynamic_array
+ #define __get_rel_dynamic_array(field) \
+ ((void *)__entry + \
+ offsetof(typeof(*__entry), __rel_loc_##field) + \
+ sizeof(__entry->__rel_loc_##field) + \
+ (__entry->__rel_loc_##field & 0xffff))
+
+ #undef __get_rel_dynamic_array_len
+ #define __get_rel_dynamic_array_len(field) \
+ ((__entry->__rel_loc_##field >> 16) & 0xffff)
+
+ #undef __get_rel_str
+ #define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
+
+ #undef __get_bitmask
+ #define __get_bitmask(field) \
+ ({ \
+ void *__bitmask = __get_dynamic_array(field); \
+ unsigned int __bitmask_size; \
+ __bitmask_size = __get_dynamic_array_len(field); \
+ trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
+ })
+
+ #undef __get_rel_bitmask
+ #define __get_rel_bitmask(field) \
+ ({ \
+ void *__bitmask = __get_rel_dynamic_array(field); \
+ unsigned int __bitmask_size; \
+ __bitmask_size = __get_rel_dynamic_array_len(field); \
+ trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
+ })
+
++#undef __get_sockaddr
++#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
++
++#undef __get_rel_sockaddr
++#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
++
+ #undef __print_flags
+ #define __print_flags(flag, delim, flag_array...) \
+ ({ \
+ static const struct trace_print_flags __flags[] = \
+ { flag_array, { -1, NULL }}; \
+ trace_print_flags_seq(p, delim, flag, __flags); \
+ })
+
+ #undef __print_symbolic
+ #define __print_symbolic(value, symbol_array...) \
+ ({ \
+ static const struct trace_print_flags symbols[] = \
+ { symbol_array, { -1, NULL }}; \
+ trace_print_symbols_seq(p, value, symbols); \
+ })
+
+ #undef __print_flags_u64
+ #undef __print_symbolic_u64
+ #if BITS_PER_LONG == 32
+ #define __print_flags_u64(flag, delim, flag_array...) \
+ ({ \
+ static const struct trace_print_flags_u64 __flags[] = \
+ { flag_array, { -1, NULL } }; \
+ trace_print_flags_seq_u64(p, delim, flag, __flags); \
+ })
+
+ #define __print_symbolic_u64(value, symbol_array...) \
+ ({ \
+ static const struct trace_print_flags_u64 symbols[] = \
+ { symbol_array, { -1, NULL } }; \
+ trace_print_symbols_seq_u64(p, value, symbols); \
+ })
+ #else
+ #define __print_flags_u64(flag, delim, flag_array...) \
+ __print_flags(flag, delim, flag_array)
+
+ #define __print_symbolic_u64(value, symbol_array...) \
+ __print_symbolic(value, symbol_array)
+ #endif
+
+ #undef __print_hex
+ #define __print_hex(buf, buf_len) \
+ trace_print_hex_seq(p, buf, buf_len, false)
+
+ #undef __print_hex_str
+ #define __print_hex_str(buf, buf_len) \
+ trace_print_hex_seq(p, buf, buf_len, true)
+
+ #undef __print_array
+ #define __print_array(array, count, el_size) \
+ ({ \
+ BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
+ el_size != 4 && el_size != 8); \
+ trace_print_array_seq(p, array, count, el_size); \
+ })
+
+ #undef __print_hex_dump
+ #define __print_hex_dump(prefix_str, prefix_type, \
+ rowsize, groupsize, buf, len, ascii) \
+ trace_print_hex_dump_seq(p, prefix_str, prefix_type, \
+ rowsize, groupsize, buf, len, ascii)
+
+ #undef __print_ns_to_secs
+ #define __print_ns_to_secs(value) \
+ ({ \
+ u64 ____val = (u64)(value); \
+ do_div(____val, NSEC_PER_SEC); \
+ ____val; \
+ })
+
+ #undef __print_ns_without_secs
+ #define __print_ns_without_secs(value) \
+ ({ \
+ u64 ____val = (u64)(value); \
+ (u32) do_div(____val, NSEC_PER_SEC); \
+ })
--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 4 definitions for creating trace events */
+
+ #undef __field_ext
+ #define __field_ext(_type, _item, _filter_type) { \
+ .type = #_type, .name = #_item, \
+ .size = sizeof(_type), .align = __alignof__(_type), \
+ .is_signed = is_signed_type(_type), .filter_type = _filter_type },
+
+ #undef __field_struct_ext
+ #define __field_struct_ext(_type, _item, _filter_type) { \
+ .type = #_type, .name = #_item, \
+ .size = sizeof(_type), .align = __alignof__(_type), \
+ 0, .filter_type = _filter_type },
+
+ #undef __field
+ #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
+
+ #undef __field_struct
+ #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
+
+ #undef __array
+ #define __array(_type, _item, _len) { \
+ .type = #_type"["__stringify(_len)"]", .name = #_item, \
+ .size = sizeof(_type[_len]), .align = __alignof__(_type), \
+ .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
+
+ #undef __dynamic_array
+ #define __dynamic_array(_type, _item, _len) { \
+ .type = "__data_loc " #_type "[]", .name = #_item, \
+ .size = 4, .align = 4, \
+ .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
+
+ #undef __string
+ #define __string(item, src) __dynamic_array(char, item, -1)
+
+ #undef __string_len
+ #define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
+ #undef __bitmask
+ #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
+
++#undef __sockaddr
++#define __sockaddr(field, len) __dynamic_array(u8, field, len)
++
+ #undef __rel_dynamic_array
+ #define __rel_dynamic_array(_type, _item, _len) { \
+ .type = "__rel_loc " #_type "[]", .name = #_item, \
+ .size = 4, .align = 4, \
+ .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
+
+ #undef __rel_string
+ #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_string_len
+ #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_bitmask
+ #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
++
++#undef __rel_sockaddr
++#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 5 definitions for creating trace events */
+
+ /*
+ * remember the offset of each array from the beginning of the event.
+ */
+
+ #undef __entry
+ #define __entry entry
+
+ #undef __field
+ #define __field(type, item)
+
+ #undef __field_ext
+ #define __field_ext(type, item, filter_type)
+
+ #undef __field_struct
+ #define __field_struct(type, item)
+
+ #undef __field_struct_ext
+ #define __field_struct_ext(type, item, filter_type)
+
+ #undef __array
+ #define __array(type, item, len)
+
+ #undef __dynamic_array
+ #define __dynamic_array(type, item, len) \
+ __item_length = (len) * sizeof(type); \
+ __data_offsets->item = __data_size + \
+ offsetof(typeof(*entry), __data); \
+ __data_offsets->item |= __item_length << 16; \
+ __data_size += __item_length;
+
+ #undef __string
+ #define __string(item, src) __dynamic_array(char, item, \
+ strlen((src) ? (const char *)(src) : "(null)") + 1)
+
+ #undef __string_len
+ #define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
+
+ #undef __rel_dynamic_array
+ #define __rel_dynamic_array(type, item, len) \
+ __item_length = (len) * sizeof(type); \
+ __data_offsets->item = __data_size + \
+ offsetof(typeof(*entry), __data) - \
+ offsetof(typeof(*entry), __rel_loc_##item) - \
+ sizeof(u32); \
+ __data_offsets->item |= __item_length << 16; \
+ __data_size += __item_length;
+
+ #undef __rel_string
+ #define __rel_string(item, src) __rel_dynamic_array(char, item, \
+ strlen((src) ? (const char *)(src) : "(null)") + 1)
+
+ #undef __rel_string_len
+ #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
+ /*
+ * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
+ * num_possible_cpus().
+ */
+ #define __bitmask_size_in_bytes_raw(nr_bits) \
+ (((nr_bits) + 7) / 8)
+
+ #define __bitmask_size_in_longs(nr_bits) \
+ ((__bitmask_size_in_bytes_raw(nr_bits) + \
+ ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
+
+ /*
+ * __bitmask_size_in_bytes is the number of bytes needed to hold
+ * num_possible_cpus() padded out to the nearest long. This is what
+ * is saved in the buffer, just to be consistent.
+ */
+ #define __bitmask_size_in_bytes(nr_bits) \
+ (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
+
+ #undef __bitmask
+ #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
+ __bitmask_size_in_longs(nr_bits))
+
+ #undef __rel_bitmask
+ #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \
+ __bitmask_size_in_longs(nr_bits))
++
++#undef __sockaddr
++#define __sockaddr(field, len) __dynamic_array(u8, field, len)
++
++#undef __rel_sockaddr
++#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 6 definitions for creating trace events */
+
+ #undef __entry
+ #define __entry entry
+
+ #undef __field
+ #define __field(type, item)
+
+ #undef __field_struct
+ #define __field_struct(type, item)
+
+ #undef __array
+ #define __array(type, item, len)
+
+ #undef __dynamic_array
+ #define __dynamic_array(type, item, len) \
+ __entry->__data_loc_##item = __data_offsets.item;
+
+ #undef __string
+ #define __string(item, src) __dynamic_array(char, item, -1)
+
+ #undef __string_len
+ #define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
+ #undef __assign_str
+ #define __assign_str(dst, src) \
+ strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
+
+ #undef __assign_str_len
+ #define __assign_str_len(dst, src, len) \
+ do { \
+ memcpy(__get_str(dst), (src), (len)); \
+ __get_str(dst)[len] = '\0'; \
+ } while(0)
+
+ #undef __bitmask
+ #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
+
+ #undef __get_bitmask
+ #define __get_bitmask(field) (char *)__get_dynamic_array(field)
+
+ #undef __assign_bitmask
+ #define __assign_bitmask(dst, src, nr_bits) \
+ memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
+
++#undef __sockaddr
++#define __sockaddr(field, len) __dynamic_array(u8, field, len)
++
++#undef __get_sockaddr
++#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
++
++#undef __assign_sockaddr
++#define __assign_sockaddr(dest, src, len) \
++ memcpy(__get_dynamic_array(dest), src, len)
++
+ #undef __rel_dynamic_array
+ #define __rel_dynamic_array(type, item, len) \
+ __entry->__rel_loc_##item = __data_offsets.item;
+
+ #undef __rel_string
+ #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
+
+ #undef __rel_string_len
+ #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
+
+ #undef __assign_rel_str
+ #define __assign_rel_str(dst, src) \
+ strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
+
+ #undef __assign_rel_str_len
+ #define __assign_rel_str_len(dst, src, len) \
+ do { \
+ memcpy(__get_rel_str(dst), (src), (len)); \
+ __get_rel_str(dst)[len] = '\0'; \
+ } while (0)
+
+ #undef __rel_bitmask
+ #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
+
+ #undef __get_rel_bitmask
+ #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
+
+ #undef __assign_rel_bitmask
+ #define __assign_rel_bitmask(dst, src, nr_bits) \
+ memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
+
++#undef __rel_sockaddr
++#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
++
++#undef __get_rel_sockaddr
++#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
++
++#undef __assign_rel_sockaddr
++#define __assign_rel_sockaddr(dest, src, len) \
++ memcpy(__get_rel_dynamic_array(dest), src, len)
++
+ #undef TP_fast_assign
+ #define TP_fast_assign(args...) args
+
+ #undef __perf_count
+ #define __perf_count(c) (c)
+
+ #undef __perf_task
+ #define __perf_task(t) (t)
--- /dev/null
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /* Stage 7 definitions for creating trace events */
+
+ #undef __entry
+ #define __entry REC
+
+ #undef __print_flags
+ #undef __print_symbolic
+ #undef __print_hex
+ #undef __print_hex_str
+ #undef __get_dynamic_array
+ #undef __get_dynamic_array_len
+ #undef __get_str
+ #undef __get_bitmask
++#undef __get_sockaddr
+ #undef __get_rel_dynamic_array
+ #undef __get_rel_dynamic_array_len
+ #undef __get_rel_str
+ #undef __get_rel_bitmask
++#undef __get_rel_sockaddr
+ #undef __print_array
+ #undef __print_hex_dump
+
+ /*
+ * The below is not executed in the kernel. It is only what is
+ * displayed in the print format for userspace to parse.
+ */
+ #undef __print_ns_to_secs
+ #define __print_ns_to_secs(val) (val) / 1000000000UL
+
+ #undef __print_ns_without_secs
+ #define __print_ns_without_secs(val) (val) % 1000000000UL
+
+ #undef TP_printk
+ #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
--- /dev/null
- TP_ARGS(preempt, prev, next),
+ /* SPDX-License-Identifier: GPL-2.0 */
+
+ /*
+ * Like the headers that use TRACE_EVENT(), the TRACE_CUSTOM_EVENT()
+ * needs a header that allows for multiple inclusions.
+ *
+ * Test for a unique name (here we have _TRACE_CUSTOM_SCHED_H),
+ * also allowing to continue if TRACE_CUSTOM_MULTI_READ is defined.
+ */
+ #if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ)
+ #define _TRACE_CUSTOM_SCHED_H
+
+ /* Include linux/trace_events.h for initial defines of TRACE_CUSTOM_EVENT() */
+ #include <linux/trace_events.h>
+
+ /*
+ * TRACE_CUSTOM_EVENT() is just like TRACE_EVENT(). The first parameter
+ * is the event name of an existing event where the TRACE_EVENT has been included
+ * in the C file before including this file.
+ */
+ TRACE_CUSTOM_EVENT(sched_switch,
+
+ /*
+ * The TP_PROTO() and TP_ARGS must match the trace event
+ * that the custom event is using.
+ */
+ TP_PROTO(bool preempt,
++ unsigned int prev_state,
+ struct task_struct *prev,
+ struct task_struct *next),
+
++ TP_ARGS(preempt, prev_state, prev, next),
+
+ /*
+ * The next fields are where the customization happens.
+ * The TP_STRUCT__entry() defines what will be recorded
+ * in the ring buffer when the custom event triggers.
+ *
+ * The rest is just like the TRACE_EVENT() macro except that
+ * it uses the custom entry.
+ */
+ TP_STRUCT__entry(
+ __field( unsigned short, prev_prio )
+ __field( unsigned short, next_prio )
+ __field( pid_t, next_pid )
+ ),
+
+ TP_fast_assign(
+ __entry->prev_prio = prev->prio;
+ __entry->next_pid = next->pid;
+ __entry->next_prio = next->prio;
+ ),
+
+ TP_printk("prev_prio=%d next_pid=%d next_prio=%d",
+ __entry->prev_prio, __entry->next_pid, __entry->next_prio)
+ )
+
+
+ TRACE_CUSTOM_EVENT(sched_waking,
+
+ TP_PROTO(struct task_struct *p),
+
+ TP_ARGS(p),
+
+ TP_STRUCT__entry(
+ __field( pid_t, pid )
+ __field( unsigned short, prio )
+ ),
+
+ TP_fast_assign(
+ __entry->pid = p->pid;
+ __entry->prio = p->prio;
+ ),
+
+ TP_printk("pid=%d prio=%d", __entry->pid, __entry->prio)
+ )
+ #endif
+ /*
+ * Just like the headers that create TRACE_EVENTs, the below must
+ * be outside the protection of the above #if block.
+ */
+
+ /*
+ * It is required that the Makefile includes:
+ * CFLAGS_<c_file>.o := -I$(src)
+ */
+ #undef TRACE_INCLUDE_PATH
+ #undef TRACE_INCLUDE_FILE
+ #define TRACE_INCLUDE_PATH .
+
+ /*
+ * It is requred that the TRACE_INCLUDE_FILE be the same
+ * as this file without the ".h".
+ */
+ #define TRACE_INCLUDE_FILE trace_custom_sched
+ #include <trace/define_custom_trace.h>