[PATCH 5/7] libtracefs: Call mmap ioctl if a refresh happens

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

If the reader sub-buffer gets more data on it due to a writer still on the
reader sub-buffer, just updating the kbuf is not enough. An ioctl() needs to
be called again to update the "read" pointer, otherwise after reading the
full reader sub-buffer and calling the next ioctl(), the kernel will not
swap out for a new reader sub-buffer as it still thinks there's more to be
read.

Fixes: 2ed14b594f669 ("libtracefs: Add ring buffer memory mapping APIs")
Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
 src/tracefs-mmap.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/tracefs-mmap.c b/src/tracefs-mmap.c
index e0e37681e019..499233ae396c 100644
--- a/src/tracefs-mmap.c
+++ b/src/tracefs-mmap.c
@@ -143,6 +143,11 @@ __hidden void trace_unmap(void *mapping)
 	free(tmap);
 }
 
+static int get_reader(struct trace_mmap *tmap)
+{
+	return ioctl(tmap->fd, TRACE_MMAP_IOCTL_GET_READER);
+}
+
 __hidden int trace_mmap_load_subbuf(void *mapping, struct kbuffer *kbuf)
 {
 	struct trace_mmap *tmap = mapping;
@@ -171,11 +176,18 @@ __hidden int trace_mmap_load_subbuf(void *mapping, struct kbuffer *kbuf)
 	kbuffer_refresh(kbuf);
 
 	/* Are there still events to read? */
-	if (kbuffer_curr_size(kbuf))
+	if (kbuffer_curr_size(kbuf)) {
+		/* If current is greater than what was read, refresh */
+		if (kbuffer_curr_offset(kbuf) + kbuffer_curr_size(kbuf) >
+		    tmap->map->reader.read) {
+			if (get_reader(tmap) < 0)
+				return -1;
+		}
 		return 1;
+	}
 
 	/* See if a new page is ready? */
-	if (ioctl(tmap->fd, TRACE_MMAP_IOCTL_GET_READER) < 0)
+	if (get_reader(tmap) < 0)
 		return -1;
 	id = tmap->map->reader.id;
 	data = tmap->data + tmap->map->subbuf_size * id;
-- 
2.43.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux