All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Vincent Donnefort <vdonnefort@google.com>,
	"Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 4/4] libtracefs: Have tracefs_cpu_flush(_buf)() use mapping
Date: Tue,  9 Jan 2024 15:48:59 -0500	[thread overview]
Message-ID: <20240109205112.74225-5-rostedt@goodmis.org> (raw)
In-Reply-To: <20240109205112.74225-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the tracefs_cpu is opened with tracefs_cpu_open_mapped() and uses
tracefs_cpu_read_buf() along with tracefs_cpu_flush_buf(), the flush will
load the tcpu->kbuf with a new buffer which may make the one in the mmapped
out of sync.

If the tcpu is mapped, make sure tracefs_cpu_flush() and
tracefs_cpu_flush_buf() also use the mapping.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-record.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/tracefs-record.c b/src/tracefs-record.c
index 4a59c61c195f..fca3ddf9afbe 100644
--- a/src/tracefs-record.c
+++ b/src/tracefs-record.c
@@ -690,6 +690,9 @@ int tracefs_cpu_flush(struct tracefs_cpu *tcpu, void *buffer)
 	if (tcpu->buffered < 0)
 		tcpu->buffered = 0;
 
+	if (tcpu->mapping)
+		return trace_mmap_read(tcpu->mapping, buffer);
+
 	if (tcpu->buffered) {
 		ret = read(tcpu->splice_pipe[0], buffer, tcpu->subbuf_size);
 		if (ret > 0)
@@ -729,6 +732,13 @@ struct kbuffer *tracefs_cpu_flush_buf(struct tracefs_cpu *tcpu)
 	if (!get_buffer(tcpu))
 		return NULL;
 
+	if (tcpu->mapping) {
+		/* Make sure that reading is now non blocking */
+		set_nonblock(tcpu);
+		ret = trace_mmap_load_subbuf(tcpu->mapping, tcpu->kbuf);
+		return ret > 0 ? tcpu->kbuf : NULL;
+	}
+
 	ret = tracefs_cpu_flush(tcpu, tcpu->buffer);
 	if (ret <= 0)
 		return NULL;
-- 
2.43.0


      parent reply	other threads:[~2024-01-09 20:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 20:48 [PATCH 0/4] libtracefs: More updates and fixes to mmap code Steven Rostedt
2024-01-09 20:48 ` [PATCH 1/4] libtracefs: Unmap mmap mapping on tracefs_cpu close Steven Rostedt
2024-01-09 20:48 ` [PATCH 2/4] libtracefs: Use tracefs_cpu_*_buf() calls for iterator Steven Rostedt
2024-01-09 20:48 ` [PATCH 3/4] libtracefs: Use mmapping for iterating raw events Steven Rostedt
2024-01-09 20:48 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240109205112.74225-5-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=vdonnefort@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.