From: Francis Deslauriers Date: Wed, 5 May 2021 15:51:31 +0000 (-0400) Subject: Group all syscall enums in one compile unit X-Git-Tag: v2.13.0-rc2~33 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=16e1064f1216e90e49ac61752d24df5218d9962e;p=lttng-modules.git Group all syscall enums in one compile unit Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: Ic0189984d9bc70ae3f76af08bffd127500adad80 --- diff --git a/include/instrumentation/syscalls/headers/syscalls_pointers_override.h b/include/instrumentation/syscalls/headers/syscalls_pointers_override.h index cbd226aa..000756db 100644 --- a/include/instrumentation/syscalls/headers/syscalls_pointers_override.h +++ b/include/instrumentation/syscalls/headers/syscalls_pointers_override.h @@ -457,6 +457,7 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6, ) #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */ +#ifdef LTTNG_CREATE_FIELD_METADATA #ifndef ONCE_LTTNG_TRACE_POLL_H #define ONCE_LTTNG_TRACE_POLL_H @@ -464,6 +465,7 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6, #define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \ ilog2(LTTNG_POLL_NRFLAGS - 1) +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN /* * Only extract the values specified by iBCS2 for now. */ @@ -491,18 +493,30 @@ static const struct lttng_kernel_event_field *lttng_pollfd_flag_fields[] = { false, false, false), }; +static_assert(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) + POLL_FLAGS_PADDING_SIZE) == sizeof(uint8_t) * BITS_PER_BYTE); + +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ + +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_pollfd_flag_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init( ARRAY_SIZE(lttng_pollfd_flag_fields), lttng_pollfd_flag_fields, 0))) + +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN static const struct lttng_kernel_event_field *lttng_pollfd_fields[] = { [0] = lttng_kernel_static_event_field("fd", lttng_kernel_static_type_integer_from_type(int, __BYTE_ORDER, 10), false, false, false), [1] = lttng_kernel_static_event_field("raw_events", lttng_kernel_static_type_integer_from_type(uint16_t, __BYTE_ORDER, 16), false, false, false), [2] = lttng_kernel_static_event_field("events", - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_pollfd_flag_fields), - lttng_pollfd_flag_fields, 0), + (const struct lttng_kernel_type_common *) <tng_pollfd_flag_fields_struct, false, false, false), }; +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ + +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_pollfd_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init(ARRAY_SIZE(lttng_pollfd_fields), lttng_pollfd_fields, 0))) #endif /* ONCE_LTTNG_TRACE_POLL_H */ +#endif /* LTTNG_CREATE_FIELD_METADATA */ #define LTTNG_SYSCALL_POLL_locvar \ unsigned int fds_length, fds_max_len, alloc_fds; \ @@ -510,9 +524,6 @@ static const struct lttng_kernel_event_field *lttng_pollfd_fields[] = { uint8_t overflow; #define LTTNG_SYSCALL_POLL_code_pre \ - BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) + \ - POLL_FLAGS_PADDING_SIZE) != \ - sizeof(uint8_t) * BITS_PER_BYTE); \ tp_locvar->fds = NULL; \ tp_locvar->overflow = 0; \ \ @@ -570,7 +581,7 @@ end: \ ctf_custom_field( \ ctf_custom_type( \ lttng_kernel_static_type_sequence("fds_length", \ - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_pollfd_fields), lttng_pollfd_fields, 0), \ + (const struct lttng_kernel_type_common *) <tng_pollfd_fields_struct, \ 0, \ none) \ ), \ @@ -592,7 +603,7 @@ end: \ ctf_custom_field( \ ctf_custom_type( \ lttng_kernel_static_type_sequence("fds_length", \ - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_pollfd_fields), lttng_pollfd_fields, 0), \ + (const struct lttng_kernel_type_common *) <tng_pollfd_fields_struct, \ 0, \ none) \ ), \ @@ -699,6 +710,8 @@ SC_LTTNG_TRACEPOINT_ENUM(lttng_epoll_op, ) ) +#ifdef LTTNG_CREATE_FIELD_METADATA + #ifndef ONCE_LTTNG_TRACE_EPOLL_CTL_H #define ONCE_LTTNG_TRACE_EPOLL_CTL_H @@ -706,6 +719,7 @@ SC_LTTNG_TRACEPOINT_ENUM(lttng_epoll_op, #define EPOLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \ ilog2(LTTNG_EPOLL_NRFLAGS - 1) +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN /* * Only extract the values specified by iBCS2 for now. */ @@ -734,7 +748,12 @@ static const struct lttng_kernel_event_field *lttng_epoll_ctl_events_fields[] = lttng_kernel_static_type_integer(EPOLL_FLAGS_PADDING_SIZE, 1, 0, __LITTLE_ENDIAN, 10), false, false, false), }; +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ + +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_epoll_ctl_events_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init(ARRAY_SIZE(lttng_epoll_ctl_events_fields), lttng_epoll_ctl_events_fields, 0))) +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN static const struct lttng_kernel_event_field *lttng_epoll_data_fields[] = { [0] = lttng_kernel_static_event_field("u64", lttng_kernel_static_type_integer_from_type(uint64_t, __BYTE_ORDER, 16), @@ -743,23 +762,30 @@ static const struct lttng_kernel_event_field *lttng_epoll_data_fields[] = { lttng_kernel_static_type_integer_from_type(int, __BYTE_ORDER, 10), false, false, false), }; +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_epoll_data_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init(ARRAY_SIZE(lttng_epoll_data_fields), lttng_epoll_data_fields, 0))) + +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN static const struct lttng_kernel_event_field *epoll_ctl_fields[] = { [0] = lttng_kernel_static_event_field("data_union", - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_epoll_data_fields), - lttng_epoll_data_fields, - 0), + (const struct lttng_kernel_type_common *) <tng_epoll_data_fields_struct, false, false, false), [1] = lttng_kernel_static_event_field("raw_events", lttng_kernel_static_type_integer_from_type(uint32_t, __BYTE_ORDER, 16), false, false, false), [2] = lttng_kernel_static_event_field("events", - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_epoll_ctl_events_fields), - lttng_epoll_ctl_events_fields, - 0), + (const struct lttng_kernel_type_common *) <tng_epoll_ctl_events_fields_struct, false, false, false), }; +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ + +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct epoll_ctl_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init(ARRAY_SIZE(epoll_ctl_fields), epoll_ctl_fields, 0))) + #endif /* ONCE_LTTNG_TRACE_EPOLL_CTL_H */ +#endif /* LTTNG_CREATE_FIELD_METADATA */ #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) #define OVERRIDE_32_epoll_ctl @@ -810,21 +836,31 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl, ) #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */ +#ifdef LTTNG_CREATE_FIELD_METADATA #ifndef ONCE_LTTNG_TRACE_EPOLL_H #define ONCE_LTTNG_TRACE_EPOLL_H +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN static const struct lttng_kernel_event_field *lttng_epoll_wait_fields[] = lttng_kernel_static_event_field_array( [0] = lttng_kernel_static_event_field("data_union", - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_epoll_data_fields), lttng_epoll_data_fields, 0), + (const struct lttng_kernel_type_common *) <tng_epoll_data_fields_struct, false, false, false), [1] = lttng_kernel_static_event_field("raw_events", lttng_kernel_static_type_integer_from_type(uint32_t, __BYTE_ORDER, 16), false, false, false), [2] = lttng_kernel_static_event_field("events", - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_epoll_ctl_events_fields), lttng_epoll_ctl_events_fields, 0), + (const struct lttng_kernel_type_common *) <tng_epoll_ctl_events_fields_struct, false, false, false), ); +static_assert(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) + EPOLL_FLAGS_PADDING_SIZE) == sizeof(uint8_t) * BITS_PER_BYTE); + +#endif /* LTTNG_TRACEPOINT_TYPE_EXTERN */ + +LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_epoll_wait_fields_struct), + PARAMS(lttng_kernel_static_type_struct_init(ARRAY_SIZE(lttng_epoll_wait_fields), lttng_epoll_wait_fields, 0))) + #endif /* ONCE_LTTNG_TRACE_EPOLL_H */ +#endif /* LTTNG_CREATE_FIELD_METADATA */ #define LTTNG_SYSCALL_EPOLL_WAIT_locvar \ sc_out( \ @@ -834,9 +870,6 @@ static const struct lttng_kernel_event_field *lttng_epoll_wait_fields[] = lttng_ ) #define LTTNG_SYSCALL_EPOLL_WAIT_code_pre \ - BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) + \ - EPOLL_FLAGS_PADDING_SIZE) != \ - sizeof(uint8_t) * BITS_PER_BYTE); \ sc_out({ \ int err; \ unsigned long maxalloc; \ diff --git a/include/lttng/events-reset.h b/include/lttng/events-reset.h index 31c828dc..c4a43787 100644 --- a/include/lttng/events-reset.h +++ b/include/lttng/events-reset.h @@ -22,6 +22,9 @@ #undef LTTNG_TRACEPOINT_ENUM #define LTTNG_TRACEPOINT_ENUM(_name, _values) +#undef LTTNG_TRACEPOINT_TYPE +#define LTTNG_TRACEPOINT_TYPE(_prototype, _init) + #undef TP_PROTO #define TP_PROTO(args...) diff --git a/include/lttng/events.h b/include/lttng/events.h index b7267cd5..a04d0f2a 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -142,6 +142,10 @@ struct lttng_kernel_event_field { nofilter:1; /* do not consider for filter */ }; +#ifndef PARAMS +#define PARAMS(args...) args +#endif + #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \ ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \ .parent = { \ @@ -207,15 +211,20 @@ struct lttng_kernel_event_field { .encoding = lttng_kernel_string_encoding_##_encoding, \ })) -#define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \ - ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \ +#define lttng_kernel_static_type_struct_init(_nr_fields, _fields, _alignment) \ + { \ .parent = { \ .type = lttng_kernel_type_struct, \ }, \ .nr_fields = (_nr_fields), \ .fields = _fields, \ .alignment = (_alignment), \ - })) + } + +#define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \ + ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, \ + lttng_kernel_static_type_struct_init(_nr_fields, PARAMS(_fields), _alignment) \ + )) #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \ ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \ diff --git a/include/lttng/tracepoint-event-impl.h b/include/lttng/tracepoint-event-impl.h index 4df71ff2..32ecf29d 100644 --- a/include/lttng/tracepoint-event-impl.h +++ b/include/lttng/tracepoint-event-impl.h @@ -198,11 +198,13 @@ void __event_template_proto___##_name(void); #define TP_ENUM_VALUES(...) \ __VA_ARGS__ -#undef LTTNG_TRACEPOINT_ENUM -#define LTTNG_TRACEPOINT_ENUM(_name, _values) \ +#ifndef LTTNG_TRACEPOINT_TYPE_EXTERN +# undef LTTNG_TRACEPOINT_ENUM +# define LTTNG_TRACEPOINT_ENUM(_name, _values) \ static const struct lttng_kernel_enum_entry *__enum_values__##_name[] = { \ _values \ }; +#endif #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) @@ -307,18 +309,37 @@ void __event_template_proto___##_name(void); #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post) -#undef LTTNG_TRACEPOINT_ENUM -#define LTTNG_TRACEPOINT_ENUM(_name, _values) \ - static const struct lttng_kernel_enum_desc __enum_##_name = { \ - .name = #_name, \ - .entries = __enum_values__##_name, \ - .nr_entries = ARRAY_SIZE(__enum_values__##_name), \ - }; +#ifdef LTTNG_TRACEPOINT_TYPE_EXTERN +# undef LTTNG_TRACEPOINT_TYPE +# define LTTNG_TRACEPOINT_TYPE(_prototype, _init) \ + extern _prototype; +#elif defined (LTTNG_TRACEPOINT_TYPE_DEFINE_EXPORT) +# define LTTNG_TRACEPOINT_TYPE_VISIBILITY __attribute__((visibility("hidden"))) +#else +# define LTTNG_TRACEPOINT_TYPE_VISIBILITY static +#endif + +#ifdef LTTNG_TRACEPOINT_TYPE_VISIBILITY +# undef LTTNG_TRACEPOINT_TYPE +# define LTTNG_TRACEPOINT_TYPE(_prototype, _init) \ + LTTNG_TRACEPOINT_TYPE_VISIBILITY _prototype = _init; +#endif + +# undef LTTNG_TRACEPOINT_ENUM +# define LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_enum_desc __enum_##_name), \ + PARAMS({ \ + .name = #_name, \ + .entries = __enum_values__##_name, \ + .nr_entries = ARRAY_SIZE(__enum_values__##_name), \ + })) #define LTTNG_CREATE_FIELD_METADATA #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #undef LTTNG_CREATE_FIELD_METADATA +#undef LTTNG_TRACEPOINT_TYPE_VISIBILITY + /* * Stage 3 of the trace events. * diff --git a/src/Kbuild b/src/Kbuild index a5a840a7..b03b4b93 100644 --- a/src/Kbuild +++ b/src/Kbuild @@ -90,6 +90,7 @@ lttng-wrapper-objs := wrapper/page_alloc.o \ ifneq ($(CONFIG_HAVE_SYSCALL_TRACEPOINTS),) lttng-tracer-objs += lttng-syscalls.o + lttng-tracer-objs += lttng-syscalls-enum.o endif # CONFIG_HAVE_SYSCALL_TRACEPOINTS ifneq ($(CONFIG_PERF_EVENTS),) diff --git a/src/lttng-syscalls-enum.c b/src/lttng-syscalls-enum.c new file mode 100644 index 00000000..1bb60b13 --- /dev/null +++ b/src/lttng-syscalls-enum.c @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls-enum.c + * + * LTTng syscall enum types + * + * Copyright (C) 2021 Mathieu Desnoyers + * Copyright (C) 2021 Francis Deslauriers + */ + +#include + +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TP_MODULE_NOINIT +#define TRACE_INCLUDE_PATH instrumentation/syscalls/headers + +#define PARAMS(args...) args + +#undef sc_exit +#define sc_exit(...) +#undef sc_in +#define sc_in(...) __VA_ARGS__ +#undef sc_out +#define sc_out(...) +#undef sc_inout +#define sc_inout(...) __VA_ARGS__ + +#define TP_PROBE_CB(_template) +#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) +#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) +#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) +#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) + +#define LTTNG_TRACEPOINT_TYPE_DEFINE_EXPORT + +#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_entry_integers +#define TRACE_INCLUDE_FILE syscalls_integers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_entry_pointers +#define TRACE_INCLUDE_FILE syscalls_pointers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#undef SC_LTTNG_TRACEPOINT_ENUM