summaryrefslogtreecommitdiff
path: root/samples/user_events/example.c
diff options
context:
space:
mode:
authorBeau Belgrave <beaub@linux.microsoft.com>2022-07-28 16:33:08 -0700
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-09-29 10:17:37 -0400
commit39d6d08b2edf99c4b39a689a70bf0adee065b357 (patch)
tree2dfb47d9ea7e51415af2cd79815f2c9597786655 /samples/user_events/example.c
parentd401b72458562c2f2a81dad162de5c1b8e191e17 (diff)
tracing/user_events: Use bits vs bytes for enabled status page data
User processes may require many events and when they do the cache performance of a byte index status check is less ideal than a bit index. The previous event limit per-page was 4096, the new limit is 32,768. This change adds a bitwise index to the user_reg struct. Programs check that the bit at status_bit has a bit set within the status page(s). Link: https://lkml.kernel.org/r/20220728233309.1896-6-beaub@linux.microsoft.com Link: https://lore.kernel.org/all/2059213643.196683.1648499088753.JavaMail.zimbra@efficios.com/ Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Diffstat (limited to 'samples/user_events/example.c')
-rw-r--r--samples/user_events/example.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/samples/user_events/example.c b/samples/user_events/example.c
index 4f5778e441c0..d06dc24156ec 100644
--- a/samples/user_events/example.c
+++ b/samples/user_events/example.c
@@ -12,13 +12,21 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
+#include <asm/bitsperlong.h>
+#include <endian.h>
#include <linux/user_events.h>
+#if __BITS_PER_LONG == 64
+#define endian_swap(x) htole64(x)
+#else
+#define endian_swap(x) htole32(x)
+#endif
+
/* Assumes debugfs is mounted */
const char *data_file = "/sys/kernel/debug/tracing/user_events_data";
const char *status_file = "/sys/kernel/debug/tracing/user_events_status";
-static int event_status(char **status)
+static int event_status(long **status)
{
int fd = open(status_file, O_RDONLY);
@@ -33,7 +41,8 @@ static int event_status(char **status)
return 0;
}
-static int event_reg(int fd, const char *command, int *status, int *write)
+static int event_reg(int fd, const char *command, long *index, long *mask,
+ int *write)
{
struct user_reg reg = {0};
@@ -43,7 +52,8 @@ static int event_reg(int fd, const char *command, int *status, int *write)
if (ioctl(fd, DIAG_IOCSREG, &reg) == -1)
return -1;
- *status = reg.status_index;
+ *index = reg.status_bit / __BITS_PER_LONG;
+ *mask = endian_swap(1L << (reg.status_bit % __BITS_PER_LONG));
*write = reg.write_index;
return 0;
@@ -51,8 +61,9 @@ static int event_reg(int fd, const char *command, int *status, int *write)
int main(int argc, char **argv)
{
- int data_fd, status, write;
- char *status_page;
+ int data_fd, write;
+ long index, mask;
+ long *status_page;
struct iovec io[2];
__u32 count = 0;
@@ -61,7 +72,7 @@ int main(int argc, char **argv)
data_fd = open(data_file, O_RDWR);
- if (event_reg(data_fd, "test u32 count", &status, &write) == -1)
+ if (event_reg(data_fd, "test u32 count", &index, &mask, &write) == -1)
return errno;
/* Setup iovec */
@@ -75,7 +86,7 @@ ask:
getchar();
/* Check if anyone is listening */
- if (status_page[status]) {
+ if (status_page[index] & mask) {
/* Yep, trace out our data */
writev(data_fd, (const struct iovec *)io, 2);