Skip to content

Commit 9211dda

Browse files
beaubelgraverostedt
authored andcommitted
tracing/user_events: Use write ABI in example
The ABI has changed to use a remote write approach. Update the example to show the expected use of this new ABI. Also remove debugfs path and use tracefs to ensure example works in more environments. Link: https://lkml.kernel.org/r/20230328235219.203-9-beaub@linux.microsoft.com Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 60b1af8 commit 9211dda

1 file changed

Lines changed: 8 additions & 37 deletions

File tree

samples/user_events/example.c

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,28 @@
99
#include <errno.h>
1010
#include <sys/ioctl.h>
1111
#include <sys/mman.h>
12+
#include <sys/uio.h>
1213
#include <fcntl.h>
1314
#include <stdio.h>
1415
#include <unistd.h>
15-
#include <asm/bitsperlong.h>
16-
#include <endian.h>
1716
#include <linux/user_events.h>
1817

19-
#if __BITS_PER_LONG == 64
20-
#define endian_swap(x) htole64(x)
21-
#else
22-
#define endian_swap(x) htole32(x)
23-
#endif
24-
25-
/* Assumes debugfs is mounted */
2618
const char *data_file = "/sys/kernel/tracing/user_events_data";
27-
const char *status_file = "/sys/kernel/tracing/user_events_status";
19+
int enabled = 0;
2820

29-
static int event_status(long **status)
30-
{
31-
int fd = open(status_file, O_RDONLY);
32-
33-
*status = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ,
34-
MAP_SHARED, fd, 0);
35-
36-
close(fd);
37-
38-
if (*status == MAP_FAILED)
39-
return -1;
40-
41-
return 0;
42-
}
43-
44-
static int event_reg(int fd, const char *command, long *index, long *mask,
45-
int *write)
21+
static int event_reg(int fd, const char *command, int *write, int *enabled)
4622
{
4723
struct user_reg reg = {0};
4824

4925
reg.size = sizeof(reg);
26+
reg.enable_bit = 31;
27+
reg.enable_size = sizeof(*enabled);
28+
reg.enable_addr = (__u64)enabled;
5029
reg.name_args = (__u64)command;
5130

5231
if (ioctl(fd, DIAG_IOCSREG, &reg) == -1)
5332
return -1;
5433

55-
*index = reg.status_bit / __BITS_PER_LONG;
56-
*mask = endian_swap(1L << (reg.status_bit % __BITS_PER_LONG));
5734
*write = reg.write_index;
5835

5936
return 0;
@@ -62,31 +39,25 @@ static int event_reg(int fd, const char *command, long *index, long *mask,
6239
int main(int argc, char **argv)
6340
{
6441
int data_fd, write;
65-
long index, mask;
66-
long *status_page;
6742
struct iovec io[2];
6843
__u32 count = 0;
6944

70-
if (event_status(&status_page) == -1)
71-
return errno;
72-
7345
data_fd = open(data_file, O_RDWR);
7446

75-
if (event_reg(data_fd, "test u32 count", &index, &mask, &write) == -1)
47+
if (event_reg(data_fd, "test u32 count", &write, &enabled) == -1)
7648
return errno;
7749

7850
/* Setup iovec */
7951
io[0].iov_base = &write;
8052
io[0].iov_len = sizeof(write);
8153
io[1].iov_base = &count;
8254
io[1].iov_len = sizeof(count);
83-
8455
ask:
8556
printf("Press enter to check status...\n");
8657
getchar();
8758

8859
/* Check if anyone is listening */
89-
if (status_page[index] & mask) {
60+
if (enabled) {
9061
/* Yep, trace out our data */
9162
writev(data_fd, (const struct iovec *)io, 2);
9263

0 commit comments

Comments
 (0)