LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch 1/3]  Relay Reset Consumed
@ 2008-03-03 23:51 David J. Wilder
  2008-03-05 22:12 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: David J. Wilder @ 2008-03-03 23:51 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: systemtap

This patch allows relay channels to be reset i.e. unconsumed.
Basically allows a 'rewind' function for flight-recorder tracing.

Signed-off-by: Tom Zanussi <zanussi@us.ibm.com>
Signed-off-by: David Wilder <dwilder@us.ibm.com>
---
 Documentation/filesystems/relay.txt |   11 ++++++
 include/linux/relay.h               |    1 +
 kernel/relay.c                      |   58 ++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/Documentation/filesystems/relay.txt b/Documentation/filesystems/relay.txt
index 094f2d2..1af6d4b 100644
--- a/Documentation/filesystems/relay.txt
+++ b/Documentation/filesystems/relay.txt
@@ -161,6 +161,7 @@ TBD(curr. line MT:/API/)
     relay_close(chan)
     relay_flush(chan)
     relay_reset(chan)
+    relay_reset_consumed(chan)
 
   channel management typically called on instigation of userspace:
 
@@ -452,6 +453,16 @@ state without reallocating channel buffer memory or destroying
 existing mappings.  It should however only be called when it's safe to
 do so, i.e. when the channel isn't currently being written to.
 
+The read(2) implementation always 'consumes' the bytes read,
+i.e. those bytes won't be available again to subsequent reads.
+Certain applications may nonetheless wish to allow the 'consumed' data
+to be re-read; relay_reset_consumed() is provided for that purpose -
+it resets the internal consumed counters for all buffers in the
+channel.  For example, if a first set of reads 'drains' the channel,
+and then relay_reset_consumed() is called, a second set of reads will
+get the exact same data (assuming no new data was written between the
+first set of reads and the second).
+
 Finally, there are a couple of utility callbacks that can be used for
 different purposes.  buf_mapped() is called whenever a channel buffer
 is mmapped from user space and buf_unmapped() is called when it's
diff --git a/include/linux/relay.h b/include/linux/relay.h
index 6cd8c44..aca45fa 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -175,6 +175,7 @@ extern void relay_subbufs_consumed(struct rchan *chan,
 				   unsigned int cpu,
 				   size_t consumed);
 extern void relay_reset(struct rchan *chan);
+extern void relay_reset_consumed(struct rchan *chan);
 extern int relay_buf_full(struct rchan_buf *buf);
 
 extern size_t relay_switch_subbuf(struct rchan_buf *buf,
diff --git a/kernel/relay.c b/kernel/relay.c
index d080b9d..f9dc539 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -378,6 +378,57 @@ void relay_reset(struct rchan *chan)
 }
 EXPORT_SYMBOL_GPL(relay_reset);
 
+/**
+ *	__relay_reset_consumed - reset a channel buffer's consumed count
+ *	@buf: the channel buffer
+ *
+ *	See relay_reset_consumed for description of effect.
+ */
+static void __relay_reset_consumed(struct rchan_buf *buf)
+{
+	size_t n_subbufs = buf->chan->n_subbufs;
+	size_t produced = buf->subbufs_produced;
+	size_t consumed = buf->subbufs_consumed;
+
+	if (produced < n_subbufs)
+		buf->subbufs_consumed = 0;
+	else {
+		consumed = produced - n_subbufs;
+		if (buf->offset)
+			consumed++;
+		buf->subbufs_consumed = consumed;
+	}
+	buf->bytes_consumed = 0;
+}
+
+/**
+ *	relay_reset_consumed - reset the channel's consumed counts
+ *	@chan: the channel
+ *
+ *	This has the effect of making all data previously read (and
+ *	not overwritten by subsequent writes) from a channel available
+ *	for reading again.
+ *
+ *	NOTE: Care should be taken that the channel isn't actually
+ *	being used by anything when this call is made.
+ */
+void relay_reset_consumed(struct rchan *chan)
+{
+	unsigned int i;
+	struct rchan_buf *prev = NULL;
+
+	if (!chan)
+		return;
+
+	for (i = 0; i < NR_CPUS; i++) {
+		if (!chan->buf[i] || chan->buf[i] == prev)
+			break;
+		__relay_reset_consumed(chan->buf[i]);
+		prev = chan->buf[i];
+	}
+}
+EXPORT_SYMBOL_GPL(relay_reset_consumed);
+
 /*
  *	relay_open_buf - create a new relay channel buffer
  *
@@ -840,11 +891,8 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
 		return 1;
 	}
 
-	if (unlikely(produced - consumed >= n_subbufs)) {
-		consumed = produced - n_subbufs + 1;
-		buf->subbufs_consumed = consumed;
-		buf->bytes_consumed = 0;
-	}
+	if (unlikely(produced - consumed >= n_subbufs))
+		__relay_reset_consumed(buf);
 
 	produced = (produced % n_subbufs) * subbuf_size + buf->offset;
 	consumed = (consumed % n_subbufs) * subbuf_size + buf->bytes_consumed;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 1/3]  Relay Reset Consumed
  2008-03-03 23:51 [patch 1/3] Relay Reset Consumed David J. Wilder
@ 2008-03-05 22:12 ` Andrew Morton
  2008-03-06 10:56   ` Andy Whitcroft
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2008-03-05 22:12 UTC (permalink / raw)
  To: David J. Wilder; +Cc: linux-kernel, systemtap, Andy Whitcroft

On Mon, 03 Mar 2008 15:51:50 -0800
"David J. Wilder" <dwilder@us.ibm.com> wrote:

> This patch allows relay channels to be reset i.e. unconsumed.
> Basically allows a 'rewind' function for flight-recorder tracing.
> 
> +void relay_reset_consumed(struct rchan *chan)
> +{
> +	unsigned int i;
> +	struct rchan_buf *prev = NULL;
> +
> +	if (!chan)
> +		return;
> +
> +	for (i = 0; i < NR_CPUS; i++) {

Use of NR_CPUS is usually wrong.  In this case it seems you should be using
for_each_possible_cpu().

Also the existing usage of NR_CPUS in relay_subbufs_consumed() should be
switched to using cpu_possible().


New usage of NR_CPUS might be checkpatch-worthy, actually:

akpm:/usr/src/25> grep -l '^+.*NR_CPUS' patches/*.patch 
patches/ext4-mm-mballoc-core.patch
patches/git-kvm.patch
patches/git-perfmon.patch
patches/relay-reset-consumed.patch
patches/x86-andi-git-x86.patch
patches/x86-andi-smp-switch-optimize.patch

that's a sample of 1852 patches.

An appropriate warning would be "Usage of NR_CPUS is often wrong - should
you be using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(),
etc?".


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 1/3]  Relay Reset Consumed
  2008-03-05 22:12 ` Andrew Morton
@ 2008-03-06 10:56   ` Andy Whitcroft
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Whitcroft @ 2008-03-06 10:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: David J. Wilder, linux-kernel, systemtap

On Wed, Mar 05, 2008 at 02:12:29PM -0800, Andrew Morton wrote:
> On Mon, 03 Mar 2008 15:51:50 -0800
> "David J. Wilder" <dwilder@us.ibm.com> wrote:
> 
> > This patch allows relay channels to be reset i.e. unconsumed.
> > Basically allows a 'rewind' function for flight-recorder tracing.
> > 
> > +void relay_reset_consumed(struct rchan *chan)
> > +{
> > +	unsigned int i;
> > +	struct rchan_buf *prev = NULL;
> > +
> > +	if (!chan)
> > +		return;
> > +
> > +	for (i = 0; i < NR_CPUS; i++) {
> 
> Use of NR_CPUS is usually wrong.  In this case it seems you should be using
> for_each_possible_cpu().
> 
> Also the existing usage of NR_CPUS in relay_subbufs_consumed() should be
> switched to using cpu_possible().
> 
> 
> New usage of NR_CPUS might be checkpatch-worthy, actually:
> 
> akpm:/usr/src/25> grep -l '^+.*NR_CPUS' patches/*.patch 
> patches/ext4-mm-mballoc-core.patch
> patches/git-kvm.patch
> patches/git-perfmon.patch
> patches/relay-reset-consumed.patch
> patches/x86-andi-git-x86.patch
> patches/x86-andi-smp-switch-optimize.patch
> 
> that's a sample of 1852 patches.
> 
> An appropriate warning would be "Usage of NR_CPUS is often wrong - should
> you be using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(),
> etc?".

That seems reasonable.  If we special case the definitions of NR_CPUS
and the use of them to define arrays of things both of which appear
reasonable,

	#define NR_CPUS 10
	int semid[NR_CPUS];

then it seems sensible to report this one:

	WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc
	#1: FILE: Z101.c:1:
	+       for (i = 0; i < NR_CPUS; i++)

This will be in the next push to -mm.

-apw

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch 1/3]  Relay Reset Consumed
@ 2008-02-26 22:38 David J. Wilder
  0 siblings, 0 replies; 5+ messages in thread
From: David J. Wilder @ 2008-02-26 22:38 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: systemtap, prasadav, hch

This patch allows relay channels to be reset i.e. unconsumed.
Basically allows a 'rewind' function for flight-recorder tracing.

Signed-off-by: Tom Zanussi <zanussi@us.ibm.com>
Signed-off-by: David Wilder <dwilder@us.ibm.com>
---
 Documentation/filesystems/relay.txt |   11 ++++++
 include/linux/relay.h               |    1 +
 kernel/relay.c                      |   58 ++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/Documentation/filesystems/relay.txt b/Documentation/filesystems/relay.txt
index 094f2d2..1af6d4b 100644
--- a/Documentation/filesystems/relay.txt
+++ b/Documentation/filesystems/relay.txt
@@ -161,6 +161,7 @@ TBD(curr. line MT:/API/)
     relay_close(chan)
     relay_flush(chan)
     relay_reset(chan)
+    relay_reset_consumed(chan)
 
   channel management typically called on instigation of userspace:
 
@@ -452,6 +453,16 @@ state without reallocating channel buffer memory or destroying
 existing mappings.  It should however only be called when it's safe to
 do so, i.e. when the channel isn't currently being written to.
 
+The read(2) implementation always 'consumes' the bytes read,
+i.e. those bytes won't be available again to subsequent reads.
+Certain applications may nonetheless wish to allow the 'consumed' data
+to be re-read; relay_reset_consumed() is provided for that purpose -
+it resets the internal consumed counters for all buffers in the
+channel.  For example, if a first set of reads 'drains' the channel,
+and then relay_reset_consumed() is called, a second set of reads will
+get the exact same data (assuming no new data was written between the
+first set of reads and the second).
+
 Finally, there are a couple of utility callbacks that can be used for
 different purposes.  buf_mapped() is called whenever a channel buffer
 is mmapped from user space and buf_unmapped() is called when it's
diff --git a/include/linux/relay.h b/include/linux/relay.h
index 6cd8c44..aca45fa 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -175,6 +175,7 @@ extern void relay_subbufs_consumed(struct rchan *chan,
 				   unsigned int cpu,
 				   size_t consumed);
 extern void relay_reset(struct rchan *chan);
+extern void relay_reset_consumed(struct rchan *chan);
 extern int relay_buf_full(struct rchan_buf *buf);
 
 extern size_t relay_switch_subbuf(struct rchan_buf *buf,
diff --git a/kernel/relay.c b/kernel/relay.c
index d080b9d..f9dc539 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -378,6 +378,57 @@ void relay_reset(struct rchan *chan)
 }
 EXPORT_SYMBOL_GPL(relay_reset);
 
+/**
+ *	__relay_reset_consumed - reset a channel buffer's consumed count
+ *	@buf: the channel buffer
+ *
+ *	See relay_reset_consumed for description of effect.
+ */
+static void __relay_reset_consumed(struct rchan_buf *buf)
+{
+	size_t n_subbufs = buf->chan->n_subbufs;
+	size_t produced = buf->subbufs_produced;
+	size_t consumed = buf->subbufs_consumed;
+
+	if (produced < n_subbufs)
+		buf->subbufs_consumed = 0;
+	else {
+		consumed = produced - n_subbufs;
+		if (buf->offset)
+			consumed++;
+		buf->subbufs_consumed = consumed;
+	}
+	buf->bytes_consumed = 0;
+}
+
+/**
+ *	relay_reset_consumed - reset the channel's consumed counts
+ *	@chan: the channel
+ *
+ *	This has the effect of making all data previously read (and
+ *	not overwritten by subsequent writes) from a channel available
+ *	for reading again.
+ *
+ *	NOTE: Care should be taken that the channel isn't actually
+ *	being used by anything when this call is made.
+ */
+void relay_reset_consumed(struct rchan *chan)
+{
+	unsigned int i;
+	struct rchan_buf *prev = NULL;
+
+	if (!chan)
+		return;
+
+	for (i = 0; i < NR_CPUS; i++) {
+		if (!chan->buf[i] || chan->buf[i] == prev)
+			break;
+		__relay_reset_consumed(chan->buf[i]);
+		prev = chan->buf[i];
+	}
+}
+EXPORT_SYMBOL_GPL(relay_reset_consumed);
+
 /*
  *	relay_open_buf - create a new relay channel buffer
  *
@@ -840,11 +891,8 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
 		return 1;
 	}
 
-	if (unlikely(produced - consumed >= n_subbufs)) {
-		consumed = produced - n_subbufs + 1;
-		buf->subbufs_consumed = consumed;
-		buf->bytes_consumed = 0;
-	}
+	if (unlikely(produced - consumed >= n_subbufs))
+		__relay_reset_consumed(buf);
 
 	produced = (produced % n_subbufs) * subbuf_size + buf->offset;
 	consumed = (consumed % n_subbufs) * subbuf_size + buf->bytes_consumed;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch 1/3]  Relay Reset Consumed
@ 2007-11-13  1:02 David J. Wilder
  0 siblings, 0 replies; 5+ messages in thread
From: David J. Wilder @ 2007-11-13  1:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: systemtap

This patch allows relay channels to be reset i.e. unconsumed.
Basically allows a 'rewind' function for flight-recorder tracing.

Signed-off-by: Tom Zanussi <zanussi@us.ibm.com>
Signed-off-by: David Wilder <dwilder@us.ibm.com>
---
 Documentation/filesystems/relay.txt |   11 ++++++
 include/linux/relay.h               |    1 +
 kernel/relay.c                      |   58 ++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/Documentation/filesystems/relay.txt b/Documentation/filesystems/relay.txt
index 18d23f9..d31113a 100644
--- a/Documentation/filesystems/relay.txt
+++ b/Documentation/filesystems/relay.txt
@@ -161,6 +161,7 @@ TBD(curr. line MT:/API/)
     relay_close(chan)
     relay_flush(chan)
     relay_reset(chan)
+    relay_reset_consumed(chan)
 
   channel management typically called on instigation of userspace:
 
@@ -452,6 +453,16 @@ state without reallocating channel buffer memory or destroying
 existing mappings.  It should however only be called when it's safe to
 do so, i.e. when the channel isn't currently being written to.
 
+The read(2) implementation always 'consumes' the bytes read,
+i.e. those bytes won't be available again to subsequent reads.
+Certain applications may nonetheless wish to allow the 'consumed' data
+to be re-read; relay_reset_consumed() is provided for that purpose -
+it resets the internal consumed counters for all buffers in the
+channel.  For example, if a first set of reads 'drains' the channel,
+and then relay_reset_consumed() is called, a second set of reads will
+get the exact same data (assuming no new data was written between the
+first set of reads and the second).
+
 Finally, there are a couple of utility callbacks that can be used for
 different purposes.  buf_mapped() is called whenever a channel buffer
 is mmapped from user space and buf_unmapped() is called when it's
diff --git a/include/linux/relay.h b/include/linux/relay.h
index 6cd8c44..aca45fa 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -175,6 +175,7 @@ extern void relay_subbufs_consumed(struct rchan *chan,
 				   unsigned int cpu,
 				   size_t consumed);
 extern void relay_reset(struct rchan *chan);
+extern void relay_reset_consumed(struct rchan *chan);
 extern int relay_buf_full(struct rchan_buf *buf);
 
 extern size_t relay_switch_subbuf(struct rchan_buf *buf,
diff --git a/kernel/relay.c b/kernel/relay.c
index 61134eb..654028e 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -383,6 +383,57 @@ void relay_reset(struct rchan *chan)
 }
 EXPORT_SYMBOL_GPL(relay_reset);
 
+/**
+ *	__relay_reset_consumed - reset a channel buffer's consumed count
+ *	@buf: the channel buffer
+ *
+ *	See relay_reset_consumed for description of effect.
+ */
+static void __relay_reset_consumed(struct rchan_buf *buf)
+{
+	size_t n_subbufs = buf->chan->n_subbufs;
+	size_t produced = buf->subbufs_produced;
+	size_t consumed = buf->subbufs_consumed;
+
+	if (produced < n_subbufs)
+		buf->subbufs_consumed = 0;
+	else {
+		consumed = produced - n_subbufs;
+		if (buf->offset)
+			consumed++;
+		buf->subbufs_consumed = consumed;
+	}
+	buf->bytes_consumed = 0;
+}
+
+/**
+ *	relay_reset_consumed - reset the channel's consumed counts
+ *	@chan: the channel
+ *
+ *	This has the effect of making all data previously read (and
+ *	not overwritten by subsequent writes) from a channel available
+ *	for reading again.
+ *
+ *	NOTE: Care should be taken that the channel isn't actually
+ *	being used by anything when this call is made.
+ */
+void relay_reset_consumed(struct rchan *chan)
+{
+	unsigned int i;
+	struct rchan_buf *prev = NULL;
+
+	if (!chan)
+		return;
+
+	for (i = 0; i < NR_CPUS; i++) {
+		if (!chan->buf[i] || chan->buf[i] == prev)
+			break;
+		__relay_reset_consumed(chan->buf[i]);
+		prev = chan->buf[i];
+	}
+}
+EXPORT_SYMBOL_GPL(relay_reset_consumed);
+
 /*
  *	relay_open_buf - create a new relay channel buffer
  *
@@ -845,11 +896,8 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
 		return 1;
 	}
 
-	if (unlikely(produced - consumed >= n_subbufs)) {
-		consumed = produced - n_subbufs + 1;
-		buf->subbufs_consumed = consumed;
-		buf->bytes_consumed = 0;
-	}
+	if (unlikely(produced - consumed >= n_subbufs))
+		__relay_reset_consumed(buf);
 
 	produced = (produced % n_subbufs) * subbuf_size + buf->offset;
 	consumed = (consumed % n_subbufs) * subbuf_size + buf->bytes_consumed;



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-06 11:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-03 23:51 [patch 1/3] Relay Reset Consumed David J. Wilder
2008-03-05 22:12 ` Andrew Morton
2008-03-06 10:56   ` Andy Whitcroft
  -- strict thread matches above, loose matches on Subject: below --
2008-02-26 22:38 David J. Wilder
2007-11-13  1:02 David J. Wilder

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 NNTP newsgroup(s).