Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jan 2015 12:59:58 +0100
From:      Hans Petter Selasky <hps@selasky.org>
To:        Ian Lepore <ian@freebsd.org>
Cc:        kott <kmatpral@yahoo.com>, freebsd-usb@freebsd.org
Subject:   Re: usb_pc_cpu_flush
Message-ID:  <54B8FD3E.2080404@selasky.org>
In-Reply-To: <1421247832.14601.258.camel@freebsd.org>
References:  <1419359192795-5975583.post@n5.nabble.com>				 <5499E734.1070507@selasky.org>	 <1419392511197-5975691.post@n5.nabble.com>				 <549A811D.3060204@selasky.org>	 <1419416870924-5975752.post@n5.nabble.com>				 <1419423740820-5975763.post@n5.nabble.com>	 <549AB711.8070005@selasky.org>				 <1419431704871-5975773.post@n5.nabble.com>	 <549BF430.8000207@selasky.org>				 <1419877515606-5976832.post@n5.nabble.com>				 <1421133295061-5980199.post@n5.nabble.com>				 <1421160576.14601.175.camel@freebsd.org> <54B53956.4090708@selasky.org>			 <1421163656.14601.184.camel@freebsd.org> <54B54073.6000409@selasky.org>		 <1421166591.14601.195.camel@freebsd.org> <54B54D4D.3010805@selasky.org>	 <1421180700.14601.209.camel@freebsd.org> <54B5FAE8.7020705@selasky.org> <1421247832.14601.258.camel@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi Ian,

Please find attached a patch which disable the double mapping of 
allocated DMA capable buffers in the USB stack for all drivers.

Can you test it and check out the total memory usage before and after 
the patch? Also verify it if makes any difference on any platforms.

Thank you!

--HPS

[-- Attachment #2 --]
Index: sys/dev/usb/usb_transfer.c
===================================================================
--- sys/dev/usb/usb_transfer.c	(revision 277240)
+++ sys/dev/usb/usb_transfer.c	(working copy)
@@ -237,7 +237,7 @@
 		n_obj = 1;
 	} else {
 		/* compute number of objects per page */
-		n_obj = (USB_PAGE_SIZE / size);
+		n_obj = 1; /* (USB_PAGE_SIZE / size); */
 		/*
 		 * Compute number of DMA chunks, rounded up
 		 * to nearest one:
@@ -273,8 +273,11 @@
 		    &parm->curr_xfer->xroot->dma_parent_tag;
 	}
 
-	if (ppc) {
-		*ppc = parm->xfer_page_cache_ptr;
+	if (ppc != NULL) {
+		if (n_obj != 1)
+			*ppc = parm->xfer_page_cache_ptr;
+		else
+			*ppc = parm->dma_page_cache_ptr;
 	}
 	r = count;			/* set remainder count */
 	z = n_obj * size;		/* set allocation size */
@@ -281,7 +284,18 @@
 	pc = parm->xfer_page_cache_ptr;
 	pg = parm->dma_page_ptr;
 
-	for (x = 0; x != n_dma_pc; x++) {
+	if (n_obj == 1) {
+	    for (x = 0; x != n_dma_pc; x++) {
+		if (usb_pc_alloc_mem(parm->dma_page_cache_ptr,
+		    pg, z, align)) {
+			return (1);	/* failure */
+		}
+		/* Make room for one DMA page cache and "n_dma_pg" pages */
+		parm->dma_page_cache_ptr++;
+		pg += n_dma_pg;
+	    }
+	} else {
+	    for (x = 0; x != n_dma_pc; x++) {
 
 		if (r < n_obj) {
 			/* compute last remainder */
@@ -294,7 +308,7 @@
 		}
 		/* Set beginning of current buffer */
 		buf = parm->dma_page_cache_ptr->buffer;
-		/* Make room for one DMA page cache and one page */
+		/* Make room for one DMA page cache and "n_dma_pg" pages */
 		parm->dma_page_cache_ptr++;
 		pg += n_dma_pg;
 
@@ -314,6 +328,7 @@
 			}
 			mtx_unlock(pc->tag_parent->mtx);
 		}
+	    }
 	}
 
 	parm->xfer_page_cache_ptr = pc;

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54B8FD3E.2080404>