mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Per Forlin <per.forlin@linaro.org>
To: Felipe Balbi <balbi@ti.com>, Greg Kroah-Hartman <gregkh@suse.de>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linaro-dev@lists.linaro.org
Cc: Per Forlin <per.forlin@linaro.org>
Subject: [PATCH] usb: gadget: storage_common: make FSG_NUM_BUFFERS variable size
Date: Mon,  8 Aug 2011 02:22:14 +0200	[thread overview]
Message-ID: <1312762934-4884-1-git-send-email-per.forlin@linaro.org> (raw)

FSG_NUM_BUFFERS is set to 2 as default.
Usually 2 buffers are enough to establish a good
double buffering pipeline. But when dealing with expensive
request preparation (i.e. dma_map) there may be benefits of
increasing the number of buffers. There is an extra cost for
every first request, the others are prepared in parallell with
an ongoing transfer. Every time all buffers are consumed there is
an additional cost for the next first request. Increasing the number
of buffers decreases the risk of running out of buffers.

Test set up
 * Running dd on the host reading from the mass storage device
 * cmdline: dd if=/dev/sdb of=/dev/null bs=4k count=$((256*100))
 * Caches are dropped on the host and on the device before each run

Measurements on a Snowball board with ondemand_govenor active.

FSG_NUM_BUFFERS 2
104857600 bytes (105 MB) copied, 5.62173 s, 18.7 MB/s
104857600 bytes (105 MB) copied, 5.61811 s, 18.7 MB/s
104857600 bytes (105 MB) copied, 5.57817 s, 18.8 MB/s
104857600 bytes (105 MB) copied, 5.57769 s, 18.8 MB/s
104857600 bytes (105 MB) copied, 5.59654 s, 18.7 MB/s
104857600 bytes (105 MB) copied, 5.58948 s, 18.8 MB/s

FSG_NUM_BUFFERS 4
104857600 bytes (105 MB) copied, 5.26839 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.2691 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.2711 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.27174 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.27261 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.27135 s, 19.9 MB/s
104857600 bytes (105 MB) copied, 5.27249 s, 19.9 MB/s

There may not be one optimal number for all boards. That is the
reason for adding the number to Kconfig,

Signed-off-by: Per Forlin <per.forlin@linaro.org>
---
 drivers/usb/gadget/Kconfig          |   15 +++++++++++++++
 drivers/usb/gadget/storage_common.c |    4 ++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 029e288..bbd17f3 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -96,6 +96,21 @@ config USB_GADGET_VBUS_DRAW
 	   This value will be used except for system-specific gadget
 	   drivers that have more specific information.
 
+config USB_GADGET_STORAGE_NUM_BUFFERS
+	int "Number of storage pipline buffers"
+	range 2 64
+	default 2
+	help
+	  Usually 2 buffers are enough to establish a good
+	  double buffering pipeline. But when dealing with expensive
+	  request preparation (i.e. dma_map) there may be benefits of
+	  increasing the number of buffers. There is an extra cost for
+	  every first request, the others are prepared in parallell with
+	  an ongoing transfer. Every time all buffers are consumed there is
+	  an additional cost for the next first request. Increasing the number
+	  of buffers decreases the risk of running out of buffers.
+	  If unsure, say 2.
+
 config	USB_GADGET_SELECTED
 	boolean
 
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 1fa4f70..512d9cf 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -262,8 +262,8 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
 #define EP0_BUFSIZE	256
 #define DELAYED_STATUS	(EP0_BUFSIZE + 999)	/* An impossibly large value */
 
-/* Number of buffers we will use.  2 is enough for double-buffering */
-#define FSG_NUM_BUFFERS	2
+/* Number of buffers we will use.  2 is usually enough for double-buffering */
+#define FSG_NUM_BUFFERS	CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
 
 /* Default size of buffer length. */
 #define FSG_BUFLEN	((u32)16384)
-- 
1.7.4.1


             reply	other threads:[~2011-08-08  0:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-08  0:22 Per Forlin [this message]
2011-08-08  9:40 ` Michal Nazarewicz
2011-08-08 10:50   ` Per Forlin
2011-08-08 11:59     ` Michal Nazarewicz
2011-08-08 14:34 ` Alan Stern
2011-08-08 18:11   ` Per Forlin
2011-08-08 18:45     ` Alan Stern
2011-08-08 19:34       ` Per Forlin
2011-08-08 20:23         ` Alan Stern
2011-08-08 20:45           ` Per Forlin

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=1312762934-4884-1-git-send-email-per.forlin@linaro.org \
    --to=per.forlin@linaro.org \
    --cc=balbi@ti.com \
    --cc=gregkh@suse.de \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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®