Received: by 10.223.185.116 with SMTP id b49csp1775275wrg; Sun, 11 Feb 2018 21:08:31 -0800 (PST) X-Google-Smtp-Source: AH8x224IKjhgqaO9exHOhG+b9xkGyIZEy6bcdBFmTvkdNNVrOFt4UupjTgkcZHI9Sim9hv7olkHg X-Received: by 10.98.254.21 with SMTP id z21mr10536183pfh.48.1518412111324; Sun, 11 Feb 2018 21:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518412111; cv=none; d=google.com; s=arc-20160816; b=TqSi1AEiSz63NQP6nC21GroLybcQz9orAfsPLyM4/+hPxPRv45Ohrr+3ZlDAsH7dTL ++g50DX4C+zuY5g+S527qAVkSIF2KEPok7qNErkVS5dpjuCFZtiGO7IM7gapApV8ro6O jjTWBc6HFza1TOxS41QZCkQ4uw2vr9fyXs/5dPS4iotUvm3uaP1CXAqedR9+tt/oq4Rb Lxu9BBzlJNpVp2aTsH32BWFAPk+0x89cBdIyrwIbcJei3o1aTmZ2YWR7M4dQV4TjiB8k QoW2jgfmoZm7zT5lPXyDVNjNiAfx3+Q2bBM+IyaMrMVzqhgpTXDxsqZMiPWPlRcSx9wL 3zLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=9PPoAifCQwNDoVjFt2/1QTatzbcZboN04bkhRghqd0Q=; b=DDonwCLJu3eqMoUB4w1LOXJ3H7RK3qt8hhQgu4R79hilGCcOq0lfS8atFKIZw+xZWf h0dTS7s5KyeMjwSpGHeQXsEceF3KuSr50o7R9fRaZuLHfIBkelmkxBHJHrEHKB0ZtLnS uHxFc7LDERbCgyehKqeqLWgjJjSH5LWmbSljK6u6NPTVTiG5xNLEY8nOykQYOQ0jwd9f jzVGMR5lJAwRZ3Ed7RZ8VZFCTetH0IAY5nWG/estRDYYEKVL6NFvv+AX75d2Ct1gxtSN KnBDQ/wFGJ1qQVA2gviJRomy/3HHJi+uJMQ15Wp753VzoagyMdDun9qEhxiWZDiH6RuZ QR3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t125si3006298pgc.758.2018.02.11.21.08.16; Sun, 11 Feb 2018 21:08:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932676AbeBLDaG (ORCPT + 99 others); Sun, 11 Feb 2018 22:30:06 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48868 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932396AbeBLDaF (ORCPT ); Sun, 11 Feb 2018 22:30:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2FE780AD211; Mon, 12 Feb 2018 03:30:04 +0000 (UTC) Received: from redhat.com (ovpn-120-221.rdu2.redhat.com [10.10.120.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3052C2024CA1; Mon, 12 Feb 2018 03:30:04 +0000 (UTC) Date: Mon, 12 Feb 2018 05:30:03 +0200 From: "Michael S. Tsirkin" To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: linux-kernel@vger.kernel.org, slp@redhat.com, bhe@redhat.com, somlo@cmu.edu, xiaolong.ye@intel.com Subject: Re: [PATCH v13 4/4] RFC: fw_cfg: do DMA read operation Message-ID: <20180212052710-mutt-send-email-mst@kernel.org> References: <20180207013525.1634-1-marcandre.lureau@redhat.com> <20180207013525.1634-5-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180207013525.1634-5-marcandre.lureau@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 12 Feb 2018 03:30:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 12 Feb 2018 03:30:04 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 07, 2018 at 02:35:25AM +0100, Marc-Andr? Lureau wrote: > Modify fw_cfg_read_blob() to use DMA if the device supports it. > Return errors, because the operation may fail. > > So far, only one call in fw_cfg_register_dir_entries() is using > kmalloc'ed buf and is thus clearly eligible to DMA read. > > Initially, I didn't implement DMA read to speed up boot time, but as a > first step before introducing DMA write (since read operations were > already presents). Even more, I didn't realize fw-cfg entries were > being read by the kernel during boot by default. But actally fw-cfg > entries are being populated during module probe. I knew DMA improved a > lot bios boot time (the main reason the DMA interface was added > afaik). Let see the time it would take to read the whole ACPI > tables (128kb allocated) > > # time cat /sys/firmware/qemu_fw_cfg/by_name/etc/acpi/tables/raw > - with DMA: sys 0m0.003s > - without DMA (-global fw_cfg.dma_enabled=off): sys 0m7.674s > > FW_CFG_FILE_DIR (0x19) is the only "file" that is read during kernel > boot to populate sysfs qemu_fw_cfg directory, and it is quite > small (1-2kb). Since it does not expose itself, in order to measure > the time it takes to read such small file, I took a comparable sized > file of 2048 bytes and exposed it (-fw_cfg test,file=file with a > modified read_raw enabling DMA) > > # perf stat -r 100 cat /sys/firmware/qemu_fw_cfg/by_name/test/raw >/dev/null > - with DMA: > 0.636037 task-clock (msec) # 0.141 CPUs utilized ( +- 1.19% ) > - without DMA: > 6.430128 task-clock (msec) # 0.622 CPUs utilized ( +- 0.22% ) > > That's a few msec saved during boot by enabling DMA read (the gain > would be more substantial if other & bigger fw-cfg entries are read by > others from sysfs, unfortunately, it's not clear if we can always > enable DMA there) > > Signed-off-by: Marc-Andr? Lureau > --- > drivers/firmware/qemu_fw_cfg.c | 47 ++++++++++++++++++++++++++++++------------ > 1 file changed, 34 insertions(+), 13 deletions(-) > > diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c > index fd576ba7b337..3721dc868a2b 100644 > --- a/drivers/firmware/qemu_fw_cfg.c > +++ b/drivers/firmware/qemu_fw_cfg.c > @@ -150,11 +150,13 @@ static ssize_t fw_cfg_dma_transfer(void *address, u32 length, u32 control) > } > > /* read chunk of given fw_cfg blob (caller responsible for sanity-check) */ > -static inline void fw_cfg_read_blob(u16 key, > - void *buf, loff_t pos, size_t count) > +static ssize_t fw_cfg_read_blob(u16 key, > + void *buf, loff_t pos, size_t count, > + bool dma) > { > u32 glk = -1U; > acpi_status status; > + ssize_t ret = count; > > /* If we have ACPI, ensure mutual exclusion against any potential > * device access by the firmware, e.g. via AML methods: > @@ -164,17 +166,36 @@ static inline void fw_cfg_read_blob(u16 key, > /* Should never get here */ > WARN(1, "fw_cfg_read_blob: Failed to lock ACPI!\n"); > memset(buf, 0, count); > - return; > + return -EINVAL; > } > > mutex_lock(&fw_cfg_dev_lock); > - iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); > - while (pos-- > 0) > - ioread8(fw_cfg_reg_data); > - ioread8_rep(fw_cfg_reg_data, buf, count); > + if (dma && fw_cfg_dma_enabled()) { > + if (pos == 0) { > + ret = fw_cfg_dma_transfer(buf, count, key << 16 > + | FW_CFG_DMA_CTL_SELECT > + | FW_CFG_DMA_CTL_READ); > + } else { > + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); > + ret = fw_cfg_dma_transfer(NULL, pos, FW_CFG_DMA_CTL_SKIP); > + if (ret < 0) > + goto end; > + ret = fw_cfg_dma_transfer(buf, count, > + FW_CFG_DMA_CTL_READ); > + } > + } else { > + iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl); > + while (pos-- > 0) > + ioread8(fw_cfg_reg_data); > + ioread8_rep(fw_cfg_reg_data, buf, count); > + } > + > +end: > mutex_unlock(&fw_cfg_dev_lock); > > acpi_release_global_lock(glk); > + > + return ret; > } > These two functions share no common code at all. Pls name the dma one fw_cfg_dma_read or something like this, cleaner than a flag. > #ifdef CONFIG_CRASH_CORE > @@ -307,7 +328,7 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev) > #endif > > /* verify fw_cfg device signature */ > - fw_cfg_read_blob(FW_CFG_SIGNATURE, sig, 0, FW_CFG_SIG_SIZE); > + fw_cfg_read_blob(FW_CFG_SIGNATURE, sig, 0, FW_CFG_SIG_SIZE, false); > if (memcmp(sig, "QEMU", FW_CFG_SIG_SIZE) != 0) { > fw_cfg_io_cleanup(); > return -ENODEV; BTW it looks like fw_cfg_read_blob can fail and that failure isn't handled properly here. > @@ -494,8 +515,8 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp, struct kobject *kobj, > if (count > entry->f.size - pos) > count = entry->f.size - pos; > > - fw_cfg_read_blob(entry->f.select, buf, pos, count); > - return count; > + /* do not use DMA, virt_to_phys(buf) might not be ok */ > + return fw_cfg_read_blob(entry->f.select, buf, pos, count, false); > } > > static struct bin_attribute fw_cfg_sysfs_attr_raw = { > @@ -656,7 +677,7 @@ static int fw_cfg_register_dir_entries(void) > struct fw_cfg_file *dir; > size_t dir_size; > > - fw_cfg_read_blob(FW_CFG_FILE_DIR, &count, 0, sizeof(count)); > + fw_cfg_read_blob(FW_CFG_FILE_DIR, &count, 0, sizeof(count), false); > count = be32_to_cpu(count); > dir_size = count * sizeof(struct fw_cfg_file); > > @@ -664,7 +685,7 @@ static int fw_cfg_register_dir_entries(void) > if (!dir) > return -ENOMEM; > > - fw_cfg_read_blob(FW_CFG_FILE_DIR, dir, sizeof(count), dir_size); > + fw_cfg_read_blob(FW_CFG_FILE_DIR, dir, sizeof(count), dir_size, true); > > for (i = 0; i < count; i++) { > dir[i].size = be32_to_cpu(dir[i].size); > @@ -713,7 +734,7 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev) > goto err_probe; > > /* get revision number, add matching top-level attribute */ > - fw_cfg_read_blob(FW_CFG_ID, &fw_cfg_rev, 0, sizeof(fw_cfg_rev)); > + fw_cfg_read_blob(FW_CFG_ID, &fw_cfg_rev, 0, sizeof(fw_cfg_rev), false); > fw_cfg_rev = le32_to_cpu(fw_cfg_rev); > err = sysfs_create_file(fw_cfg_top_ko, &fw_cfg_rev_attr.attr); > if (err) > -- > 2.16.1.73.g5832b7e9f2