public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] ohci1394: dma_pool_destroy while in_atomic() && irqs_disabled()
@ 2005-02-19 19:36 David Brownell
  2005-02-19 20:50 ` Parag Warudkar
  2005-02-19 22:55 ` Jody McIntyre
  0 siblings, 2 replies; 17+ messages in thread
From: David Brownell @ 2005-02-19 19:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: scjody


> > Jody - Is the 200K waste for sure or do you want me to verify it by some 
> > means? ( Reason I am asking is firstly, Dave Brownell was quite sure it 
> > wasn't that costly and secondly, I am hoping it isn't.. ;)
> 
> I'm not sure, but I looked through the code and it seems to allocate:
>  - 16 buffers of 2x PAGE_SIZE (= 131072 on i386)
>  - 16 buffers of PAGE_SIZE (= 65536 on i386)
>  - various other smaller structures.
> 
> I'm not sure how to actually _measure_ how much memory this is using.
> slabinfo isn't useful, at least on my system, because the 1394
> allocations get lost in the noise of other activity.

Those allocations could be from _using_ a dma pool ... but they're
not from just creating one!

The cost of creating the dma_pool is the cost of one small kmalloc()
plus (the expensive part) the /sys/devices/.../pools sysfs attribute
is created along with the first pool.  (Use that instead of slabinfo
for those pool allocations.)  That's why the normal spot to create and
destroy dma pools is in driver probe() and remove() methods.

If you want to allocate gobs of other stuff at the same time, that's
your choice ... but it'd be a separate issue.  Cost to create a
dma_pool is significantly less than PAGE_SIZE, and there's no good
reason to allocate or destroy those pools anywhere near an IRQ context.

- Dave

^ permalink raw reply	[flat|nested] 17+ messages in thread
* [PATCH] ohci1394: dma_pool_destroy while in_atomic() && irqs_disabled()
@ 2005-01-30 20:54 Parag Warudkar
  2005-01-30 21:17 ` Andrew Morton
  0 siblings, 1 reply; 17+ messages in thread
From: Parag Warudkar @ 2005-01-30 20:54 UTC (permalink / raw)
  To: bcollins, linux-kernel, linux1394-devel, Andrew Morton

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

Problem - ohci1394.c:ohci_devctl ends up calling dma_pool_destroy from 
invalid context. Below is the dmesg output when I exit Kino after video 
capture -

Debug: sleeping function called from invalid context at 
include/asm/semaphore.h:107
in_atomic():1, irqs_disabled():1
 [<c0104c2e>] dump_stack+0x1e/0x20
 [<c011f8a2>] __might_sleep+0xa2/0xc0
 [<c028c660>] dma_pool_destroy+0x20/0x140
 [<f0b7affe>] free_dma_rcv_ctx+0x8e/0x150 [ohci1394]
 [<f0b774a4>] ohci_devctl+0x214/0x9b0 [ohci1394]
 [<f0e7aa99>] handle_iso_listen+0x2d9/0x310 [raw1394]
 [<f0e7f22b>] state_connected+0x29b/0x2b0 [raw1394]
 [<f0e7f2de>] raw1394_write+0x9e/0xd0 [raw1394]
 [<c0183ef2>] vfs_write+0xc2/0x170
 [<c018406b>] sys_write+0x4b/0x80
 [<c0103cb1>] sysenter_past_esp+0x52/0x75

Attached patch against 2.6.11-rc2 (tested to work normally with a  
camcorder device) enables ohci_devctl to defer the work of destroying 
the dma pool by using a work queue, so the dma pool is destroyed in a 
valid context and we no longer get an error in dmesg (duh :)

Note : There still exists  one more similar problem with ohci1394 - that 
is with dma_pool_create being called from invalid context - this happens 
in response to ISO_LISTEN_CHANNEL. I get dmesg debug for this case which 
is similar to the above. My analysis is that this one is non-trivial to 
fix. More on this in a separate mail.

Patch is attached since T'Bird messes up with the inlined one. (Pls. 
suggest a good email client for kernel patch stuff :)

Signed-off-by: Parag Warudkar (kernel-stuff@comcast.net)


Parag



[-- Attachment #2: patch-ohci1394 --]
[-- Type: text/plain, Size: 1596 bytes --]

--- drivers/ieee1394/ohci1394.c.orig	2004-12-24 16:35:25.000000000 -0500
+++ drivers/ieee1394/ohci1394.c	2005-01-30 15:46:34.000000000 -0500
@@ -99,6 +99,7 @@
 #include <asm/uaccess.h>
 #include <linux/delay.h>
 #include <linux/spinlock.h>
+#include <linux/workqueue.h>
 
 #include <asm/pgtable.h>
 #include <asm/page.h>
@@ -164,6 +165,7 @@
 static char version[] __devinitdata =
 	"$Rev: 1223 $ Ben Collins <bcollins@debian.org>";
 
+
 /* Module Parameters */
 static int phys_dma = 1;
 module_param(phys_dma, int, 0644);
@@ -184,6 +186,8 @@
 
 static void ohci1394_pci_remove(struct pci_dev *pdev);
 
+static void ohci_free_dma_work_fn(void* data);
+
 #ifndef __LITTLE_ENDIAN
 static unsigned hdr_sizes[] =
 {
@@ -1130,6 +1134,13 @@
 	return retval;
 }
 
+static void ohci_free_dma_work_fn(void* data)
+{
+	struct pci_pool* prg_pool = (struct pci_pool*) data;
+	pci_pool_destroy(prg_pool);
+	OHCI_DMA_FREE("dma_rcv prg pool");
+}
+
 /***********************************
  * rawiso ISO reception            *
  ***********************************/
@@ -2898,13 +2909,14 @@
 		kfree(d->buf_bus);
 	}
 	if (d->prg_cpu) {
+		struct work_struct ohci_free_dma_work;
 		for (i=0; i<d->num_desc; i++)
 			if (d->prg_cpu[i] && d->prg_bus[i]) {
 				pci_pool_free(d->prg_pool, d->prg_cpu[i], d->prg_bus[i]);
 				OHCI_DMA_FREE("consistent dma_rcv prg[%d]", i);
 			}
-		pci_pool_destroy(d->prg_pool);
-		OHCI_DMA_FREE("dma_rcv prg pool");
+		INIT_WORK(&ohci_free_dma_work, ohci_free_dma_work_fn, (void*) d->prg_pool);
+		schedule_work(&ohci_free_dma_work);
 		kfree(d->prg_cpu);
 		kfree(d->prg_bus);
 	}

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

end of thread, other threads:[~2005-02-19 22:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-19 19:36 [PATCH] ohci1394: dma_pool_destroy while in_atomic() && irqs_disabled() David Brownell
2005-02-19 20:50 ` Parag Warudkar
2005-02-19 21:13   ` David Brownell
2005-02-19 22:55 ` Jody McIntyre
  -- strict thread matches above, loose matches on Subject: below --
2005-01-30 20:54 Parag Warudkar
2005-01-30 21:17 ` Andrew Morton
2005-01-30 22:49   ` Parag Warudkar
2005-01-30 23:02     ` Andrew Morton
2005-01-31  1:19       ` Parag Warudkar
2005-01-31 23:26         ` Parag Warudkar
2005-02-11 15:35         ` Dan Dennedy
2005-02-11 18:43           ` Jody McIntyre
2005-02-12  3:54             ` Parag Warudkar
2005-02-18 15:32               ` Dan Dennedy
2005-02-18 15:42                 ` Parag Warudkar
2005-02-19  6:36                   ` Jody McIntyre
2005-02-19 15:06                     ` Parag Warudkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox