From patchwork Mon Aug 8 21:43:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Per Forlin X-Patchwork-Id: 3304 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 9B4F523F4D for ; Mon, 8 Aug 2011 21:49:00 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id 45E84A1846E for ; Mon, 8 Aug 2011 21:49:00 +0000 (UTC) Received: by qyk31 with SMTP id 31so2934169qyk.11 for ; Mon, 08 Aug 2011 14:48:59 -0700 (PDT) Received: by 10.224.209.9 with SMTP id ge9mr4630685qab.19.1312840139693; Mon, 08 Aug 2011 14:48:59 -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 dh7cs27169qcb; Mon, 8 Aug 2011 14:48:55 -0700 (PDT) Received: from mr.google.com ([10.223.159.137]) by 10.223.159.137 with SMTP id j9mr10261633fax.64.1312840135536 (num_hops = 1); Mon, 08 Aug 2011 14:48:55 -0700 (PDT) Received: by 10.223.159.137 with SMTP id j9mr8256229fax.64.1312840134609; Mon, 08 Aug 2011 14:48:54 -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 d23si466231fak.18.2011.08.08.14.48.53 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Aug 2011 14:48:54 -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 2so6519184fxh.37 for ; Mon, 08 Aug 2011 14:48:53 -0700 (PDT) Received: by 10.223.56.79 with SMTP id x15mr8184957fag.130.1312839832895; Mon, 08 Aug 2011 14:43:52 -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 y15sm4454725fah.35.2011.08.08.14.43.50 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Aug 2011 14:43:52 -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, Michal Nazarewicz , Alan Stern Cc: Per Forlin Subject: [PATCH v3] usb: gadget: storage_common: make FSG_NUM_BUFFERS variable size Date: Mon, 8 Aug 2011 23:43:35 +0200 Message-Id: <1312839815-30886-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 buffering pipeline. The number may be increased in order to compensate a for bursty VFS behaviour. Here follows a description of system that may require more than 2 buffers. * CPU ondemand governor active * latency cost for wake up and/or frequency change * DMA for IO Use case description. * Data transfer from MMC via VFS to USB. * DMA shuffles data from MMC and to USB. * The CPU wakes up every now and then to pass data in and out from VFS, which cause the bursty VFS behaviour. 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 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 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 --- Change log. v2: Update after proofreading comments from Michal Nazarewicz v3: Clarify the description of this patch based on input from Alan Stern drivers/usb/gadget/Kconfig | 14 ++++++++++++++ drivers/usb/gadget/storage_common.c | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 029e288..24d3ef5 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -96,6 +96,20 @@ 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 4 + default 2 + help + Usually 2 buffers are enough to establish a good buffering + pipeline. The number may be increased in order to compensate + for a bursty VFS behaviour. For instance there may be cpu wake up + latencies that makes the VFS to appear bursty in a system with + an cpu on-demand governor. Especially if DMA is doing IO to + offload the CPU. In this case the CPU will go into power + save often and spin up occasionally to move data within VFS. + 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)