linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Vinod Koul <vkoul@kernel.org>
Cc: <dmaengine@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<dan.j.williams@intel.com>, <geert@linux-m68k.org>
Subject: Re: [PATCH v3] dmaengine: Add basic debugfs support
Date: Wed, 26 Feb 2020 14:10:14 +0200	[thread overview]
Message-ID: <71231b0e-a9a2-4795-da71-b484f4992278@ti.com> (raw)
In-Reply-To: <20200224163707.GA2618@vkoul-mobl>

Hi Vinod,

On 2/24/20 6:37 PM, Vinod Koul wrote:
> On 05-02-20, 13:15, Peter Ujfalusi wrote:
>> Via the /sys/kernel/debug/dmaengine users can get information about the
>> DMA devices and the used channels.
>>
>> Example output on am654-evm with audio using two channels and after running
>> dmatest on 6 channels:
>>
>> # cat /sys/kernel/debug/dmaengine
>> dma0 (285c0000.dma-controller): number of channels: 96
>>
>> dma1 (31150000.dma-controller): number of channels: 267
>>  dma1chan0    | 2b00000.mcasp:tx
>>  dma1chan1    | 2b00000.mcasp:rx
>>  dma1chan2    | in-use
>>  dma1chan3    | in-use
>>  dma1chan4    | in-use
>>  dma1chan5    | in-use
>>  dma1chan6    | in-use
>>  dma1chan7    | in-use
>>
>> For slave channels we can show the device and the channel name a given
>> channel is requested.
>> For non slave devices the only information we know is that the channel is
>> in use.
>>
>> DMA drivers can implement the optional dbg_show callback to provide
>> controller specific information instead of the generic one.
>>
>> It is easy to extend the generic dmaengine_dbg_show() to print additional
>> information about the used channels.
>>
>> I have taken the idea from gpiolib.
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>> Hi,
>>
>> Changes since v2:
>> - Use dma_chan_name() for printing the channel's name
>>
>> Changes since v1:
>> - Use much more simplified fops for the debugfs file (via DEFINE_SHOW_ATTRIBUTE)
>> - do not allow modification to dma_device_list while the debugfs file is read
>> - rename the slave_name to dbg_client_name (it is only for debugging)
>> - print information about dma_router if it is used by the channel
>> - Formating of the output slightly changed
>>
>> Regards,
>> Peter
>>
>>  drivers/dma/dmaengine.c   | 65 +++++++++++++++++++++++++++++++++++++++
>>  include/linux/dmaengine.h | 12 +++++++-
>>  2 files changed, 76 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
>> index c3b1283b6d31..37c3a4cd5b1a 100644
>> --- a/drivers/dma/dmaengine.c
>> +++ b/drivers/dma/dmaengine.c
>> @@ -32,6 +32,7 @@
>>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>>  
>>  #include <linux/platform_device.h>
>> +#include <linux/debugfs.h>
>>  #include <linux/dma-mapping.h>
>>  #include <linux/init.h>
>>  #include <linux/module.h>
>> @@ -760,6 +761,11 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
>>  		return chan ? chan : ERR_PTR(-EPROBE_DEFER);
>>  
>>  found:
>> +#ifdef CONFIG_DEBUG_FS
>> +	chan->dbg_client_name = kasprintf(GFP_KERNEL, "%s:%s", dev_name(dev),
>> +					  name);
>> +#endif
>> +
>>  	chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
>>  	if (!chan->name)
>>  		return chan;
>> @@ -837,6 +843,11 @@ void dma_release_channel(struct dma_chan *chan)
>>  		chan->name = NULL;
>>  		chan->slave = NULL;
>>  	}
>> +
>> +#ifdef CONFIG_DEBUG_FS
>> +	kfree(chan->dbg_client_name);
>> +	chan->dbg_client_name = NULL;
>> +#endif
>>  	mutex_unlock(&dma_list_mutex);
>>  }
>>  EXPORT_SYMBOL_GPL(dma_release_channel);
>> @@ -1562,3 +1573,57 @@ static int __init dma_bus_init(void)
>>  	return class_register(&dma_devclass);
>>  }
>>  arch_initcall(dma_bus_init);
>> +
>> +#ifdef CONFIG_DEBUG_FS
>> +static void dmaengine_dbg_show(struct seq_file *s, struct dma_device *dma_dev)
>> +{
>> +	struct dma_chan *chan;
>> +
>> +	list_for_each_entry(chan, &dma_dev->channels, device_node) {
>> +		if (chan->client_count) {
>> +			seq_printf(s, " %-13s| %s", dma_chan_name(chan),
>> +				   chan->dbg_client_name ?: "in-use");
>> +
>> +			if (chan->router)
>> +				seq_printf(s, " (via router: %s)\n",
>> +					dev_name(chan->router->dev));
>> +			else
>> +				seq_puts(s, "\n");
>> +		}
>> +	}
>> +}
>> +
>> +static int dmaengine_debugfs_show(struct seq_file *s, void *data)
>> +{
>> +	struct dma_device *dma_dev = NULL;
>> +
>> +	mutex_lock(&dma_list_mutex);
>> +	list_for_each_entry(dma_dev, &dma_device_list, global_node) {
>> +		seq_printf(s, "dma%d (%s): number of channels: %u\n",
>> +			   dma_dev->dev_id, dev_name(dma_dev->dev),
>> +			   dma_dev->chancnt);
>> +
>> +		if (dma_dev->dbg_show)
>> +			dma_dev->dbg_show(s, dma_dev);
>  do we really want a custom dbg_show()..? Drivers can add their own
> files...

They could do that already ;)

With the custom dbg_show() DMA drivers can save on the surrounding
code and just fill in the information regarding to their HW.
Again, on am654 the default information is:
# cat /sys/kernel/debug/dmaengine 
dma0 (285c0000.dma-controller): number of channels: 96

dma1 (31150000.dma-controller): number of channels: 267
 dma1chan0    | 2b00000.mcasp:tx
 dma1chan1    | 2b00000.mcasp:rx
 dma1chan2    | in-use
 dma1chan3    | in-use
 dma1chan4    | in-use
 dma1chan5    | in-use

With my current .dbg_show implementation for k3-udma:
# cat /sys/kernel/debug/dmaengine 
dma0 (285c0000.dma-controller): number of channels: 96

dma1 (31150000.dma-controller): number of channels: 267
 dma1chan0    | 2b00000.mcasp:tx (MEM_TO_DEV, tchan8 [0x1008 -> 0xc400], PDMA, TR mode)
 dma1chan1    | 2b00000.mcasp:rx (DEV_TO_MEM, rchan8 [0x4400 -> 0x9008], PDMA, TR mode)
 dma1chan2    | in-use (MEM_TO_MEM, chan2 pair [0x1002 -> 0x9002], PSI-L Native, TR mode)
 dma1chan3    | in-use (MEM_TO_MEM, chan3 pair [0x1003 -> 0x9003], PSI-L Native, TR mode)
 dma1chan4    | in-use (MEM_TO_MEM, chan4 pair [0x1004 -> 0x9004], PSI-L Native, TR mode)
 dma1chan5    | in-use (MEM_TO_MEM, chan5 pair [0x1005 -> 0x9005], PSI-L Native, TR mode)

For me this makes a huge difference.

> 
>> +		else
>> +			dmaengine_dbg_show(s, dma_dev);
>> +
>> +		if (!list_is_last(&dma_dev->global_node, &dma_device_list))
>> +			seq_puts(s, "\n");
>> +	}
>> +	mutex_unlock(&dma_list_mutex);
>> +
>> +	return 0;
>> +}
>> +DEFINE_SHOW_ATTRIBUTE(dmaengine_debugfs);
>> +
>> +static int __init dmaengine_debugfs_init(void)
>> +{
>> +	/* /sys/kernel/debug/dmaengine */
>> +	debugfs_create_file("dmaengine", 0444, NULL, NULL,
>> +			    &dmaengine_debugfs_fops);
> 
> Should we add a directory? That way we can keep adding stuff into that
> one

and have this file as 'summary' underneath?
I like the fact hat I can get all the information via one file.
Saves a lot of time (and explaining to users) on finding the correct
one to cat...
 - Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2020-02-26 12:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 11:15 [PATCH v3] dmaengine: Add basic debugfs support Peter Ujfalusi
2020-02-24 16:37 ` Vinod Koul
2020-02-26 12:10   ` Peter Ujfalusi [this message]
2020-02-28  4:47     ` Vinod Koul
2020-02-28 10:01       ` Peter Ujfalusi
2020-02-28 10:26         ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71231b0e-a9a2-4795-da71-b484f4992278@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).