1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021, Microsoft Corporation.
6 * Beau Belgrave <beaub@linux.microsoft.com>
10 #include <sys/ioctl.h>
16 #include <linux/user_events.h>
18 const char *data_file = "/sys/kernel/tracing/user_events_data";
21 static int event_reg(int fd, const char *command, int *write, int *enabled)
23 struct user_reg reg = {0};
25 reg.size = sizeof(reg);
27 reg.enable_size = sizeof(*enabled);
28 reg.enable_addr = (__u64)enabled;
29 reg.name_args = (__u64)command;
31 if (ioctl(fd, DIAG_IOCSREG, ®) == -1)
34 *write = reg.write_index;
39 int main(int argc, char **argv)
45 data_fd = open(data_file, O_RDWR);
47 if (event_reg(data_fd, "test u32 count", &write, &enabled) == -1)
51 io[0].iov_base = &write;
52 io[0].iov_len = sizeof(write);
53 io[1].iov_base = &count;
54 io[1].iov_len = sizeof(count);
56 printf("Press enter to check status...\n");
59 /* Check if anyone is listening */
61 /* Yep, trace out our data */
62 writev(data_fd, (const struct iovec *)io, 2);
64 /* Increase the count */
67 printf("Something was attached, wrote data\n");