Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1333831imm; Sat, 4 Aug 2018 01:03:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdOimoC7/Jj0VrWSSND9vmdKNTcYJ/Eq0lGa/a00qQzauaWyA61Jkg953YieoxCybYwI/Iu X-Received: by 2002:a65:62cd:: with SMTP id m13-v6mr6761367pgv.280.1533369798106; Sat, 04 Aug 2018 01:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533369797; cv=none; d=google.com; s=arc-20160816; b=IUJv2XFNHan8WpcbO4y/67BOJ7BSXz+vv7XMm01teRlcBBTngy4J29mflLAtbma/29 OxHibXsvXJmEwbyfnats6F8yAPT3AZCDMGiQZcvqHhBWAQf/enUXtZYfZR57xzqOhOK8 HUq2/eyeyf+AThz6iJtdhQ37vZlIOQMBrJDVKk85nyOVM2RT6gcwfdwTGE2Dvo0UBoyg PbFPCya2JkQAVsLfctefbQs8ag4+7D7cLyY3UvYrufI90K0wBjpkFu6+JWNsU+NxRI7w 2x1XW4yxHMtTg/0pSWytxwYEJyPKrynrA+qPeimXjoAoPR9nCrsueQ/jQAchNLTcfbRn hMAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=TnrRxH7hpSxjUXlMOo0osfu5mjWzOeK8d80zX04cfhk=; b=evtsEm1obYmyQlCcRNLXtvddfeJwqigqzctEa37UUgYVoTAATjSciAGS4bY5v48uCv qSCLCP/WFwU9eUUBnGt57mXog4G1Sdv5soWbUb1i9Vge4Inm6du61oeSB+SfBc+sL4hn Db7ktJRhnkN3JTBsRGgBq4OpJxwKSsVbbHvZcT3Yvg+/DRocfOup0mwPbVmht8MaHUBT OqCNPXNJqnxuIZO8bQPUhuCICxldc0gDiLaWe6qQvc4oOwQEgSUc274BT+3YN+KEAPcS kxRqdfSu3eJ6NCHzaEsYg8Mqz2FxRfh+LBEutKy/SnV5+W+YXR89+H5xLiesd7Byi+Gn JIcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=L+fwd96+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a75-v6si7964914pfc.106.2018.08.04.01.02.37; Sat, 04 Aug 2018 01:03:17 -0700 (PDT) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=L+fwd96+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726983AbeHDKAO (ORCPT + 99 others); Sat, 4 Aug 2018 06:00:14 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:46724 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbeHDKAN (ORCPT ); Sat, 4 Aug 2018 06:00:13 -0400 Received: by mail-oi0-f67.google.com with SMTP id y207-v6so13800562oie.13; Sat, 04 Aug 2018 01:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=TnrRxH7hpSxjUXlMOo0osfu5mjWzOeK8d80zX04cfhk=; b=L+fwd96+rh/DAK1BM1Q90aiha7E/iKgq5BcmkwpOgZ234Em+7C3vy7JwExhBTfNSux 8b5RV/6O2f3JQBEkvX0/AzK4P16oVdKs6vvELBtCwRPbxfFukfddqNKRc17OZO1wHJw6 wtJ5m/g3PWVaAeH+8obfTzOILxo7ICKHMCRLU2/LBB19o+DNWY4nPADaunh7oJUJXrDu KmAo1O1V9QblFwyeqXWdu0aA4tWLCLrdBQroI0YLPmbhMQ20G2lgU1BwGAASFOKLFEWT +cAy4hf3+BglnadihVJ0Ij8knTwi9aZm17IYdzBBbUC/9w/C1V4BSlg5nxol6kiZ0YSB P+0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=TnrRxH7hpSxjUXlMOo0osfu5mjWzOeK8d80zX04cfhk=; b=HOGac2DvI6vE3M52rIspD3YZfVEGUJ0d5tUfwlXeJbhqXpHasLULVprLfhRGNoojxC bpFSsJjQn3XQgi+dbW1a4Rm+XFQQ+CjPxw3kGc+QHhTMAMxNu16lsIQdRQMhhuFmxQrD SZjQJ3hbdl7YF3PP2ncXFgfNyw/J105cBl4j0aUAJOngvYx1Ltq4sCzR9E/3T3rk3VO3 DKPuW1E55Gx8JvmfSJ+euU64BXk6MzobDmYeXb6is+j47aDG4Zd6ct3T671pEvFPO/BY iK+o3d+PGamse5QOv/vjGFgk72Ekr3Nrw9yu/emRzk/gGtLNnwMTbbjpkxfI7A+J+gd1 TIEQ== X-Gm-Message-State: AOUpUlHr8tltsiZpIfOUapBVxY42JPKXSzhc4DRtfV+tsAdM1bWQPT1b 000VgAeQmK/CMgazoQjUKEsY3QLgFYtpm+Ksr7I= X-Received: by 2002:aca:c514:: with SMTP id v20-v6mr6813002oif.153.1533369626302; Sat, 04 Aug 2018 01:00:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:734:0:0:0:0:0 with HTTP; Sat, 4 Aug 2018 01:00:05 -0700 (PDT) In-Reply-To: <1556658.LS2rrRvGR3@avalon> References: <1556658.LS2rrRvGR3@avalon> From: "Matwey V. Kornilov" Date: Sat, 4 Aug 2018 11:00:05 +0300 X-Google-Sender-Auth: 5CjSUtvDaBZKN4Opv0Q2uu4BVT8 Message-ID: Subject: Re: [PATCH 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer To: Laurent Pinchart Cc: Alan Stern , Tomasz Figa , Ezequiel Garcia , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab , Steven Rostedt , mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , Linux Media Mailing List , Linux Kernel Mailing List , Kieran Bingham , keiichiw@chromium.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-07-30 18:35 GMT+03:00 Laurent Pinchart : > Hi Matwey, > > On Tuesday, 24 July 2018 21:56:09 EEST Matwey V. Kornilov wrote: >> 2018-07-23 21:57 GMT+03:00 Alan Stern: >> > On Mon, 23 Jul 2018, Matwey V. Kornilov wrote: >> >> I've tried to strategies: >> >> >> >> 1) Use dma_unmap and dma_map inside the handler (I suppose this is >> >> similar to how USB core does when there is no URB_NO_TRANSFER_DMA_MAP) >> > >> > Yes. >> > >> >> 2) Use sync_cpu and sync_device inside the handler (and dma_map only >> >> once at memory allocation) >> >> >> >> It is interesting that dma_unmap/dma_map pair leads to the lower >> >> overhead (+1us) than sync_cpu/sync_device (+2us) at x86_64 platform. >> >> At armv7l platform using dma_unmap/dma_map leads to ~50 usec in the >> >> handler, and sync_cpu/sync_device - ~65 usec. >> >> >> >> However, I am not sure is it mandatory to call >> >> dma_sync_single_for_device for FROM_DEVICE direction? >> > >> > According to Documentation/DMA-API-HOWTO.txt, the CPU should not write >> > to a DMA_FROM_DEVICE-mapped area, so dma_sync_single_for_device() is >> > not needed. >> >> Well, I measured the following at armv7l. The handler execution time >> (URB_NO_TRANSFER_DMA_MAP is used for all cases): >> >> 1) coherent DMA: ~3000 usec (pwc is not functional) >> 2) explicit dma_unmap and dma_map in the handler: ~52 usec >> 3) explicit dma_sync_single_for_cpu (no dma_sync_single_for_device): ~56 >> usec > > I really don't understand why the sync option is slower. Could you please > investigate ? Before doing anything we need to make sure we have a full > understanding of the problem. Hi, I've found one drawback in my measurements. I forgot to fix CPU frequency at lowest state 300MHz. Now, I remeasured 2) dma_unmap and dma_map in the handler: 2A) dma_unmap_single call: 28.8 +- 1.5 usec 2B) memcpy and the rest: 58 +- 6 usec 2C) dma_map_single call: 22 +- 2 usec Total: 110 +- 7 usec 3) dma_sync_single_for_cpu 3A) dma_sync_single_for_cpu call: 29.4 +- 1.7 usec 3B) memcpy and the rest: 59 +- 6 usec 3C) noop (trace events overhead): 5 +- 2 usec Total: 93 +- 7 usec So, now we see that 2A and 3A (as well as 2B and 3B) agree good within error ranges. > >> So, I suppose that unfortunately Tomasz suggestion doesn't work. There >> is no performance improvement when dma_sync_single is used. >> >> At x86_64 the following happens: >> >> 1) coherent DMA: ~2 usec > > What do you mean by coherent DMA for x86_64 ? Is that usb_alloc_coherent() ? > Could you trace it to see how memory is allocated exactly, and how it's mapped > to the CPU ? I suspect that it will end up in dma_direct_alloc() but I'd like > a confirmation. usb_alloc_coherents() ends up inside hcd_buffer_alloc() where dma_alloc_coherent() is called. Keep in mind, that requested size is 9560 in our case and pool is not used. > >> 2) explicit dma_unmap and dma_map in the handler: ~3.5 usec >> 3) explicit dma_sync_single_for_cpu (no dma_sync_single_for_device): ~4 usec >> >> So, whats to do next? Personally, I think that DMA streaming API >> introduces not so great overhead. > > It might not be very large, but with USB3 cameras at high resolutions and > framerates, it might still become noticeable. I wouldn't degrade performances > on x86, especially if we can decide which option to use based on the platform > (or perhaps even better based on Kconfig options such as DMA_NONCOHERENT). PWC is discontinued chip, so there will not be any new USB3 cameras. Kconfig won't work here, as I said before, DMA config is stored inside device tree blob on ARM architecture. > >> Does anybody happy with turning to streaming DMA or I'll introduce >> module-level switch as Ezequiel suggested? > > A module-level switch isn't a good idea, it will just confuse users. We need > to establish a strategy and come up with a good heuristic that can be applied > at compile and/or runtime to automatically decide how to allocate buffers. I am agree in general, but I cannot understand why webcam driver should think about memory allocation heuristics. > > -- > Regards, > > Laurent Pinchart > > > -- With best regards, Matwey V. Kornilov. Sternberg Astronomical Institute, Lomonosov Moscow State University, Russia 119234, Moscow, Universitetsky pr-k 13, +7 (495) 9392382