linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] relay: Add global mode support for buffer-only channels
@ 2016-07-03 16:15 akash.goel
  2016-07-04  8:00 ` Chris Wilson
  0 siblings, 1 reply; 13+ messages in thread
From: akash.goel @ 2016-07-03 16:15 UTC (permalink / raw)
  To: linux-kernel, akpm, viro
  Cc: Akash Goel, Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

From: Akash Goel <akash.goel@intel.com>

The following patch added support to use channels with no associated files.
	relay: add buffer-only channels; useful for early logging
This is useful when the exact location of relay file is not known or the
the parent directory of relay file is not available, while creating the
channel and the logging has to start right from the boot.

But there was no provision to use global mode with buffer-only channels,
which is added by this patch, without modifying the interface where initially
there will be a dummy invocation of create_buf_file callback through which
kernel client can convey the need of a global buffer.

For the use case where drivers/kernel clients want a simple interface for the
userspace, which enables them to capture data/logs from relay file in order &
without any post processing, support of Global buffer mode is warranted.

Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Akash Goel <akash.goel@intel.com>
---
 kernel/relay.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/kernel/relay.c b/kernel/relay.c
index 04d7cf3..b267384 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -451,6 +451,16 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
 		if (!dentry)
 			goto free_buf;
 		relay_set_buf_dentry(buf, dentry);
+	} else {
+		dentry = chan->cb->create_buf_file(NULL, NULL,
+					S_IRUSR, buf,
+					&chan->is_global);
+		/* We did not expected the client to return a valid dentry,
+		 * was now just looking for the global info from the client.
+		 * Now onus is on client only to release this dentry pointer.
+		 */
+		if (WARN_ON(dentry))
+			goto free_buf;
 	}
 
  	buf->cpu = cpu;
@@ -666,6 +676,27 @@ int relay_late_setup_files(struct rchan *chan,
 	}
 	chan->has_base_filename = 1;
 	chan->parent = parent;
+
+	if (chan->is_global) {
+		if (unlikely(!chan->buf[0])) {
+			WARN_ONCE(1, KERN_ERR "CPU 0 has no buffer!\n");
+			mutex_unlock(&relay_channels_mutex);
+			return -EINVAL;
+                }
+
+		dentry = relay_create_buf_file(chan, chan->buf[0], 0);
+
+		if (unlikely(!dentry))
+			err = -EINVAL;
+		else if (WARN_ON(!chan->is_global))
+			err = -EINVAL;
+		else
+			relay_set_buf_dentry(chan->buf[0], dentry);
+
+		mutex_unlock(&relay_channels_mutex);
+		return err;
+	}
+
 	curr_cpu = get_cpu();
 	/*
 	 * The CPU hotplug notifier ran before us and created buffers with
@@ -706,6 +737,7 @@ int relay_late_setup_files(struct rchan *chan,
 
 	return err;
 }
+EXPORT_SYMBOL_GPL(relay_late_setup_files);
 
 /**
  *	relay_switch_subbuf - switch to a new sub-buffer
-- 
1.9.2

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

* Re: [PATCH] relay: Add global mode support for buffer-only channels
  2016-07-03 16:15 [PATCH] relay: Add global mode support for buffer-only channels akash.goel
@ 2016-07-04  8:00 ` Chris Wilson
  2016-07-04 13:03   ` Goel, Akash
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Wilson @ 2016-07-04  8:00 UTC (permalink / raw)
  To: akash.goel
  Cc: linux-kernel, akpm, viro, Eduard - Gabriel Munteanu, Tom Zanussi

On Sun, Jul 03, 2016 at 09:45:27PM +0530, akash.goel@intel.com wrote:
> From: Akash Goel <akash.goel@intel.com>
> 
> The following patch added support to use channels with no associated files.
> 	relay: add buffer-only channels; useful for early logging
> This is useful when the exact location of relay file is not known or the
> the parent directory of relay file is not available, while creating the
> channel and the logging has to start right from the boot.
> 
> But there was no provision to use global mode with buffer-only channels,
> which is added by this patch, without modifying the interface where initially
> there will be a dummy invocation of create_buf_file callback through which
> kernel client can convey the need of a global buffer.
> 
> For the use case where drivers/kernel clients want a simple interface for the
> userspace, which enables them to capture data/logs from relay file in order &
> without any post processing, support of Global buffer mode is warranted.
> 
> Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
> Cc: Tom Zanussi <tzanussi@gmail.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Akash Goel <akash.goel@intel.com>
> ---
>  kernel/relay.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/kernel/relay.c b/kernel/relay.c
> index 04d7cf3..b267384 100644
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -451,6 +451,16 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
>  		if (!dentry)
>  			goto free_buf;
>  		relay_set_buf_dentry(buf, dentry);
> +	} else {

The trailing block can be replaced with:

		/* Only retrieve global info, nothing more, nothing less */

> +		dentry = chan->cb->create_buf_file(NULL, NULL,
> +					S_IRUSR, buf,
> +					&chan->is_global);

Watch alignment, align to the opening bracket.

> +		if (WARN_ON(dentry))
> +			goto free_buf;
>  	}
>  
>   	buf->cpu = cpu;
> @@ -666,6 +676,27 @@ int relay_late_setup_files(struct rchan *chan,
>  	}
>  	chan->has_base_filename = 1;
>  	chan->parent = parent;
> +
> +	if (chan->is_global) {
> +		if (unlikely(!chan->buf[0])) {

if (WARN_ON_ONCE(!chan->buf[0])) {

> +			WARN_ONCE(1, KERN_ERR "CPU 0 has no buffer!\n");

The WARN includes the unlikely and the message here isn't any more
informative than the line itself, plus has the erroneous KERN_ERR

> +			mutex_unlock(&relay_channels_mutex);
> +			return -EINVAL;
> +                }
> +
> +		dentry = relay_create_buf_file(chan, chan->buf[0], 0);
> +
> +		if (unlikely(!dentry))
> +			err = -EINVAL;
> +		else if (WARN_ON(!chan->is_global))

?

> +			err = -EINVAL;
> +		else
> +			relay_set_buf_dentry(chan->buf[0], dentry);
> +
> +		mutex_unlock(&relay_channels_mutex);
> +		return err;

This could be written:

if (chan->is_global) {
	err = -EINVAL;
	if (!WARN_ON_ONCE(!chan->buf[0])) {
		dentry = relay_create_buf_file(chan, chan->buf[0], 0))
		if (dentry) {
			relay_set_buf_dentry(chan->buf[0], dentry);
			err = 0;
		}
	}
	mutex_unlock();
	return err;
}

for a single exit/unlock path in this block.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

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

* Re: [PATCH] relay: Add global mode support for buffer-only channels
  2016-07-04  8:00 ` Chris Wilson
@ 2016-07-04 13:03   ` Goel, Akash
  2016-07-11  7:17     ` [PATCH v2] " akash.goel
  0 siblings, 1 reply; 13+ messages in thread
From: Goel, Akash @ 2016-07-04 13:03 UTC (permalink / raw)
  To: Chris Wilson
  Cc: linux-kernel, akpm, viro, Eduard - Gabriel Munteanu, Tom Zanussi,
	akash.goel



On 7/4/2016 1:30 PM, Chris Wilson wrote:
> On Sun, Jul 03, 2016 at 09:45:27PM +0530, akash.goel@intel.com wrote:
>> From: Akash Goel <akash.goel@intel.com>
>>
>> The following patch added support to use channels with no associated files.
>> 	relay: add buffer-only channels; useful for early logging
>> This is useful when the exact location of relay file is not known or the
>> the parent directory of relay file is not available, while creating the
>> channel and the logging has to start right from the boot.
>>
>> But there was no provision to use global mode with buffer-only channels,
>> which is added by this patch, without modifying the interface where initially
>> there will be a dummy invocation of create_buf_file callback through which
>> kernel client can convey the need of a global buffer.
>>
>> For the use case where drivers/kernel clients want a simple interface for the
>> userspace, which enables them to capture data/logs from relay file in order &
>> without any post processing, support of Global buffer mode is warranted.
>>
>> Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
>> Cc: Tom Zanussi <tzanussi@gmail.com>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Signed-off-by: Akash Goel <akash.goel@intel.com>
>> ---
>>  kernel/relay.c | 32 ++++++++++++++++++++++++++++++++
>>  1 file changed, 32 insertions(+)
>>
>> diff --git a/kernel/relay.c b/kernel/relay.c
>> index 04d7cf3..b267384 100644
>> --- a/kernel/relay.c
>> +++ b/kernel/relay.c
>> @@ -451,6 +451,16 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
>>  		if (!dentry)
>>  			goto free_buf;
>>  		relay_set_buf_dentry(buf, dentry);
>> +	} else {
>
> The trailing block can be replaced with:
>
> 		/* Only retrieve global info, nothing more, nothing less */
>

Thanks, will do like this.
>> +		dentry = chan->cb->create_buf_file(NULL, NULL,
>> +					S_IRUSR, buf,
>> +					&chan->is_global);
>
> Watch alignment, align to the opening bracket.
>
>> +		if (WARN_ON(dentry))
>> +			goto free_buf;
>>  	}
>>
>>   	buf->cpu = cpu;
>> @@ -666,6 +676,27 @@ int relay_late_setup_files(struct rchan *chan,
>>  	}
>>  	chan->has_base_filename = 1;
>>  	chan->parent = parent;
>> +
>> +	if (chan->is_global) {
>> +		if (unlikely(!chan->buf[0])) {
>
> if (WARN_ON_ONCE(!chan->buf[0])) {
>
>> +			WARN_ONCE(1, KERN_ERR "CPU 0 has no buffer!\n");
>
> The WARN includes the unlikely and the message here isn't any more
> informative than the line itself, plus has the erroneous KERN_ERR
>
Thanks will combine the WARN and if check.

>> +			mutex_unlock(&relay_channels_mutex);
>> +			return -EINVAL;
>> +                }
>> +
>> +		dentry = relay_create_buf_file(chan, chan->buf[0], 0);
>> +
>> +		if (unlikely(!dentry))
>> +			err = -EINVAL;
>> +		else if (WARN_ON(!chan->is_global))
>
> ?
>

Though have checked 'is_global' value before, but can't rule out the
clients toggling its value (inadvertently or maliciously).

Actually create_buf_file() callback will be invoked again from the
relay_create_buf_file() and pointer of 'chan->is_global' is passed in
that.
So to be on safer side, thought to validate the 'chan->is_global' value 
after the call to relay_create_buf_file().

>> +			err = -EINVAL;
>> +		else
>> +			relay_set_buf_dentry(chan->buf[0], dentry);
>> +
>> +		mutex_unlock(&relay_channels_mutex);
>> +		return err;
>
> This could be written:
>
Thanks this is much better.


Best Regards
Akash

> if (chan->is_global) {
> 	err = -EINVAL;
> 	if (!WARN_ON_ONCE(!chan->buf[0])) {
> 		dentry = relay_create_buf_file(chan, chan->buf[0], 0))
> 		if (dentry) {
> 			relay_set_buf_dentry(chan->buf[0], dentry);
> 			err = 0;
> 		}
> 	}
> 	mutex_unlock();
> 	return err;
> }
>
> for a single exit/unlock path in this block.
> -Chris
>

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

* [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-04 13:03   ` Goel, Akash
@ 2016-07-11  7:17     ` akash.goel
  2016-07-11 20:17       ` Andrew Morton
  0 siblings, 1 reply; 13+ messages in thread
From: akash.goel @ 2016-07-11  7:17 UTC (permalink / raw)
  To: linux-kernel, akpm, viro
  Cc: Akash Goel, Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

From: Akash Goel <akash.goel@intel.com>

The following patch added support to use channels with no associated files.
	relay: add buffer-only channels; useful for early logging
This is useful when the exact location of relay file is not known or the
the parent directory of relay file is not available, while creating the
channel and the logging has to start right from the boot.

But there was no provision to use global mode with buffer-only channels,
which is added by this patch, without modifying the interface where initially
there will be a dummy invocation of create_buf_file callback through which
kernel client can convey the need of a global buffer.

For the use case where drivers/kernel clients want a simple interface for the
userspace, which enables them to capture data/logs from relay file in order &
without any post processing, support of Global buffer mode is warranted.

v2: Minor refactoring of code & rephrase the comment to be succinct. (Chris)

Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Akash Goel <akash.goel@intel.com>
---
 kernel/relay.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/kernel/relay.c b/kernel/relay.c
index 04d7cf3..92db973 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -451,6 +451,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
 		if (!dentry)
 			goto free_buf;
 		relay_set_buf_dentry(buf, dentry);
+	} else {
+		/* Only retrieve global info, nothing more, nothing less */
+		dentry = chan->cb->create_buf_file(NULL, NULL,
+						   S_IRUSR, buf,
+						   &chan->is_global);
+		if (WARN_ON(dentry))
+			goto free_buf;
 	}
 
  	buf->cpu = cpu;
@@ -666,6 +673,20 @@ int relay_late_setup_files(struct rchan *chan,
 	}
 	chan->has_base_filename = 1;
 	chan->parent = parent;
+
+	if (chan->is_global) {
+		err = -EINVAL;
+		if (!WARN_ON_ONCE(!chan->buf[0])) {
+			dentry = relay_create_buf_file(chan, chan->buf[0], 0);
+			if (dentry && !WARN_ON_ONCE(!chan->is_global)) {
+				relay_set_buf_dentry(chan->buf[0], dentry);
+				err = 0;
+			}
+		}
+		mutex_unlock(&relay_channels_mutex);
+		return err;
+	}
+
 	curr_cpu = get_cpu();
 	/*
 	 * The CPU hotplug notifier ran before us and created buffers with
@@ -706,6 +727,7 @@ int relay_late_setup_files(struct rchan *chan,
 
 	return err;
 }
+EXPORT_SYMBOL_GPL(relay_late_setup_files);
 
 /**
  *	relay_switch_subbuf - switch to a new sub-buffer
-- 
1.9.2

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-11  7:17     ` [PATCH v2] " akash.goel
@ 2016-07-11 20:17       ` Andrew Morton
  2016-07-12  9:24         ` Chris Wilson
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2016-07-11 20:17 UTC (permalink / raw)
  To: akash.goel
  Cc: linux-kernel, viro, Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

On Mon, 11 Jul 2016 12:47:36 +0530 akash.goel@intel.com wrote:

> From: Akash Goel <akash.goel@intel.com>
> 
> The following patch added support to use channels with no associated files.
> 	relay: add buffer-only channels; useful for early logging

hm, 8 years ago.  Normally we refer to previous commits using the form
20d8b67c06fa5e74f44e ("relay: add buffer-only channels; useful for
early logging").  But this one is so old that we should inform readers
about its vintage, so this form:

commit 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a
Author: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Date:   Fri Jul 25 19:45:12 2008 -0700

    relay: add buffer-only channels; useful for early logging

would be better.

> This is useful when the exact location of relay file is not known or the
> the parent directory of relay file is not available, while creating the
> channel and the logging has to start right from the boot.
> 
> But there was no provision to use global mode with buffer-only channels,
> which is added by this patch, without modifying the interface where initially
> there will be a dummy invocation of create_buf_file callback through which
> kernel client can convey the need of a global buffer.
> 
> For the use case where drivers/kernel clients want a simple interface for the
> userspace, which enables them to capture data/logs from relay file in order &
> without any post processing, support of Global buffer mode is warranted.
>
> ...
>
> @@ -706,6 +727,7 @@ int relay_late_setup_files(struct rchan *chan,
>  
>  	return err;
>  }
> +EXPORT_SYMBOL_GPL(relay_late_setup_files);

The export is unneeded and undocumented.

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-11 20:17       ` Andrew Morton
@ 2016-07-12  9:24         ` Chris Wilson
  2016-07-12 12:50           ` Goel, Akash
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Wilson @ 2016-07-12  9:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: akash.goel, linux-kernel, viro, Eduard - Gabriel Munteanu, Tom Zanussi

On Mon, Jul 11, 2016 at 01:17:09PM -0700, Andrew Morton wrote:
> On Mon, 11 Jul 2016 12:47:36 +0530 akash.goel@intel.com wrote:
> 
> > From: Akash Goel <akash.goel@intel.com>
> > 
> > The following patch added support to use channels with no associated files.
> > 	relay: add buffer-only channels; useful for early logging
> 
> hm, 8 years ago.  Normally we refer to previous commits using the form
> 20d8b67c06fa5e74f44e ("relay: add buffer-only channels; useful for
> early logging").  But this one is so old that we should inform readers
> about its vintage, so this form:
> 
> commit 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a
> Author: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
> Date:   Fri Jul 25 19:45:12 2008 -0700
> 
>     relay: add buffer-only channels; useful for early logging
> 
> would be better.
> 
> > This is useful when the exact location of relay file is not known or the
> > the parent directory of relay file is not available, while creating the
> > channel and the logging has to start right from the boot.
> > 
> > But there was no provision to use global mode with buffer-only channels,
> > which is added by this patch, without modifying the interface where initially
> > there will be a dummy invocation of create_buf_file callback through which
> > kernel client can convey the need of a global buffer.
> > 
> > For the use case where drivers/kernel clients want a simple interface for the
> > userspace, which enables them to capture data/logs from relay file in order &
> > without any post processing, support of Global buffer mode is warranted.
> >
> > ...
> >
> > @@ -706,6 +727,7 @@ int relay_late_setup_files(struct rchan *chan,
> >  
> >  	return err;
> >  }
> > +EXPORT_SYMBOL_GPL(relay_late_setup_files);
> 
> The export is unneeded and undocumented.

Something like:

diff --git a/kernel/relay.c b/kernel/relay.c
index 04d7cf3ef8cf..fd86f01de4b2 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -562,6 +562,10 @@ static int relay_hotcpu_callback(struct notifier_block *nb,
  *     attributes specified.  The created channel buffer files
  *     will be named base_filename0...base_filenameN-1.  File
  *     permissions will be %S_IRUSR.
+ *
+ *     If opening a buffer (@parent = NULL) that you later wish to register
+ *     in a filesystem, call relay_late_setup_files() once the @parent dentry
+ *     is available.
  */
 struct rchan *relay_open(const char *base_filename,
                         struct dentry *parent,
@@ -640,8 +644,12 @@ static void __relay_set_buf_dentry(void *info)
  *
  *     Returns 0 if successful, non-zero otherwise.
  *
- *     Use to setup files for a previously buffer-only channel.
- *     Useful to do early tracing in kernel, before VFS is up, for example.
+ *     Use to setup files for a previously buffer-only channel created
+ *     by relay_open() with a NULL parent dentry.
+ *
+ *     For example, this is useful for perfomring early tracing in kernel,
+ *     before VFS is up and then exposing the early results once the dentry
+ *     is available.
  */
 int relay_late_setup_files(struct rchan *chan,
                           const char *base_filename,


with a comment in the changelog that modules using relay_open() in early
init also want to later register their buffer-only relays once debugfs is
available, e.g. i915.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-12  9:24         ` Chris Wilson
@ 2016-07-12 12:50           ` Goel, Akash
  2016-07-12 13:01             ` Chris Wilson
  0 siblings, 1 reply; 13+ messages in thread
From: Goel, Akash @ 2016-07-12 12:50 UTC (permalink / raw)
  To: Chris Wilson, Andrew Morton
  Cc: linux-kernel, viro, Eduard - Gabriel Munteanu, Tom Zanussi, akash.goel



On 7/12/2016 2:54 PM, Chris Wilson wrote:
> On Mon, Jul 11, 2016 at 01:17:09PM -0700, Andrew Morton wrote:
>> On Mon, 11 Jul 2016 12:47:36 +0530 akash.goel@intel.com wrote:
>>
>>> From: Akash Goel <akash.goel@intel.com>
>>>
>>> The following patch added support to use channels with no associated files.
>>> 	relay: add buffer-only channels; useful for early logging
>>
>> hm, 8 years ago.  Normally we refer to previous commits using the form
>> 20d8b67c06fa5e74f44e ("relay: add buffer-only channels; useful for
>> early logging").  But this one is so old that we should inform readers
>> about its vintage, so this form:
>>
>> commit 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a
>> Author: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
>> Date:   Fri Jul 25 19:45:12 2008 -0700
>>
>>     relay: add buffer-only channels; useful for early logging
>>
>> would be better.
>>
>>> This is useful when the exact location of relay file is not known or the
>>> the parent directory of relay file is not available, while creating the
>>> channel and the logging has to start right from the boot.
>>>
>>> But there was no provision to use global mode with buffer-only channels,
>>> which is added by this patch, without modifying the interface where initially
>>> there will be a dummy invocation of create_buf_file callback through which
>>> kernel client can convey the need of a global buffer.
>>>
>>> For the use case where drivers/kernel clients want a simple interface for the
>>> userspace, which enables them to capture data/logs from relay file in order &
>>> without any post processing, support of Global buffer mode is warranted.
>>>
>>> ...
>>>
>>> @@ -706,6 +727,7 @@ int relay_late_setup_files(struct rchan *chan,
>>>
>>>  	return err;
>>>  }
>>> +EXPORT_SYMBOL_GPL(relay_late_setup_files);
>>
>> The export is unneeded and undocumented.
>
> Something like:
>
> diff --git a/kernel/relay.c b/kernel/relay.c
> index 04d7cf3ef8cf..fd86f01de4b2 100644
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -562,6 +562,10 @@ static int relay_hotcpu_callback(struct notifier_block *nb,
>   *     attributes specified.  The created channel buffer files
>   *     will be named base_filename0...base_filenameN-1.  File
>   *     permissions will be %S_IRUSR.
> + *
> + *     If opening a buffer (@parent = NULL) that you later wish to register
> + *     in a filesystem, call relay_late_setup_files() once the @parent dentry
> + *     is available.
>   */
>  struct rchan *relay_open(const char *base_filename,
>                          struct dentry *parent,
> @@ -640,8 +644,12 @@ static void __relay_set_buf_dentry(void *info)
>   *
>   *     Returns 0 if successful, non-zero otherwise.
>   *
> - *     Use to setup files for a previously buffer-only channel.
> - *     Useful to do early tracing in kernel, before VFS is up, for example.
> + *     Use to setup files for a previously buffer-only channel created
> + *     by relay_open() with a NULL parent dentry.
> + *
> + *     For example, this is useful for perfomring early tracing in kernel,
> + *     before VFS is up and then exposing the early results once the dentry
> + *     is available.
>   */
>  int relay_late_setup_files(struct rchan *chan,
>                            const char *base_filename,
>
>
> with a comment in the changelog that modules using relay_open() in early
> init also want to later register their buffer-only relays once debugfs is
> available, e.g. i915.

Thanks much, will update the documentation as well as the changelog as 
per the above.

But an export of symbol relay_late_setup_files() is still needed, just
like relay_open() is exported, in order to make it accessible to modules 
like i915 ?

Best regards
Akash


> -Chris
>

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-12 12:50           ` Goel, Akash
@ 2016-07-12 13:01             ` Chris Wilson
  2016-07-12 13:24               ` Goel, Akash
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Wilson @ 2016-07-12 13:01 UTC (permalink / raw)
  To: Goel, Akash
  Cc: Andrew Morton, linux-kernel, viro, Eduard - Gabriel Munteanu,
	Tom Zanussi

On Tue, Jul 12, 2016 at 06:20:06PM +0530, Goel, Akash wrote:
> Thanks much, will update the documentation as well as the changelog
> as per the above.
> 
> But an export of symbol relay_late_setup_files() is still needed, just
> like relay_open() is exported, in order to make it accessible to
> modules like i915 ?

Yes, we need the companion function in i915.ko. That needs to be
explained in the patch notes to justify adding the EXPORT_SYMBOL.
Otherwise without that context, it looks unnecessary as Andrew objected
to.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-12 13:01             ` Chris Wilson
@ 2016-07-12 13:24               ` Goel, Akash
  2016-07-12 19:51                 ` Andrew Morton
  0 siblings, 1 reply; 13+ messages in thread
From: Goel, Akash @ 2016-07-12 13:24 UTC (permalink / raw)
  To: Chris Wilson
  Cc: Andrew Morton, linux-kernel, viro, Eduard - Gabriel Munteanu,
	Tom Zanussi, akash.goel



On 7/12/2016 6:31 PM, Chris Wilson wrote:
> On Tue, Jul 12, 2016 at 06:20:06PM +0530, Goel, Akash wrote:
>> Thanks much, will update the documentation as well as the changelog
>> as per the above.
>>
>> But an export of symbol relay_late_setup_files() is still needed, just
>> like relay_open() is exported, in order to make it accessible to
>> modules like i915 ?
>
> Yes, we need the companion function in i915.ko. That needs to be
> explained in the patch notes to justify adding the EXPORT_SYMBOL.
> Otherwise without that context, it looks unnecessary as Andrew objected
> to.

Won't your suggested updates to Documentation & changelog suffice ?.
relay_late_setup_files() is to be used in conjunction with
relay_open(), hence need to be exported.

Do I also need to provide the corresponding i915 patch, which has a
call to relay_late_setup_files() ?

Best regards
Akash

> -Chris
>

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

* Re: [PATCH v2] relay: Add global mode support for buffer-only channels
  2016-07-12 13:24               ` Goel, Akash
@ 2016-07-12 19:51                 ` Andrew Morton
  2016-07-13  7:39                   ` [PATCH v3] " akash.goel
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2016-07-12 19:51 UTC (permalink / raw)
  To: Goel, Akash
  Cc: Chris Wilson, linux-kernel, viro, Eduard - Gabriel Munteanu, Tom Zanussi

On Tue, 12 Jul 2016 18:54:49 +0530 "Goel, Akash" <akash.goel@intel.com> wrote:

> 
> 
> On 7/12/2016 6:31 PM, Chris Wilson wrote:
> > On Tue, Jul 12, 2016 at 06:20:06PM +0530, Goel, Akash wrote:
> >> Thanks much, will update the documentation as well as the changelog
> >> as per the above.
> >>
> >> But an export of symbol relay_late_setup_files() is still needed, just
> >> like relay_open() is exported, in order to make it accessible to
> >> modules like i915 ?
> >
> > Yes, we need the companion function in i915.ko. That needs to be
> > explained in the patch notes to justify adding the EXPORT_SYMBOL.
> > Otherwise without that context, it looks unnecessary as Andrew objected
> > to.
> 
> Won't your suggested updates to Documentation & changelog suffice ?.
> relay_late_setup_files() is to be used in conjunction with
> relay_open(), hence need to be exported.
> 
> Do I also need to provide the corresponding i915 patch, which has a
> call to relay_late_setup_files() ?

No, as long as i915 people promise to use the export, a note in the
changelog is sufficient.

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

* [PATCH v3] relay: Add global mode support for buffer-only channels
  2016-07-12 19:51                 ` Andrew Morton
@ 2016-07-13  7:39                   ` akash.goel
  2016-07-13  8:30                     ` kbuild test robot
  0 siblings, 1 reply; 13+ messages in thread
From: akash.goel @ 2016-07-13  7:39 UTC (permalink / raw)
  To: linux-kernel, akpm, viro
  Cc: Akash Goel, Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

From: Akash Goel <akash.goel@intel.com>

The following patch added support to use channels with no associated files.
	commit 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a
	Author: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
	Date:   Fri Jul 25 19:45:12 2008 -0700

		relay: add buffer-only channels; useful for early logging

This is useful when the exact location of relay file is not known or the
the parent directory of relay file is not available, while creating the
channel and the logging has to start right from the boot.

But there was no provision to use global mode with buffer-only channels,
which is added by this patch, without modifying the interface where initially
there will be a dummy invocation of create_buf_file callback through which
kernel client can convey the need of a global buffer.

For the use case where drivers/kernel clients want a simple interface for the
userspace, which enables them to capture data/logs from relay file inorder &
without any post processing, support of Global buffer mode is warranted.

Modules, like i915, using relay_open() in early init would have to later
register their buffer-only relays, once debugfs is available, by calling
relay_late_setup_files(). Hence relay_late_setup_files() symbol also needs
to be exported.

v2: Minor refactoring of code & rephrase the comment to be succinct. (Chris)

v3:
- Update the documentation & changelog to clarify about the need for
  exporting of relay_late_setup_files() symbol. (Chris)
- Elaborate the description of the parent patch. (Andrew)

Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Akash Goel <akash.goel@intel.com>
---
 kernel/relay.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index 04d7cf3..000c7bc 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -451,6 +451,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
 		if (!dentry)
 			goto free_buf;
 		relay_set_buf_dentry(buf, dentry);
+	} else {
+		/* Only retrieve global info, nothing more, nothing less */
+		dentry = chan->cb->create_buf_file(NULL, NULL,
+						   S_IRUSR, buf,
+						   &chan->is_global);
+		if (WARN_ON(dentry))
+			goto free_buf;
 	}
 
  	buf->cpu = cpu;
@@ -562,6 +569,10 @@ static int relay_hotcpu_callback(struct notifier_block *nb,
  *	attributes specified.  The created channel buffer files
  *	will be named base_filename0...base_filenameN-1.  File
  *	permissions will be %S_IRUSR.
+
+ *	If opening a buffer (@parent = NULL) that you later wish to register
+ *	in a filesystem, call relay_late_setup_files() once the @parent dentry
+ *	is available.
  */
 struct rchan *relay_open(const char *base_filename,
 			 struct dentry *parent,
@@ -640,8 +651,12 @@ static void __relay_set_buf_dentry(void *info)
  *
  *	Returns 0 if successful, non-zero otherwise.
  *
- *	Use to setup files for a previously buffer-only channel.
- *	Useful to do early tracing in kernel, before VFS is up, for example.
+ *	Use to setup files for a previously buffer-only channel created
+ *	by relay_open() with a NULL parent dentry.
+ *
+ *	For example, this is useful for perfomring early tracing in kernel,
+ *	before VFS is up and then exposing the early results once the dentry
+ *	is available.
  */
 int relay_late_setup_files(struct rchan *chan,
 			   const char *base_filename,
@@ -666,6 +681,20 @@ int relay_late_setup_files(struct rchan *chan,
 	}
 	chan->has_base_filename = 1;
 	chan->parent = parent;
+
+	if (chan->is_global) {
+		err = -EINVAL;
+		if (!WARN_ON_ONCE(!chan->buf[0])) {
+			dentry = relay_create_buf_file(chan, chan->buf[0], 0);
+			if (dentry && !WARN_ON_ONCE(!chan->is_global)) {
+				relay_set_buf_dentry(chan->buf[0], dentry);
+				err = 0;
+			}
+		}
+		mutex_unlock(&relay_channels_mutex);
+		return err;
+	}
+
 	curr_cpu = get_cpu();
 	/*
 	 * The CPU hotplug notifier ran before us and created buffers with
@@ -706,6 +735,7 @@ int relay_late_setup_files(struct rchan *chan,
 
 	return err;
 }
+EXPORT_SYMBOL_GPL(relay_late_setup_files);
 
 /**
  *	relay_switch_subbuf - switch to a new sub-buffer
-- 
1.9.2

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

* Re: [PATCH v3] relay: Add global mode support for buffer-only channels
  2016-07-13  7:39                   ` [PATCH v3] " akash.goel
@ 2016-07-13  8:30                     ` kbuild test robot
  2016-07-13 10:09                       ` [PATCH v4] " akash.goel
  0 siblings, 1 reply; 13+ messages in thread
From: kbuild test robot @ 2016-07-13  8:30 UTC (permalink / raw)
  To: akash.goel
  Cc: kbuild-all, linux-kernel, akpm, viro, Akash Goel,
	Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

[-- Attachment #1: Type: text/plain, Size: 2150 bytes --]

Hi,

[auto build test WARNING on v4.7-rc7]
[also build test WARNING on next-20160712]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/akash-goel-intel-com/relay-Add-global-mode-support-for-buffer-only-channels/20160713-153432
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   lib/crc32.c:148: warning: No description found for parameter 'tab)[256]'
   lib/crc32.c:148: warning: Excess function parameter 'tab' description in 'crc32_le_generic'
   lib/crc32.c:293: warning: No description found for parameter 'tab)[256]'
   lib/crc32.c:293: warning: Excess function parameter 'tab' description in 'crc32_be_generic'
   lib/crc32.c:1: warning: no structured comments found
>> kernel/relay.c:572: warning: bad line: 
>> kernel/relay.c:572: warning: bad line: 

vim +572 kernel/relay.c

   556	
   557	/**
   558	 *	relay_open - create a new relay channel
   559	 *	@base_filename: base name of files to create, %NULL for buffering only
   560	 *	@parent: dentry of parent directory, %NULL for root directory or buffer
   561	 *	@subbuf_size: size of sub-buffers
   562	 *	@n_subbufs: number of sub-buffers
   563	 *	@cb: client callback functions
   564	 *	@private_data: user-defined data
   565	 *
   566	 *	Returns channel pointer if successful, %NULL otherwise.
   567	 *
   568	 *	Creates a channel buffer for each cpu using the sizes and
   569	 *	attributes specified.  The created channel buffer files
   570	 *	will be named base_filename0...base_filenameN-1.  File
   571	 *	permissions will be %S_IRUSR.
 > 572	
   573	 *	If opening a buffer (@parent = NULL) that you later wish to register
   574	 *	in a filesystem, call relay_late_setup_files() once the @parent dentry
   575	 *	is available.
   576	 */
   577	struct rchan *relay_open(const char *base_filename,
   578				 struct dentry *parent,
   579				 size_t subbuf_size,
   580				 size_t n_subbufs,

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 6370 bytes --]

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

* [PATCH v4] relay: Add global mode support for buffer-only channels
  2016-07-13  8:30                     ` kbuild test robot
@ 2016-07-13 10:09                       ` akash.goel
  0 siblings, 0 replies; 13+ messages in thread
From: akash.goel @ 2016-07-13 10:09 UTC (permalink / raw)
  To: linux-kernel, akpm, viro
  Cc: Akash Goel, Eduard - Gabriel Munteanu, Tom Zanussi, Chris Wilson

From: Akash Goel <akash.goel@intel.com>

The following patch added support to use channels with no associated files.
	commit 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a
	Author: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
	Date:   Fri Jul 25 19:45:12 2008 -0700

		relay: add buffer-only channels; useful for early logging

This is useful when the exact location of relay file is not known or the
the parent directory of relay file is not available, while creating the
channel and the logging has to start right from the boot.

But there was no provision to use global mode with buffer-only channels,
which is added by this patch, without modifying the interface where initially
there will be a dummy invocation of create_buf_file callback through which
kernel client can convey the need of a global buffer.

For the use case where drivers/kernel clients want a simple interface for the
userspace, which enables them to capture data/logs from relay file inorder &
without any post processing, support of Global buffer mode is warranted.

Modules, like i915, using relay_open() in early init would have to later
register their buffer-only relays, once debugfs is available, by calling
relay_late_setup_files(). Hence relay_late_setup_files() symbol also needs
to be exported.

v2: Minor refactoring of code & rephrase the comment to be succinct. (Chris)

v3:
- Update the documentation & changelog to clarify about the need for
  exporting of relay_late_setup_files() symbol. (Chris)
- Elaborate the description of the parent patch. (Andrew)

v4: Fix the bad line warning issue with multi line comments.

Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Akash Goel <akash.goel@intel.com>
---
 kernel/relay.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index 04d7cf3..d797502 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -451,6 +451,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
 		if (!dentry)
 			goto free_buf;
 		relay_set_buf_dentry(buf, dentry);
+	} else {
+		/* Only retrieve global info, nothing more, nothing less */
+		dentry = chan->cb->create_buf_file(NULL, NULL,
+						   S_IRUSR, buf,
+						   &chan->is_global);
+		if (WARN_ON(dentry))
+			goto free_buf;
 	}
 
  	buf->cpu = cpu;
@@ -562,6 +569,10 @@ static int relay_hotcpu_callback(struct notifier_block *nb,
  *	attributes specified.  The created channel buffer files
  *	will be named base_filename0...base_filenameN-1.  File
  *	permissions will be %S_IRUSR.
+ *
+ *	If opening a buffer (@parent = NULL) that you later wish to register
+ *	in a filesystem, call relay_late_setup_files() once the @parent dentry
+ *	is available.
  */
 struct rchan *relay_open(const char *base_filename,
 			 struct dentry *parent,
@@ -640,8 +651,12 @@ static void __relay_set_buf_dentry(void *info)
  *
  *	Returns 0 if successful, non-zero otherwise.
  *
- *	Use to setup files for a previously buffer-only channel.
- *	Useful to do early tracing in kernel, before VFS is up, for example.
+ *	Use to setup files for a previously buffer-only channel created
+ *	by relay_open() with a NULL parent dentry.
+ *
+ *	For example, this is useful for perfomring early tracing in kernel,
+ *	before VFS is up and then exposing the early results once the dentry
+ *	is available.
  */
 int relay_late_setup_files(struct rchan *chan,
 			   const char *base_filename,
@@ -666,6 +681,20 @@ int relay_late_setup_files(struct rchan *chan,
 	}
 	chan->has_base_filename = 1;
 	chan->parent = parent;
+
+	if (chan->is_global) {
+		err = -EINVAL;
+		if (!WARN_ON_ONCE(!chan->buf[0])) {
+			dentry = relay_create_buf_file(chan, chan->buf[0], 0);
+			if (dentry && !WARN_ON_ONCE(!chan->is_global)) {
+				relay_set_buf_dentry(chan->buf[0], dentry);
+				err = 0;
+			}
+		}
+		mutex_unlock(&relay_channels_mutex);
+		return err;
+	}
+
 	curr_cpu = get_cpu();
 	/*
 	 * The CPU hotplug notifier ran before us and created buffers with
@@ -706,6 +735,7 @@ int relay_late_setup_files(struct rchan *chan,
 
 	return err;
 }
+EXPORT_SYMBOL_GPL(relay_late_setup_files);
 
 /**
  *	relay_switch_subbuf - switch to a new sub-buffer
-- 
1.9.2

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

end of thread, other threads:[~2016-07-13  9:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-03 16:15 [PATCH] relay: Add global mode support for buffer-only channels akash.goel
2016-07-04  8:00 ` Chris Wilson
2016-07-04 13:03   ` Goel, Akash
2016-07-11  7:17     ` [PATCH v2] " akash.goel
2016-07-11 20:17       ` Andrew Morton
2016-07-12  9:24         ` Chris Wilson
2016-07-12 12:50           ` Goel, Akash
2016-07-12 13:01             ` Chris Wilson
2016-07-12 13:24               ` Goel, Akash
2016-07-12 19:51                 ` Andrew Morton
2016-07-13  7:39                   ` [PATCH v3] " akash.goel
2016-07-13  8:30                     ` kbuild test robot
2016-07-13 10:09                       ` [PATCH v4] " akash.goel

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).