From patchwork Mon Aug 8 00:22:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Per Forlin X-Patchwork-Id: 3292 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 9EE142406F for ; Mon, 8 Aug 2011 00:23:26 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 977ABA18791 for ; Mon, 8 Aug 2011 00:23:20 +0000 (UTC) Received: by qwb8 with SMTP id 8so290596qwb.11 for ; Sun, 07 Aug 2011 17:23:20 -0700 (PDT) Received: by 10.229.42.10 with SMTP id q10mr936643qce.45.1312762999931; Sun, 07 Aug 2011 17:23:19 -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.6.73 with SMTP id 9cs41398qcy; Sun, 7 Aug 2011 17:23:19 -0700 (PDT) Received: from mr.google.com ([10.223.43.1]) by 10.223.43.1 with SMTP id u1mr8320617fae.38.1312762999414 (num_hops = 1); Sun, 07 Aug 2011 17:23:19 -0700 (PDT) Received: by 10.223.43.1 with SMTP id u1mr6730836fae.38.1312762998331; Sun, 07 Aug 2011 17:23:18 -0700 (PDT) Received: from mail-fx0-f50.google.com (mail-fx0-f50.google.com [209.85.161.50]) by mx.google.com with ESMTPS id k23si5979073faa.148.2011.08.07.17.23.17 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Aug 2011 17:23:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.161.50 is neither permitted nor denied by best guess record for domain of per.forlin@linaro.org) client-ip=209.85.161.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.50 is neither permitted nor denied by best guess record for domain of per.forlin@linaro.org) smtp.mail=per.forlin@linaro.org Received: by fxh2 with SMTP id 2so5276591fxh.37 for ; Sun, 07 Aug 2011 17:23:17 -0700 (PDT) Received: by 10.204.151.17 with SMTP id a17mr29281bkw.102.1312762996931; Sun, 07 Aug 2011 17:23:16 -0700 (PDT) Received: from localhost.localdomain (c-c37f71d5.029-82-6c756e10.cust.bredbandsbolaget.se [213.113.127.195]) by mx.google.com with ESMTPS id f13sm1470079bku.18.2011.08.07.17.23.13 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Aug 2011 17:23:14 -0700 (PDT) From: Per Forlin To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org Cc: Per Forlin Subject: [PATCH] usb: gadget: storage_common: make FSG_NUM_BUFFERS variable size Date: Mon, 8 Aug 2011 02:22:14 +0200 Message-Id: <1312762934-4884-1-git-send-email-per.forlin@linaro.org> X-Mailer: git-send-email 1.7.4.1 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 --- 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)