Skip to contentSkip to conversation

libtracefs: Add APIs for user_events to libtracefs

PATCH In review Beau Belgrave 2 participants 7 messages Feb 22, 2022 – Feb 23, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover libtracefs: Add APIs for user_events to libtracefs

New APIs added:
struct tracefs_user_event_group *tracefs_user_event_group_open(void);

void tracefs_user_event_group_close(struct tracefs_user_event_group *group);

int tracefs_user_event_delete(const char *name);

struct tracefs_user_event *
tracefs_user_event_register(struct tracefs_user_event_group *group,
const char *name, enum tracefs_uevent_flags flags, struct tracefs_uevent_item *items);

bool tracefs_user_event_enabled(struct tracefs_user_event *event);

int tracefs_user_event_record(struct tracefs_user_event *event,

			      struct tracefs_uevent_item *items);

Documentation updates in this series describes the various APIs and the reason for a group.

Items are described with a struct to better ensure contracts for things like custom structs or static length strings. Items are allowed to be mixed/different than what they were when registered. This allows callers the ability to describe events verbosely, but write out via packed structs in their own code if needed.

V2:
Renamed tracefs_user_event_group_create() to tracefs_user_event_group_open() Renamed tracefs_user_event_test() to tracefs_user_event_enabled() Renamed tracefs_user_event_write() to tracefs_user_event_record() Updated documentation to new function names
Moved to trace_seq vs snprintf for register commands
Split struct tracefs_user_event into external and internal sides for inlining Changed tracefs_user_event_enabled to inline function
Fixed nits and whitespaces
Keep track of user view size to allow backward / forward compat if needed Couldn't get variadic helper macro to work well, not including it here for now

Beau Belgrave (3):
libtracefs: Add user_events to libtracefs sources
libtracefs: Add documentation and sample code for user_events
libtracefs: Add unit tests for user_events

 Documentation/libtracefs-userevents.txt | 260 ++++++++++++
 Makefile                                |   8 +
 include/tracefs-local.h                 |  24 ++
 include/tracefs.h                       |  67 +++
 samples/Makefile                        |   4 +
 src/Makefile                            |   4 +
 src/tracefs-userevents.c                | 516 ++++++++++++++++++++++++
 utest/tracefs-utest.c                   | 233 +++++++++++
 8 files changed, 1116 insertions(+)
 create mode 100644 Documentation/libtracefs-userevents.txt
 create mode 100644 src/tracefs-userevents.c

base-commit: e579ba38ff6bc07cd2278faf9d3ac08c15d4e9e8

Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 libtracefs: Add user_events to libtracefs sources

The user events are scheduled to be included into Linux 5.18, which register a special mmapped page to denote when the user event is enabled (from an external source). This API adds a wrapper to the kernel interface that makes it easy to register user events and test if they are enabled and to record the event when it is.

Link:
https://lore.kernel.org/linux-trace-devel/20220121192833.GA3128@kbox/T/#m2bcf53c373fbeaba2c46d1a053b3174171167e4e

---
 Makefile                 |   8 +
 include/tracefs-local.h  |  24 ++
 include/tracefs.h        |  67 +++++
 src/Makefile             |   4 +
 src/tracefs-userevents.c | 516 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 619 insertions(+)
 create mode 100644 src/tracefs-userevents.c
Makefile +8 -0
index 544684c..a4598b4 100644
@@ -154,6 +154,14 @@ CFLAGS ?= -g -Wall
 CPPFLAGS ?=
 LDFLAGS ?=
 
+USEREVENTS_INSTALLED := $(shell if (echo "$(pound)include <linux/user_events.h>" | $(CC) -E - >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi)
+export USEREVENTS_INSTALLED
+ifeq ($(USEREVENTS_INSTALLED), 1)
+CFLAGS += -DUSEREVENTS
+else
+$(warning user_events.h not installed, skipping)
+endif
+
 CUNIT_INSTALLED := $(shell if (printf "$(pound)include <CUnit/Basic.h>\n void main(){CU_initialize_registry();}" | $(CC) -x c - -lcunit -o /dev/null >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi)
 export CUNIT_INSTALLED
 
include/tracefs-local.h +24 -0
index bf157e1..9491545 100644
@@ -119,4 +119,28 @@ int trace_rescan_events(struct tep_handle *tep,
 struct tep_event *get_tep_event(struct tep_handle *tep,
 				const char *system, const char *name);
 
+/* Internal interface for ftrace user events */
+
+struct tracefs_user_event_group;
+
+struct tracefs_user_event_internal
+{
+	struct tracefs_user_event		event_external;
+	int					write_index;
+	int					iovecs;
+	int					rels;
+	int					len;
+	struct tracefs_user_event_group		*group;
+	struct tracefs_user_event_internal	*next;
+};
+
+struct tracefs_user_event_group
+{
+	int					fd;
+	int					mmap_len;
+	char					*mmap;
+	pthread_mutex_t				lock;
+	struct tracefs_user_event_internal	*events;
+};
+
 #endif /* _TRACE_FS_LOCAL_H */
include/tracefs.h +67 -0

71 lines not on this page · raw message

src/Makefile +4 -0
index e8afab5..984e8cf 100644
@@ -14,6 +14,10 @@ OBJS += tracefs-filter.o
 OBJS += tracefs-dynevents.o
 OBJS += tracefs-eprobes.o
 
+ifeq ($(USEREVENTS_INSTALLED), 1)
+OBJS += tracefs-userevents.o
+endif
+
 # Order matters for the the three below
 OBJS += sqlhist-lex.o
 OBJS += sqlhist.tab.o
src/tracefs-userevents.c new file +516 -0

516 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 2/3 libtracefs: Add documentation and sample code for user_events

In reply to Beau Belgrave

Adds the initial documentation file for user_event APIs within libtracefs. Adds sample code on how to use these new APIs.

---
 Documentation/libtracefs-userevents.txt | 260 ++++++++++++++++++++++++
 samples/Makefile                        |   4 +
 2 files changed, 264 insertions(+)
 create mode 100644 Documentation/libtracefs-userevents.txt
Documentation/libtracefs-userevents.txt new file +260 -0
new file mode 100644
index 0000000..1d32d81
@@ -0,0 +1,260 @@
+libtracefs(3)
+=============
+
+NAME
+----
+tracefs_user_event_group_open, tracefs_user_event_group_close, tracefs_user_event_register,
+tracefs_user_event_enabled, tracefs_user_event_record, tracefs_user_event_delete,
+- Creation and management of a user event group, event, and data
+
+SYNOPSIS
+--------
+[verse]
+--
+*#include <tracefs.h>*
+
+struct tracefs_user_event_group pass:[*]*tracefs_user_event_group_open*(void);
+void *tracefs_user_event_group_close*(struct tracefs_user_event_group pass:[*]_group_);
+int *tracefs_user_event_delete*(const char pass:[*]_name_);
+struct tracefs_user_event pass:[*]*tracefs_user_event_register*(struct tracefs_user_event_group pass:[*]_group_,
+				const char pass:[*]_name_,
+				enum tracefs_uevent_flags _flags_,
+				struct tracefs_uevent_item pass:[*]_items_);
+bool *tracefs_user_event_enabled*(struct tracefs_user_event pass:[*]_event_);
+int *tracefs_user_event_record*(struct tracefs_user_event pass:[*]_event_,
+				struct tracefs_uevent_item pass:[*]_items_);
+--
+
+DESCRIPTION
+-----------
+User events allow user applications to create trace events from their process.
+The status of each event that is created is exposed to the application, which
+enables quick checking if the event is being traced out or not. This enables
+a way to always have the events on with minimal impact to the performance of
+the process. The *tracefs_user_event_enabled*() function should be used for this.
+When the event is to be traced out with data the *tracefs_user_event_record*()
+function is to be used. Processes should delay any work related to the write
+calls until after *tracefs_user_event_enabled*() returns true. This ensures
+minimal performance impacts until tracing is enabled on the system for each event.
+
+To reduce the number of resources, and to manage lifetimes of the events, the
+concept of a group exists within this implementation. Groups keep track of all
+the events that have been registered within it and ensure that once the group
+is closed that all the events are cleaned up properly. All events in a group
+share system resources used for writing. Groups and events are thread safe and
+do not require additional locking when operating in a multi-threaded process.
+Once a group has been closed the events within it are no longer valid to use.
+When groups are closed their resources go away, callers need to ensure that a
+group is closed only once it's no longer needed by any of the events.
+
+*tracefs_user_event_group_open*() opens and initializes a group to be used.
+Group opening can fail if user_events are not installed, the user doesn't have
+permissions to access tracefs or memory allocation errors. The returned group is
+then used to register events.
+
+*tracefs_user_event_group_close*() closes a group and any events that have been
+registered within the group. Events within the group are no longer valid.
+
+*tracefs_user_event_register*() registers an event within the group and the system.
+The name and items passed are translated to show up in tracefs format file.
+The last item passed to this function must have the type of *TRACEFS_UEVENT_END*.
+While events do not require any items, it's expected that each item that will
+be written out should have a matching item during registration.
+
+Flags passed during registration affect the behavior of the event:
+
+*TRACEFS_UEVENT_FLAG_NONE* - No affect
+
+*TRACEFS_UEVENT_FLAG_bpf_iter* - Force BPF programs to receive iovecs instead
+of a copy of the data. Enables higher performance under some conditions for
+events that plan to use BPF programs and require very little overhead when writing.
+
+Types of items passed during the registration:
+
+*TRACEFS_UEVENT_END* - Indicates the last item.
+
+*TRACEFS_UEVENT_u8* - u8 item.
+
+*TRACEFS_UEVENT_s8* - s8 item.
+
+*TRACEFS_UEVENT_u16* - u16 item.
+
+*TRACEFS_UEVENT_s16* - s16 item.
+
+*TRACEFS_UEVENT_u32* - u32 item.
+
+*TRACEFS_UEVENT_s32* - s32 item.
+
+*TRACEFS_UEVENT_u64* - u64 item.
+
+*TRACEFS_UEVENT_s64* - s64 item.
+
+*TRACEFS_UEVENT_string* - Specific length array of char data.
+
+*TRACEFS_UEVENT_struct* - Specific sized struct by name and type (When used the
+name of the item must include both the type and name of the struct).
+
+*TRACEFS_UEVENT_varray* - Variable length array of u8 data.
+
+*TRACEFS_UEVENT_vstring* - Variable length array of char data.
+
+Each item has a type, length, and name during registration. When items are being
+used for writing each item has a type, length, and the data to write.
+
+When items are being registered, length is required for theses types:
+
+*TRACEFS_UEVENT_string*
+
+*TRACEFS_UEVENT_struct*
+
+If lengths are not set for the above types the register will fail. All other
+types have the length determined automatically.
+
+When items are being written, all items must indicate their length. If lengths
+are not set the write will fail. Automatic length sets are not performed.
+
+*tracefs_user_event_enabled*() checks if an event is being traced at that
+moment. This check is quick and should always be used before writing or
+calculating data required for writing out the event data.
+
+*tracefs_user_event_record*() records data for the event. This causes an entry
+to be made in the tracing system that has been attached (perf, ftrace, BPF,
+etc.).
+
+All items passed must set their length, even for common data types (u8, u16,
+etc.). If required, callers may mix types from what has been registered as long
+as it fits within the allocated resources. A common scenario for this is having
+an internal struct that is packed and contains several consecutive registered
+types. Passing the struct directly instead of each individual item might be
+beneficial. While mixing types is allowed, it's a bug to pass more items than
+have been registered. If this occurs the write will fail.
+
+When the type *TRACEFS_UEVENT_vstring* is being used, the length of the data
+must include the null character of a string. If the length does not include the
+null character the write will fail.
+
+*tracefs_user_event_delete*() deletes the event from the system. Delete only
+works if the event is not being used by anything, include the calling program.
+
+RETURN VALUE
+------------
+*tracefs_user_event_group_open*() returns an allocated struct
+tracefs_user_event_group on success or NULL on error.
+
+*tracefs_user_event_register*() returns an allocated struct tracefs_user_event
+on success or NULL on error.
+
+*tracefs_user_event_enabled*() returns true if the event is currently being
+traced.
+
+*tracefs_user_event_record*() returns the number of bytes recorded out on
+success or -1 on error.
+
+*tracefs_user_event_delete*() returns 0 on success or -1 on error.
+
+ERRORS
+------
+The following errors are for all the above calls:
+
+*EPERM* Not run as root user when required.
+
+*EINVAL* Either a parameter is not valid (NULL when it should not be)
+  or a item that is missing an attribute.
+
+*E2BIG* Too many items passed.
+
+*ENOMEM* not enough memory is available.
+
+And more errors may have happened from the system calls to the system.
+
+EXAMPLE
+-------
+[source,c]
+--
+#include <stdlib.h>
+#include <tracefs.h>
+
+static struct tracefs_user_event_group *group;
+static struct tracefs_user_event *event;
+
+static void make_event(void)
+{
+	struct tracefs_uevent_item items[] = {
+		{ TRACEFS_UEVENT_vstring, .name = "message" },
+		{ TRACEFS_UEVENT_END },
+	};
+
+	group = tracefs_user_event_group_open();
+
+	event = tracefs_user_event_register(group, "example",
+					    TRACEFS_UEVENT_FLAG_NONE, items);
+}
+
+int main (int argc, char **argv)
+{
+	make_event();
+
+	if (argc != 2) {
+		printf("Usage: %s <message>\n", argv[0]);
+		return 1;
+	}
+
+	if (tracefs_user_event_enabled(event)) {
+		const char *msg = argv[1];
+
+		struct tracefs_uevent_item items[] = {
+			{ TRACEFS_UEVENT_vstring, strlen(msg)+1, .data = msg },
+			{ TRACEFS_UEVENT_END },
+		};
+
+		tracefs_user_event_record(event, items);
+
+		printf("Event enabled, recorded '%s'\n", msg);
+	} else {
+		printf("Event user_events/example not enabled, enable via tracefs\n");
+	}
+
+	tracefs_user_event_group_close(group);
+
+	return 0;
+}
+--
+
+FILES
+-----
+[verse]
+--
+*tracefs.h*
+	Header file to include in order to have access to the library APIs.
+*-ltracefs*
+	Linker switch to add when building a program that uses the library.
+--
+
+SEE ALSO
+--------
+*libtracefs*(3),
+*libtraceevent*(3),
+*trace-cmd*(1)
+
+AUTHOR
+------
+[verse]
+--
+*Beau Belgrave* <[email protected]>
+--
+REPORTING BUGS
+--------------
+Report bugs to  <[email protected]>
+
+LICENSE
+-------
+libtracefs is Free Software licensed under the GNU LGPL 2.1
+
+RESOURCES
+---------
+https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
+
+COPYING
+-------
+Copyright \(C) 2022 Microsoft Corporation. Free use of this software is granted under
+the terms of the GNU Public License (GPL).
samples/Makefile +4 -0
index f03aff6..169c106 100644
@@ -21,6 +21,10 @@ EXAMPLES += tracer
 EXAMPLES += stream
 EXAMPLES += instances-affinity
 
+ifeq ($(USEREVENTS_INSTALLED), 1)
+EXAMPLES += userevents
+endif
+
 TARGETS :=
 TARGETS += sqlhist
 TARGETS += $(EXAMPLES)
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 3/3 libtracefs: Add unit tests for user_events

In reply to Beau Belgrave

Adds unit tests for user_events when available. Ensures APIs are working correctly and appropriate errors are being returned.

---
 utest/tracefs-utest.c | 233 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)
utest/tracefs-utest.c +233 -0
index e8d5c69..ed38d9c 100644
@@ -11,6 +11,7 @@
 #include <time.h>
 #include <dirent.h>
 #include <ftw.h>
+#include <linux/types.h>
 
 #include <CUnit/CUnit.h>
 #include <CUnit/Basic.h>
@@ -871,6 +872,235 @@ static void test_eprobes(void)
 	test_eprobes_instance(test_instance);
 }
 
+#ifdef USEREVENTS
+struct user_test_context {
+	int seen;
+	int failed;
+};
+static int user_callback(struct tep_event *event, struct tep_record *record,
+			  int cpu, void *context)
+{
+	struct tep_format_field *field;
+	struct user_test_context *user_context;
+	__u32 *rel, size, offset;
+
+	user_context = (struct user_test_context *)context;
+	user_context->seen++;
+
+	field = tep_find_field(event, "u8");
+	if (!field || *(__u8 *)(record->data + field->offset) != 1)
+	{
+		user_context->failed = 1;
+		return -1;
+	}
+
+	field = tep_find_field(event, "s8");
+	if (!field || *(__s8 *)(record->data + field->offset) != 2)
+	{
+		user_context->failed = 2;
+		return -1;
+	}
+
+	field = tep_find_field(event, "u16");
+	if (!field || *(__u16 *)(record->data + field->offset) != 3)
+	{
+		user_context->failed = 3;
+		return -1;
+	}
+
+	field = tep_find_field(event, "s16");
+	if (!field || *(__s16 *)(record->data + field->offset) != 4)
+	{
+		user_context->failed = 4;
+		return -1;
+	}
+
+	field = tep_find_field(event, "u32");
+	if (!field || *(__u32 *)(record->data + field->offset) != 5)
+	{
+		user_context->failed = 5;
+		return -1;
+	}
+
+	field = tep_find_field(event, "s32");
+	if (!field || *(__s32 *)(record->data + field->offset) != 6)
+	{
+		user_context->failed = 6;
+		return -1;
+	}
+
+	field = tep_find_field(event, "u64");
+	if (!field || *(__u64 *)(record->data + field->offset) != 7)
+	{
+		user_context->failed = 7;
+		return -1;
+	}
+
+	field = tep_find_field(event, "s64");
+	if (!field || *(__s64 *)(record->data + field->offset) != 8)
+	{
+		user_context->failed = 8;
+		return -1;
+	}
+
+	field = tep_find_field(event, "string");
+	if (!field || memcmp(record->data + field->offset, "12345678", 8))
+	{
+		user_context->failed = 9;
+		return -1;
+	}
+
+	field = tep_find_field(event, "struct");
+	if (!field || *(__u64 *)(record->data + field->offset) != 9)
+	{
+		user_context->failed = 10;
+		return -1;
+	}
+
+	field = tep_find_field(event, "varray");
+	if (!field) {
+		user_context->failed = 11;
+		return -1;
+	}
+
+	rel = (__u32 *)(record->data + field->offset);
+	offset = *rel & 0xffff;
+	size = *rel >> 16;
+	rel++;
+
+	if (memcmp((void *)(rel) + offset, "Array", size)) {
+		user_context->failed = 12;
+		return -1;
+	}
+
+	field = tep_find_field(event, "vstring");
+	if (!field) {
+		user_context->failed = 13;
+		return -1;
+	}
+
+	rel = (__u32 *)(record->data + field->offset);
+	offset = *rel & 0xffff;
+	size = *rel >> 16;
+	rel++;
+
+	if (memcmp((void *)(rel) + offset, "Variable", size)) {
+		user_context->failed = 14;
+		return -1;
+	}
+
+	return 0;
+}
+
+static void test_userevents_instance(struct tracefs_instance *instance)
+{
+	struct tracefs_user_event_group *group;
+	struct tracefs_user_event *event;
+	struct tep_handle *user_tep;
+	enum tracefs_uevent_flags flags = TRACEFS_UEVENT_FLAG_NONE;
+	const char *systems[] = { "user_events", NULL };
+	const char *name = "libtracefs_utest";
+	const char *system = "user_events";
+	const char *test_string = "12345678";
+	const char *test_array = "Array";
+	const char *test_vstring = "Variable";
+	__u8 a = 1;
+	__s8 b = 2;
+	__u16 c = 3;
+	__s16 d = 4;
+	__u32 e = 5;
+	__s32 f = 6;
+	__u64 g = 7;
+	__s64 h = 8;
+	__u64 i = 9;
+	struct tracefs_uevent_item all_items[] = {
+		{ TRACEFS_UEVENT_u8, .name = "u8" },
+		{ TRACEFS_UEVENT_s8, .name = "s8" },
+		{ TRACEFS_UEVENT_u16, .name = "u16" },
+		{ TRACEFS_UEVENT_s16, .name = "s16" },
+		{ TRACEFS_UEVENT_u32, .name = "u32" },
+		{ TRACEFS_UEVENT_s32, .name = "s32" },
+		{ TRACEFS_UEVENT_u64, .name = "u64" },
+		{ TRACEFS_UEVENT_s64, .name = "s64" },
+		{ TRACEFS_UEVENT_string, .name = "string", .len = 8 },
+		{ TRACEFS_UEVENT_struct, .name = "test struct", .len = 8 },
+		{ TRACEFS_UEVENT_varray, .name = "varray" },
+		{ TRACEFS_UEVENT_vstring, .name = "vstring" },
+		{ TRACEFS_UEVENT_END },
+	};
+	struct tracefs_uevent_item write_items[] = {
+		{ TRACEFS_UEVENT_u8, .data = &a, .len = sizeof(a) },
+		{ TRACEFS_UEVENT_s8, .data = &b, .len = sizeof(b) },
+		{ TRACEFS_UEVENT_u16, .data = &c, .len = sizeof(c) },
+		{ TRACEFS_UEVENT_s16, .data = &d, .len = sizeof(d) },
+		{ TRACEFS_UEVENT_u32, .data = &e, .len = sizeof(e) },
+		{ TRACEFS_UEVENT_s32, .data = &f, .len = sizeof(f) },
+		{ TRACEFS_UEVENT_u64, .data = &g, .len = sizeof(g) },
+		{ TRACEFS_UEVENT_s64, .data = &h, .len = sizeof(h) },
+		{ TRACEFS_UEVENT_string, .data = test_string,
+					 .len = strlen(test_string) },
+		{ TRACEFS_UEVENT_struct, .data = &i, .len = sizeof(i) },
+		{ TRACEFS_UEVENT_varray, .data = test_array,
+					 .len = strlen(test_array) },
+		{ TRACEFS_UEVENT_vstring, .data = test_vstring,
+					  .len = strlen(test_vstring)+1 },
+		{ TRACEFS_UEVENT_END },
+	};
+	struct user_test_context context;
+	int ret;
+
+	/* Delete if it already exists */
+	tracefs_user_event_delete(name);
+
+	group = tracefs_user_event_group_open();
+	CU_TEST(group != NULL);
+
+	event = tracefs_user_event_register(group, name, flags, all_items);
+	CU_TEST(event != NULL);
+
+	/* Test enable and status */
+	CU_TEST(!tracefs_user_event_enabled(event));
+	CU_TEST(tracefs_event_enable(instance, system, name) == 0);
+	CU_TEST(tracefs_user_event_enabled(event));
+
+	/* Correct record should work */
+	CU_TEST(tracefs_user_event_record(event, write_items) > 0);
+
+	/* Ensure record output was correct */
+	user_tep = tracefs_local_events_system(NULL, systems);
+	CU_TEST(user_tep != NULL);
+
+	memset(&context, 0, sizeof(context));
+	ret = tracefs_iterate_raw_events(user_tep, instance, NULL, 0,
+					 user_callback, &context);
+	tep_free(user_tep);
+
+	CU_TEST(ret == 0);
+	CU_TEST(context.seen == 1);
+	CU_TEST(context.failed == 0);
+
+	/* Simulate bad length */
+	write_items[0].len = 0;
+	CU_TEST(tracefs_user_event_record(event, write_items) == -1);
+
+	/* Simulate bad pointer */
+	write_items[0].len = sizeof(a);
+	write_items[0].data = NULL;
+	CU_TEST(tracefs_user_event_record(event, write_items) == -1);
+
+	tracefs_user_event_group_close(group);
+
+	/* Disable and deletion must work */
+	CU_TEST(tracefs_event_disable(instance, system, name) == 0);
+	CU_TEST(tracefs_user_event_delete(name) == 0);
+}
+
+static void test_userevents(void)
+{
+	test_userevents_instance(test_instance);
+}
+#endif
+
 static void test_instance_file(void)
 {
 	struct tracefs_instance *instance = NULL;
@@ -1706,4 +1936,7 @@ void test_tracefs_lib(void)
 	CU_add_test(suite, "kprobes", test_kprobes);
 	CU_add_test(suite, "syntetic events", test_synthetic);
 	CU_add_test(suite, "eprobes", test_eprobes);
+#ifdef USEREVENTS
+	CU_add_test(suite, "user events", test_userevents);
+#endif
 }
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/3] libtracefs: Add user_events to libtracefs sources

In reply to Beau Belgrave
Quoted 8 lines · On Tue, 22 Feb 2022 15:23:14 -0800 Beau Belgrave <[email protected]>…

The user events are scheduled to be included into Linux 5.18, which register a special mmapped page to denote when the user event is enabled (from an external source). This API adds a wrapper to the kernel interface that makes it easy to register user events and test if they are enabled and to record the event when it is.

Link:
https://lore.kernel.org/linux-trace-devel/20220121192833.GA3128@kbox/T/#m2bcf53c373fbeaba2c46d1a053b3174171167e4e

I was afraid you would copy me ;-)

After I sent the email, I noticed that claws-mail decided to line wrap that line putting the link on a different line than the Link tag. It was suppose to be:

But claws-mail decided otherwise :-p

And worse, it did it while it was not in my editor view, so I had no idea it did it. That's a bug in claws-mail that has been bothering me for some time.

-- Steve

Quoted 4 lines

---

#5 lore raw

Re: [PATCH v2 3/3] libtracefs: Add unit tests for user_events

In reply to Beau Belgrave
Quoted 8 lines · On Tue, 22 Feb 2022 15:23:16 -0800 Beau Belgrave <[email protected]>…

Adds unit tests for user_events when available. Ensures APIs are working correctly and appropriate errors are being returned.

---
 utest/tracefs-utest.c | 233 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)

OK, so I couldn't get the selftest working because I didn't have user_events.h. I then worked to get that, but the selftest still failed with:

After thinking about this a bit, I've decided that I'll release 1.3 without this patch series.

The reason being, I want 1.3 to get into distros ASAP. As adding this patch series will put a dependency on user_events.h (yes it builds without it, but distros want everything that it can build applied), then that puts a dependency on 1.3 to having user_events.h available, which may be a while as it has to get into 5.18, and then slowly move to the distro kernels.

If distros did build it without user_events.h and then later on with user_evnets.h then we have two versions of 1.3 where one supports user_events and one does not. And you can not use versioning to determine if your application will link to the library or not.

With all this in mind, I've decided to hold off this to libtracefs 1.4, and when user_events is solidly in the kernel.

But I'm very excited to have this work in both the kernel and libtracefs. I just want it properly done though.

Thanks for all your work and I'll keep these patches in my queue for 1.4.

Cheers,

-- Steve

#6 lore raw

Re: [PATCH v2 3/3] libtracefs: Add unit tests for user_events

Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Tue, 22 Feb 2022 15:23:16 -0800 Beau Belgrave <[email protected]>…

Adds unit tests for user_events when available. Ensures APIs are working correctly and appropriate errors are being returned.

---
 utest/tracefs-utest.c | 233 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 233 insertions(+)
Quoted 4 lines

OK, so I couldn't get the selftest working because I didn't have user_events.h. I then worked to get that, but the selftest still failed with:

The suspense is killing me, what did it fail with? :) (Guessing you saw the fprintf message when I simulate a failure).

Quoted 3 lines

After thinking about this a bit, I've decided that I'll release 1.3 without this patch series.

No worries.

Quoted 6 lines

The reason being, I want 1.3 to get into distros ASAP. As adding this patch series will put a dependency on user_events.h (yes it builds without it, but distros want everything that it can build applied), then that puts a dependency on 1.3 to having user_events.h available, which may be a while as it has to get into 5.18, and then slowly move to the distro kernels.

Understood.

Quoted 11 lines

If distros did build it without user_events.h and then later on with user_evnets.h then we have two versions of 1.3 where one supports user_events and one does not. And you can not use versioning to determine if your application will link to the library or not.

With all this in mind, I've decided to hold off this to libtracefs 1.4, and when user_events is solidly in the kernel.

But I'm very excited to have this work in both the kernel and libtracefs. I just want it properly done though.

Yeah, do you want me to send out a v3 with some of the fixes? Or have you put this into a branch somewhere already (I saw your other patch on top of this one). I fixed some style nits that were bugging me, as they didn't align to the kernel style.

Thanks,
-Beau