linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* dmaengine: Can we schedule new transfer from dma callback routine??
@ 2011-04-11  7:55 viresh kumar
  2011-04-11  8:56 ` Russell King - ARM Linux
  0 siblings, 1 reply; 5+ messages in thread
From: viresh kumar @ 2011-04-11  7:55 UTC (permalink / raw)
  To: linux-arm-kernel


Hello,

In dw_dmac.c driver, dwc_descriptor_complete() routine, following is
mentioned before calling callback:

	/*
	 * The API requires that no submissions are done from a
	 * callback, so we don't need to drop the lock here
	 */
	if (callback)
		callback(param);

Does this hold true for dmaengine??

-- 
viresh

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

* dmaengine: Can we schedule new transfer from dma callback routine??
  2011-04-11  7:55 dmaengine: Can we schedule new transfer from dma callback routine?? viresh kumar
@ 2011-04-11  8:56 ` Russell King - ARM Linux
  2011-04-11 10:39   ` viresh kumar
  2011-04-15  6:45   ` viresh kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Russell King - ARM Linux @ 2011-04-11  8:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Apr 11, 2011 at 01:25:04PM +0530, viresh kumar wrote:
> 
> Hello,
> 
> In dw_dmac.c driver, dwc_descriptor_complete() routine, following is
> mentioned before calling callback:
> 
> 	/*
> 	 * The API requires that no submissions are done from a
> 	 * callback, so we don't need to drop the lock here
> 	 */
> 	if (callback)
> 		callback(param);
> 
> Does this hold true for dmaengine??

Not for slave devices - see Dan's reply:

http://lists.arm.linux.org.uk/lurker/message/20101223.005313.a38d7bf0.en.html

As the slave API hasn't been well documented, there's a lot of
inconsistency of behaviour between DMA engine slave implementations.
I'd suggest at least fixing slave DMA engine drivers to ensure that:

(a) the callback is always called in tasklet context
(b) the callback can submit new slave transactions (iow, the spinlock
    which prep_slave_sg takes must not be held during the callback.)

The way that others solve this is to move the completed txd structures
to a local 'completed' list, and then walk this list after the spinlocks
have been dropped.

IOW, something like this:

my_tasklet()
{
	INIT_LIST_HEAD(completed);

	spin_lock_irqsave(my_chan->lock);
	for_each_txd(my_txd, my_chan) {
		if (has_completed(my_txd))
			list_add_tail(my_txd->node, &completed);
	}
	spin_unlock_irqrestore(my_chan->lock);

	list_for_each_entry_safe(my_txd, next, &completed, node) {
		void *callback_param = my_txd->txd.callback_param;
		void (*fn)(void *) = my_txd->txd.callback;

		my_txd_free(my_chan, my_txd);

		fn(callback_param);
	}	
}

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

* dmaengine: Can we schedule new transfer from dma callback routine??
  2011-04-11  8:56 ` Russell King - ARM Linux
@ 2011-04-11 10:39   ` viresh kumar
  2011-04-15  6:45   ` viresh kumar
  1 sibling, 0 replies; 5+ messages in thread
From: viresh kumar @ 2011-04-11 10:39 UTC (permalink / raw)
  To: linux-arm-kernel

On 04/11/2011 02:26 PM, Russell King - ARM Linux wrote:
> On Mon, Apr 11, 2011 at 01:25:04PM +0530, viresh kumar wrote:
>>
>> Hello,
>>
>> In dw_dmac.c driver, dwc_descriptor_complete() routine, following is
>> mentioned before calling callback:
>>
>> 	/*
>> 	 * The API requires that no submissions are done from a
>> 	 * callback, so we don't need to drop the lock here
>> 	 */
>> 	if (callback)
>> 		callback(param);
>>
>> Does this hold true for dmaengine??
> 
> Not for slave devices - see Dan's reply:
> 
> http://lists.arm.linux.org.uk/lurker/message/20101223.005313.a38d7bf0.en.html
> 
> As the slave API hasn't been well documented, there's a lot of
> inconsistency of behaviour between DMA engine slave implementations.
> I'd suggest at least fixing slave DMA engine drivers to ensure that:
> 
> (a) the callback is always called in tasklet context
> (b) the callback can submit new slave transactions (iow, the spinlock
>     which prep_slave_sg takes must not be held during the callback.)
> 
> The way that others solve this is to move the completed txd structures
> to a local 'completed' list, and then walk this list after the spinlocks
> have been dropped.
> 
> IOW, something like this:
> 
> my_tasklet()
> {
> 	INIT_LIST_HEAD(completed);
> 
> 	spin_lock_irqsave(my_chan->lock);
> 	for_each_txd(my_txd, my_chan) {
> 		if (has_completed(my_txd))
> 			list_add_tail(my_txd->node, &completed);
> 	}
> 	spin_unlock_irqrestore(my_chan->lock);
> 
> 	list_for_each_entry_safe(my_txd, next, &completed, node) {
> 		void *callback_param = my_txd->txd.callback_param;
> 		void (*fn)(void *) = my_txd->txd.callback;
> 
> 		my_txd_free(my_chan, my_txd);
> 
> 		fn(callback_param);
> 	}	
> }

Got it. Thanx.

-- 
viresh

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

* dmaengine: Can we schedule new transfer from dma callback routine??
  2011-04-11  8:56 ` Russell King - ARM Linux
  2011-04-11 10:39   ` viresh kumar
@ 2011-04-15  6:45   ` viresh kumar
  2011-04-15  9:15     ` Russell King - ARM Linux
  1 sibling, 1 reply; 5+ messages in thread
From: viresh kumar @ 2011-04-15  6:45 UTC (permalink / raw)
  To: linux-arm-kernel

On 04/11/2011 02:26 PM, Russell King - ARM Linux wrote:
> On Mon, Apr 11, 2011 at 01:25:04PM +0530, viresh kumar wrote:
>>
>> Hello,
>>
>> In dw_dmac.c driver, dwc_descriptor_complete() routine, following is
>> mentioned before calling callback:
>>
>> 	/*
>> 	 * The API requires that no submissions are done from a
>> 	 * callback, so we don't need to drop the lock here
>> 	 */
>> 	if (callback)
>> 		callback(param);
>>
>> Does this hold true for dmaengine??
> 
> Not for slave devices - see Dan's reply:
> 
> http://lists.arm.linux.org.uk/lurker/message/20101223.005313.a38d7bf0.en.html
> 
> As the slave API hasn't been well documented, there's a lot of
> inconsistency of behaviour between DMA engine slave implementations.
> I'd suggest at least fixing slave DMA engine drivers to ensure that:
> 
> (a) the callback is always called in tasklet context
> (b) the callback can submit new slave transactions (iow, the spinlock
>     which prep_slave_sg takes must not be held during the callback.)
> 
> The way that others solve this is to move the completed txd structures
> to a local 'completed' list, and then walk this list after the spinlocks
> have been dropped.
> 

Hello,

There is one more issue in the current DW_DMAC driver.
As most of interrupt processing is done in tasklet, spin_lock_bh() is used in almost
every routine.

Now, if some driver is calling these routines from interrupt context or with interrupt
disabled, we get KERN_WARN() messages due to following in kernel/softirq.c:

static inline void _local_bh_enable_ip(unsigned long ip)
{
	WARN_ON_ONCE(in_irq() || irqs_disabled());
	...
}

Should i minimize processing in tasklets, so that spin_lock_bh is not required anymore,
as in drivers/dma/amba-pl08x.c (tasklet for every channel) or is there some other way of
doing it.

Currently, drivers/tty/serial/amba-pl011.c is calling from interrupt context or with
interrupt disabled.

-- 
viresh

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

* dmaengine: Can we schedule new transfer from dma callback routine??
  2011-04-15  6:45   ` viresh kumar
@ 2011-04-15  9:15     ` Russell King - ARM Linux
  0 siblings, 0 replies; 5+ messages in thread
From: Russell King - ARM Linux @ 2011-04-15  9:15 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 15, 2011 at 12:15:43PM +0530, viresh kumar wrote:
> There is one more issue in the current DW_DMAC driver.
> As most of interrupt processing is done in tasklet, spin_lock_bh() is used
> in almost every routine.

As you can't use spin_lock_bh() from IRQ context (you'll get a lockdep
warning) these need to be converted to being the irqsave versions.
That's probably the easiest fix.

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

end of thread, other threads:[~2011-04-15  9:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-11  7:55 dmaengine: Can we schedule new transfer from dma callback routine?? viresh kumar
2011-04-11  8:56 ` Russell King - ARM Linux
2011-04-11 10:39   ` viresh kumar
2011-04-15  6:45   ` viresh kumar
2011-04-15  9:15     ` Russell King - ARM Linux

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