Linux-Trace-Devel Archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH] libtracefs: Add ring buffer memory mapping APIs
Date: Fri, 5 Jan 2024 15:22:02 -0500	[thread overview]
Message-ID: <20240105152202.5b6995c0@gandalf.local.home> (raw)
In-Reply-To: <20240105084100.5fe6ffa0@gandalf.local.home>

On Fri, 5 Jan 2024 08:41:00 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> > Could it fast-forward to the event until tmap->map->reader.read? So we don't
> > read again the same events.
> > 
> > Something like
> > 
> >   while (kbuf->curr < tmap->map->reader.read)
> >   	kbuffer_next_event(kbuf, NULL);  
> 
> Note that kbuf->curr is not available to libtracefs. That's internal to
> libtraceevent.
> 
> But we could have somethings like:
> 
> 	kbuffer_load_subbuffer(kbuf, data);
> 
> 	/* Update to kbuf index to the next read */
> 	if (tmap->map->reader.read) {
> 		char tmpbuf[tmap->map->reader.read];
> 		kbuffer_read_buffer(kbuf, tmpbuf, tmap->map->reader.read);
> 	}
> 
> Which should move the kbuf->curr to reader.read.

So, I tried out this:

(compiled the sample code into /tmp/map)

 # taskset -c 0 echo hello > /sys/kernel/tracing/trace_marker
 # /tmp/map 0
<...>-3767  6659.560129846	print: tracing_mark_write: hello

 # taskset -c 0 echo hello 2 > /sys/kernel/tracing/trace_marker
# /tmp/map 0
<...>-3767  6659.560129846	print: tracing_mark_write: hello

<...>-3769  6669.280279823	print: tracing_mark_write: hello 2


So it reported "hello" and "hello 2" but only should have reported "hello 2".

I added this:

@@ -111,6 +112,16 @@ __hidden void *trace_mmap(int fd, struct kbuffer *kbuf)
        data = tmap->data + tmap->map->subbuf_size * tmap->last_idx;
        kbuffer_load_subbuffer(kbuf, data);
 
+       /*
+        * The page could have left over data on it that was already
+        * consumed. Move the "read" forward in that case.
+        */
+       if (tmap->map->reader.read) {
+               int size = kbuffer_start_of_data(kbuf) + tmap->map->reader.read;
+               char tmpbuf[size];
+               kbuffer_read_buffer(kbuf, tmpbuf, size);
+       }
+
        return tmap;
 }

And now I get:

 # taskset -c 0 echo hello > /sys/kernel/tracing/trace_marker
 # /tmp/map 0
<...>-3938  6820.503525176	print: tracing_mark_write: hello

 # taskset -c 0 echo hello 2 > /sys/kernel/tracing/trace_marker
 # /tmp/map 0
<...>-3940  6827.655627086	print: tracing_mark_write: hello 2

The way you were expecting.

[
 Note the above didn't work until I applied to libtraceevent:

  https://lore.kernel.org/all/20240105194015.253165-3-rostedt@goodmis.org/
]

I'll send a v2.

-- Steve.

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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29  1:11 [PATCH] libtracefs: Add ring buffer memory mapping APIs Steven Rostedt
2024-01-05  9:17 ` Vincent Donnefort
2024-01-05 13:41   ` Steven Rostedt
2024-01-05 14:25     ` Vincent Donnefort
2024-01-05 17:31       ` Steven Rostedt
2024-01-05 18:23         ` Vincent Donnefort
2024-01-05 19:00           ` Steven Rostedt
2024-01-05 20:11         ` Steven Rostedt
2024-01-05 20:22     ` Steven Rostedt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-01-05 20:29 Steven Rostedt
2024-01-08 14:25 ` Vincent Donnefort
2024-01-08 17:16   ` Steven Rostedt
2024-01-08 17:34     ` Vincent Donnefort
2024-01-23  9:52 ` Vincent Donnefort
2024-01-23 15:15   ` Steven Rostedt

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=20240105152202.5b6995c0@gandalf.local.home \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).