relayfs: upgraded read() implementation
PATCH 1/1 relayfs: upgraded read() implementation
Hi,
The current relayfs read implementation works fine, but was designed to be used mainly for 'draining' the buffer after a tracing run. It turns out that people really want to be able to read from the buffer during a live trace, for example the blktrace application submitted recently:
http://marc.theaimsgroup.com/?l=linux-kernel&m=112480046405961&w=2
Here's an improved read implementation for relayfs which allows for that.
This version has been tested pretty thoroughly, using both the blktrace application and a new example I added to the relay-apps tarball called 'readtest' which is basically a unit test for the read functionality. All the tests I've come up with have passed and it looks pretty solid at this point. Here's a link to the test code:
http://prdownloads.sourceforge.net/relayfs/relay-apps-0.8.tar.gz?download
Andrew, please apply.
Thanks,
Tom
Documentation/filesystems/relayfs.txt +11 -6
@@ -82,10 +82,15 @@ mmap() results in channel buffer being memory space. Note that you can't do a partial mmap - you must map the entire file, which is NRBUF * SUBBUFSIZE. -read() read the contents of a channel buffer. If there are active - channel writers, results may be unpredictable - users should - make sure that all logging to the channel has ended before - using read(). +read() read the contents of a channel buffer. The bytes read are + 'consumed' by the reader i.e. they won't be available again + to subsequent reads. If the channel is being used in + no-overwrite mode (the default), it can be read at any time + even if there's an active kernel writer. If the channel is + being used in overwrite mode and there are active channel + writers, results may be unpredictable - users should make + sure that all logging to the channel has ended before using + read() with overwrite mode. poll() POLLIN/POLLRDNORM/POLLERR supported. User applications are notified when sub-buffer boundaries are crossed.
@@ -256,8 +261,8 @@ consulted. The default subbuf_start() implementation, used if the client doesn't define any callbacks, or doesn't define the subbuf_start() callback, -implements the simplest possible 'overwrite' mode i.e. it does nothing -but return 1. +implements the simplest possible 'no-overwrite' mode i.e. it does +nothing but return 0. Header information can be reserved at the beginning of each sub-buffer by calling the subbuf_start_reserve() helper function from within the
fs/relayfs/inode.c +128 -95
281 lines not on this page · raw message
fs/relayfs/relay.c +6 -1
@@ -58,6 +58,9 @@ static int subbuf_start_default_callback void *prev_subbuf, size_t prev_padding) { + if (relay_buf_full(buf)) + return 0; +return 1 ; }
@@ -120,6 +123,7 @@ static inline void __relay_reset(struct buf->subbufs_produced =0 ; buf->subbufs_consumed =0 ; + buf->bytes_consumed =0 ; buf->finalized =0 ; buf->data = buf->start; buf->offset =0 ;
@@ -262,6 +266,7 @@ struct rchan *relay_open(const char *basfor_each_online_cpu (i) {sprintf (tmpname,"%s%d" , base_filename, i); chan->buf[i] =relay_open_buf (chan, tmpname, parent); + chan->buf[i]->cpu = i;if (!chan->buf[i]) goto free_bufs; }
@@ -328,7 +333,7 @@ size_t relay_switch_subbuf(struct rchan_return length; toobig: -printk (KERN_WARNING "relayfs: event too large (%u)\n" , length); +printk (KERN_WARNING "relayfs: event too large (%Zd)\n" , length);WARN_ON (1 );return 0 ; }
include/linux/relayfs_fs.h +3 -1
@@ -22,7 +22,7 @@/* * Tracks changes to rchan_buf struct */ -#define RELAYFS_CHANNEL_VERSION 4 +#define RELAYFS_CHANNEL_VERSION 5/* * Per-cpu relay channel buffer
@@ -44,6 +44,8 @@ struct rchan_bufunsigned int finalized;/* buffer has been finalized */ size_t *padding;/* padding counts per sub-buffer */ size_t prev_padding;/* temporary variable */ +size_t bytes_consumed;/* bytes consumed in cur read subbuf */ +unsigned int cpu;/* this buf's cpu */ }____cacheline_aligned ;/*