From patchwork Mon Aug 8 10:57:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Per Forlin X-Patchwork-Id: 3297 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0D17723F5E for ; Mon, 8 Aug 2011 10:58:55 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id B27B5A181E5 for ; Mon, 8 Aug 2011 10:58:54 +0000 (UTC) Received: by qyk31 with SMTP id 31so1686790qyk.11 for ; Mon, 08 Aug 2011 03:58:54 -0700 (PDT) Received: by 10.229.159.194 with SMTP id k2mr729182qcx.83.1312801133981; Mon, 08 Aug 2011 03:58:53 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.190.71 with SMTP id dh7cs10143qcb; Mon, 8 Aug 2011 03:58:53 -0700 (PDT) Received: from mr.google.com ([10.14.37.75]) by 10.14.37.75 with SMTP id x51mr1666569eea.62.1312801133160 (num_hops = 1); Mon, 08 Aug 2011 03:58:53 -0700 (PDT) Received: by 10.14.37.75 with SMTP id x51mr1250546eea.62.1312801132433; Mon, 08 Aug 2011 03:58:52 -0700 (PDT) Received: from eu1sys200aog115.obsmtp.com (eu1sys200aog115.obsmtp.com [207.126.144.139]) by mx.google.com with SMTP id x18si3347528eej.184.2011.08.08.03.58.36 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Aug 2011 03:58:52 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.139 is neither permitted nor denied by best guess record for domain of per.forlin@stericsson.com) client-ip=207.126.144.139; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.139 is neither permitted nor denied by best guess record for domain of per.forlin@stericsson.com) smtp.mail=per.forlin@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob115.postini.com ([207.126.147.11]) with SMTP ID DSNKTj/BXA5faX4JYuyDtSBfLNztCy9w9Nfo@postini.com; Mon, 08 Aug 2011 10:58:51 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 67B0F50; Mon, 8 Aug 2011 10:58:06 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id BE31D54; Mon, 8 Aug 2011 10:58:05 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 6681924C075; Mon, 8 Aug 2011 12:57:59 +0200 (CEST) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 8 Aug 2011 12:58:05 +0200 From: Per Forlin To: Felipe Balbi , Greg Kroah-Hartman , Michal Nazarewicz Cc: , , , Per Forlin Subject: [PATCH v2] usb: gadget: storage_common: make FSG_NUM_BUFFERS variable size Date: Mon, 8 Aug 2011 12:57:40 +0200 Message-ID: <1312801060-11850-1-git-send-email-per.forlin@stericsson.com> X-Mailer: git-send-email 1.6.3.3 MIME-Version: 1.0 From: Per Forlin FSG_NUM_BUFFERS is set to 2 as default. Usually 2 buffers are enough to establish a good 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 parallel with an ongoing transfer. Every time all buffers are consumed there is an additional cost for the 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. This is why the number is added to Kconfig. Signed-off-by: Per Forlin Acked-by: Michal Nazarewicz --- drivers/usb/gadget/Kconfig | 15 +++++++++++++++ drivers/usb/gadget/storage_common.c | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 029e288..1888a16 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 pipeline buffers" + range 2 64 + default 2 + help + Usually 2 buffers are enough to establish a good + 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 parallel with + an ongoing transfer. Every time all buffers are consumed there is + an additional cost for the 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..683c972 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -262,8 +262,11 @@ 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 good buffering pipeline + */ +#define FSG_NUM_BUFFERS CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS /* Default size of buffer length. */ #define FSG_BUFLEN ((u32)16384)