From: "Dan Williams" <dan.j.williams@intel.com>
To: "Haavard Skinnemoen" <haavard.skinnemoen@atmel.com>
Cc: "Pierre Ossman" <drzeus-list@drzeus.cx>,
linux-kernel@vger.kernel.org, linux-embedded@vger.kernel.org,
kernel@avr32linux.org, shannon.nelson@intel.com,
"David Brownell" <david-b@pacbell.net>
Subject: Re: [PATCH v4 2/6] dmaengine: Add dma_chan_is_in_use() function
Date: Tue, 1 Jul 2008 19:00:55 -0700 [thread overview]
Message-ID: <e9c3a7c20807011900x7b2ac3dx7536e0450202e3c0@mail.gmail.com> (raw)
In-Reply-To: <e9c3a7c20807011831n74eb69b8r3095b62515fe5c9@mail.gmail.com>
On Tue, Jul 1, 2008 at 6:31 PM, Dan Williams <dan.j.williams@intel.com> wrote:
> On Thu, Jun 26, 2008 at 6:23 AM, Haavard Skinnemoen
> <haavard.skinnemoen@atmel.com> wrote:
>> This moves the code checking if a DMA channel is in use from
>> show_in_use() into an inline helper function, dma_is_in_use(). DMA
>> controllers can use this in order to give clients exclusive access to
>> channels (usually necessary when setting up slave DMA.)
>>
>> I have to admit that I don't really understand the channel refcounting
>> logic at all... dma_chan_get() simply increments a per-cpu value. How
>> can we be sure that whatever CPU calls dma_chan_is_in_use() sees the
>> same value?
>
> As Chris noted in the comments at the top of dmaengine.c this is an
> implementation Rusty's 'bigref'. It seeks to avoid the
> cache-line-bouncing overhead of maintaining a single global refcount
> in hot paths like tcp_v{4,6}_rcv(). When the channel is being
> removed, a rare event, we transition to the accurate, yet slow, global
> method.
>
> Your observation is correct, dma_chan_is_in_use() may lie in the case
> when the current cpu is not using the channel. For this particular
> test I think you can look to see if this channel's resources are
> already allocated. If they are then some other client got a hold of
> this channel before the current attempt. Hmm... that would also
> require that we free the channel's resources in the case where the
> client replies with DMA_NAK, probably something we should do anyways.
>
> Thoughts?
>
Actually we will probably need something like the following.
->client_count is protected by the dma_list_mutex.
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 99c22b4..10de69e 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -183,9 +183,10 @@ static void dma_client_chan_alloc(struct
dma_client *client)
/* we are done once this client rejects
* an available resource
*/
- if (ack == DMA_ACK)
+ if (ack == DMA_ACK) {
dma_chan_get(chan);
- else if (ack == DMA_NAK)
+ chan->client_count++;
+ } else if (ack == DMA_NAK)
return;
}
}
@@ -272,8 +273,10 @@ static void dma_clients_notify_removed(struct
dma_chan *chan)
/* client was holding resources for this channel so
* free it
*/
- if (ack == DMA_ACK)
+ if (ack == DMA_ACK) {
dma_chan_put(chan);
+ chan->client_count--;
+ }
}
mutex_unlock(&dma_list_mutex);
@@ -313,8 +316,10 @@ void dma_async_client_unregister(struct dma_client *client)
ack = client->event_callback(client, chan,
DMA_RESOURCE_REMOVED);
- if (ack == DMA_ACK)
+ if (ack == DMA_ACK) {
dma_chan_put(chan);
+ chan->client_count--;
+ }
}
list_del(&client->global_node);
@@ -394,6 +399,7 @@ int dma_async_device_register(struct dma_device *device)
kref_get(&device->refcount);
kref_get(&device->refcount);
kref_init(&chan->refcount);
+ chan->client_count = 0;
chan->slow_ref = 0;
INIT_RCU_HEAD(&chan->rcu);
}
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index d08a5c5..6432b83 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -139,6 +139,7 @@ struct dma_chan_percpu {
* @rcu: the DMA channel's RCU head
* @device_node: used to add this to the device chan list
* @local: per-cpu pointer to a struct dma_chan_percpu
+ * @client-count: how many clients are using this channel
*/
struct dma_chan {
struct dma_device *device;
@@ -154,6 +155,7 @@ struct dma_chan {
struct list_head device_node;
struct dma_chan_percpu *local;
+ int client_count;
};
#define to_dma_chan(p) container_of(p, struct dma_chan, dev)
next prev parent reply other threads:[~2008-07-02 2:01 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-26 13:23 [PATCH v4 0/6] dmaengine/mmc: DMA slave interface and two new drivers Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 1/6] dmaengine: Add dma_client parameter to device_alloc_chan_resources Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 2/6] dmaengine: Add dma_chan_is_in_use() function Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 3/6] dmaengine: Add slave DMA interface Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 4/6] dmaengine: Make DMA Engine menu visible for AVR32 users Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 5/6] dmaengine: Driver for the Synopsys DesignWare DMA controller Haavard Skinnemoen
2008-06-26 13:23 ` [PATCH v4 6/6] Atmel MCI: Driver for Atmel on-chip MMC controllers Haavard Skinnemoen
2008-06-27 19:10 ` Haavard Skinnemoen
2008-06-27 19:56 ` Pierre Ossman
2008-06-28 12:43 ` Haavard Skinnemoen
2008-06-28 13:31 ` Haavard Skinnemoen
2008-06-29 16:49 ` Pierre Ossman
2008-06-28 13:45 ` Pierre Ossman
2008-06-28 14:01 ` Haavard Skinnemoen
2008-06-28 14:11 ` Pierre Ossman
2008-06-27 21:31 ` Dan Williams
2008-06-28 12:47 ` Haavard Skinnemoen
2008-07-04 0:40 ` dmaengine skip unmap (was: Re: [PATCH v4 5/6] dmaengine: Driver for the Synopsys DesignWare DMA controller) Dan Williams
2008-07-04 14:47 ` Haavard Skinnemoen
2008-06-26 14:15 ` [PATCH v4 4/6] dmaengine: Make DMA Engine menu visible for AVR32 users Adrian Bunk
2008-06-26 14:46 ` Haavard Skinnemoen
2008-06-27 0:59 ` Dan Williams
2008-06-27 16:37 ` David Brownell
2008-06-27 17:44 ` Adrian Bunk
2008-06-27 18:24 ` David Brownell
2008-06-27 18:29 ` Adrian Bunk
2008-06-27 18:31 ` Dan Williams
2008-06-27 18:13 ` Haavard Skinnemoen
2008-06-26 20:04 ` David Brownell
2008-06-26 13:32 ` [PATCH v4 3/6] dmaengine: Add slave DMA interface Haavard Skinnemoen
2008-06-28 12:29 ` Haavard Skinnemoen
2008-07-02 1:31 ` [PATCH v4 2/6] dmaengine: Add dma_chan_is_in_use() function Dan Williams
2008-07-02 2:00 ` Dan Williams [this message]
2008-07-02 7:59 ` Haavard Skinnemoen
2008-07-02 7:56 ` Haavard Skinnemoen
2008-07-04 1:06 ` [PATCH v4 0/6] dmaengine/mmc: DMA slave interface and two new drivers Dan Williams
2008-07-04 15:13 ` Haavard Skinnemoen
[not found] <f12847240806270224v29de65e8h612a077e12c4d5e1@mail.gmail.com>
2008-07-01 13:52 ` [PATCH v4 2/6] dmaengine: Add dma_chan_is_in_use() function 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=e9c3a7c20807011900x7b2ac3dx7536e0450202e3c0@mail.gmail.com \
--to=dan.j.williams@intel.com \
--cc=david-b@pacbell.net \
--cc=drzeus-list@drzeus.cx \
--cc=haavard.skinnemoen@atmel.com \
--cc=kernel@avr32linux.org \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shannon.nelson@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®