Re: [PATCH] libtracefs: Add ring buffer memory mapping APIs

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

 



On Fri, 5 Jan 2024 08:41:00 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> 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@xxxxxxxxxxx/
]

I'll send a v2.

-- Steve.




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

  Powered by Linux