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 12:31:11 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> Hmm, but looking at how the code currently works without mapping, it looks
> like it would do the read again anyway assuming that the kbuf was
> completely read before reading again. Perhaps it would make the logic
> simpler to assume that the buffer was completely read before this gets
> called again. That is, we could have it do:

Now I remember why I did it the other way. This is called to get the
kbuffer after it is mapped. That is, the first time we call this,
kbuf->curr will be zero, and we do not want to call the ioctl(). If we do,
we just threw away all the events currently loaded on the kbuf.

That is, the code does this:


        tcpu = tracefs_cpu_open_mapped(NULL, cpu, 0);

// Here the memory is already mapped, and a kbuf is loaded.

        mapped = tracefs_cpu_is_mapped(tcpu);
        if (!mapped)
                printf("Was not able to map, falling back to buffered read\n");
        while ((kbuf = mapped ? tracefs_cpu_read_buf(tcpu, true) :

// The tracefs_cpu_read_buf() will call the trace_mmap_load_subbuf().
// That is, it must check if kbuf has left over data and return that.
// If it does the ioctl() here, it will throw out what it loaded in the
// initial mapping.


                        tracefs_cpu_buffered_read_buf(tcpu, true))) {
                read_page(tep, kbuf);
        }



-- Steve


> 
> 	if (data != kbuffer_subbuffer(kbuf)) {
> 		kbuffer_load_subbuffer(kbuf, data);
> 		return 1;
> 	}
> 
> 	if (ioctl(tmap->fd, TRACE_MMAP_IOCTL_GET_READER) < 0)
> 		return -1;
> 
> 	if (id != tmap->map->reader.id) {
> 		/* New page, just reload it */
> 		data = tmap->data + tmap->map->subbuf_size * id;
> 		kbuffer_load_subbuffer(kbuf, data);
> 		return 1;
> 	}
> 
> 	/*
> 	 * Perhaps the reader page had a write that added
> 	 * more data.
> 	 */
> 	kbuffer_refresh(kbuf);
> 
> 	/* Are there still events to read? */
> 	return kbuffer_curr_size(kbuf) ? 1 : 0;





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

  Powered by Linux