From: Dan Williams <dan.j.williams@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"Sosnowski, Maciej" <maciej.sosnowski@intel.com>,
"hskinnemoen@atmel.com" <hskinnemoen@atmel.com>,
"g.liakhovetski@gmx.de" <g.liakhovetski@gmx.de>,
"nicolas.ferre@atmel.com" <nicolas.ferre@atmel.com>
Subject: Re: [PATCH 03/13] dmaengine: up-level reference counting to the module level
Date: Mon, 17 Nov 2008 20:42:04 -0700 [thread overview]
Message-ID: <1226979724.25411.20.camel@dwillia2-linux.ch.intel.com> (raw)
In-Reply-To: <20081114220842.482d56e5.akpm@linux-foundation.org>
Thanks for the review.
On Fri, 2008-11-14 at 23:08 -0700, Andrew Morton wrote:
> > +static struct module *dma_chan_to_owner(struct dma_chan *chan)
> > +{
> > + return chan->device->dev->driver->owner;
> > +}
>
> Has this all been tested with CONFIG_MODULES=n?
>
It works, the only thing that changes is that ->owner is always NULL.
> It looks like we have a lot of unneeded code if CONFIG_MODULES=n.
> However that might not be a case which is worth bothering about.
We still need all the other reference counting machinery to identify
busy channels.
>
> > +/**
> > + * balance_ref_count - catch up the channel reference count
> > + */
> > +static void balance_ref_count(struct dma_chan *chan)
>
> Forgot to kerneldocument the argument.
yup
>
> > +{
> > + struct module *owner = dma_chan_to_owner(chan);
> > +
> > + while (chan->client_count < dmaengine_ref_count) {
> > + __module_get(owner);
> > + chan->client_count++;
> > + }
> > +}
>
> The locking for ->client_count is undocumented.
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index dce6d00..9396891 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -129,6 +129,9 @@ static struct module *dma_chan_to_owner(struct dma_chan *chan)
/**
* balance_ref_count - catch up the channel reference count
+ * @chan - channel to balance ->client_count versus dmaengine_ref_count
+ *
+ * balance_ref_count must be called under dma_list_mutex
*/
static void balance_ref_count(struct dma_chan *chan)
{
> > +/**
> > + * dma_chan_get - try to grab a dma channel's parent driver module
> > + * @chan - channel to grab
> > + */
> > +static int dma_chan_get(struct dma_chan *chan)
> > +{
> > + int err = -ENODEV;
> > + struct module *owner = dma_chan_to_owner(chan);
> > +
> > + if (chan->client_count) {
> > + __module_get(owner);
> > + err = 0;
> > + } else if (try_module_get(owner))
> > + err = 0;
>
> I wonder if try_module_get() could be used in both cases (migt not make
> sense to do so though).
Yes, but I like how it documents the assumption that the backing module
has been referenced when client_count is non-zero.
>
> > + if (err == 0)
> > + chan->client_count++;
>
> Locking for this?
@@ -146,6 +146,8 @@ static void balance_ref_count(struct dma_chan *chan)
/**
* dma_chan_get - try to grab a dma channel's parent driver module
* @chan - channel to grab
+ *
+ * Must be called under dma_list_mutex
*/
static int dma_chan_get(struct dma_chan *chan)
{
>
> > + /* allocate upon first client reference */
> > + if (chan->client_count == 1 && err == 0) {
> > + int desc = chan->device->device_alloc_chan_resources(chan, NULL);
> > +
> > + if (desc < 0) {
> > + chan->client_count = 0;
> > + module_put(owner);
> > + err = -ENOMEM;
>
> Shouldn't we just propagate the ->device_alloc_chan_resources() return value?
>
Yes, this is broken.
@@ -165,12 +165,11 @@ static int dma_chan_get(struct dma_chan *chan)
/* allocate upon first client reference */
if (chan->client_count == 1 && err == 0) {
- int desc = chan->device->device_alloc_chan_resources(chan);
+ err = chan->device->device_alloc_chan_resources(chan);
- if (desc < 0) {
+ if (err < 0) {
chan->client_count = 0;
module_put(owner);
- err = -ENOMEM;
} else if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
balance_ref_count(chan);
}
> > + } else
> > + balance_ref_count(chan);
> > + }
> > +
> > + return err;
> > +}
> > +
> > +static void dma_chan_put(struct dma_chan *chan)
> > +{
> > + if (!chan->client_count)
> > + return; /* this channel failed alloc_chan_resources */
>
> Or we had a bug ;)
...hopefully caught by the BUG_ON(dmaengine_ref_count < 0) in
dmaengine_put().
>
> > + chan->client_count--;
>
> Undocumented locking..
@@ -178,6 +178,12 @@ static int dma_chan_get(struct dma_chan *chan)
return err;
}
+/**
+ * dma_chan_put - drop a reference to a dma channel's parent driver module
+ * @chan - channel to release
+ *
+ * Must be called under dma_list_mutex
+ */
static void dma_chan_put(struct dma_chan *chan)
{
if (!chan->client_count)
Regards,
Dan
next prev parent reply other threads:[~2008-11-18 3:42 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-14 21:34 [PATCH 00/13] dmaengine redux Dan Williams
2008-11-14 21:34 ` [PATCH 01/13] async_tx, dmaengine: document channel allocation and api rework Dan Williams
2008-11-14 21:34 ` [PATCH 02/13] dmaengine: remove dependency on async_tx Dan Williams
2008-11-15 6:02 ` Andrew Morton
2008-11-17 23:44 ` Dan Williams
2008-11-14 21:34 ` [PATCH 03/13] dmaengine: up-level reference counting to the module level Dan Williams
2008-11-15 6:08 ` Andrew Morton
2008-11-18 3:42 ` Dan Williams [this message]
2008-12-04 16:56 ` Guennadi Liakhovetski
2008-12-04 18:51 ` Dan Williams
2008-12-04 19:28 ` Guennadi Liakhovetski
2008-12-08 22:39 ` Dan Williams
2008-12-12 14:28 ` Sosnowski, Maciej
2008-12-15 22:12 ` Dan Williams
2008-12-18 14:26 ` Sosnowski, Maciej
2008-11-14 21:34 ` [PATCH 04/13] dmaengine: centralize channel allocation, introduce dma_find_channel Dan Williams
2008-11-15 6:14 ` Andrew Morton
2008-11-18 5:59 ` Dan Williams
2008-11-14 21:34 ` [PATCH 05/13] dmaengine: provide a common 'issue_pending_all' implementation Dan Williams
2008-11-14 21:34 ` [PATCH 06/13] net_dma: convert to dma_find_channel Dan Williams
2008-11-14 21:34 ` [PATCH 07/13] dmaengine: introduce dma_request_channel and private channels Dan Williams
2008-12-02 15:52 ` Guennadi Liakhovetski
2008-12-02 17:16 ` Dan Williams
2008-12-02 17:27 ` Guennadi Liakhovetski
2008-12-02 19:10 ` Dan Williams
2008-12-02 21:28 ` Guennadi Liakhovetski
2009-01-30 17:03 ` Atsushi Nemoto
2009-01-30 23:13 ` Dan Williams
2009-01-30 23:13 ` Dan Williams
2009-01-30 23:27 ` Guennadi Liakhovetski
2009-01-30 23:27 ` Guennadi Liakhovetski
2009-01-31 12:18 ` Atsushi Nemoto
2008-12-02 17:26 ` Nicolas Ferre
2008-12-12 14:29 ` Sosnowski, Maciej
2008-12-15 23:55 ` Dan Williams
2008-12-18 14:33 ` Sosnowski, Maciej
2008-12-18 17:27 ` Dan Williams
2009-02-06 16:58 ` Atsushi Nemoto
2008-11-14 21:34 ` [PATCH 08/13] dmatest: convert to dma_request_channel Dan Williams
2008-11-15 6:17 ` Andrew Morton
2008-11-18 18:24 ` Dan Williams
2008-11-18 20:58 ` Andrew Morton
2008-11-18 22:19 ` Dan Williams
2008-11-14 21:35 ` [PATCH 09/13] atmel-mci: convert to dma_request_channel and down-level dma_slave Dan Williams
2009-01-30 16:40 ` Atsushi Nemoto
2009-01-30 23:02 ` Dan Williams
2009-01-30 23:02 ` Dan Williams
2008-11-14 21:35 ` [PATCH 10/13] dmaengine: replace dma_async_client_register with dmaengine_get Dan Williams
2008-11-14 21:35 ` [PATCH 11/13] dmaengine: kill struct dma_client and supporting infrastructure Dan Williams
2008-12-12 14:29 ` Sosnowski, Maciej
2008-12-16 0:09 ` Dan Williams
2008-12-18 14:34 ` Sosnowski, Maciej
2008-11-14 21:35 ` [PATCH 12/13] dmaengine: remove 'bigref' infrastructure Dan Williams
2008-11-14 21:35 ` [PATCH 13/13] dmaengine: kill enum dma_state_client Dan Williams
2008-12-12 14:27 ` [PATCH 00/13] dmaengine redux Sosnowski, Maciej
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=1226979724.25411.20.camel@dwillia2-linux.ch.intel.com \
--to=dan.j.williams@intel.com \
--cc=akpm@linux-foundation.org \
--cc=g.liakhovetski@gmx.de \
--cc=hskinnemoen@atmel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.sosnowski@intel.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@atmel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.