Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2956606lqt; Tue, 23 Apr 2024 06:51:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWrXIThTthI6wo9eG0IJkmilA+y5uyRFDXO8X74FF3nRJZWltMrj8kZ6cmmz3NKHiEhuJTx7FMqlpWeqfjUU6iX/WdfzsIUclKWPDkUw== X-Google-Smtp-Source: AGHT+IEsCi483/KthTpYeOBrD9N4JdcK0pd+tgCjNUwzUZm+j5GXwmatwCMh8nswsugmbxZXJ1Oo X-Received: by 2002:a17:902:c40c:b0:1e3:e8e9:5f28 with SMTP id k12-20020a170902c40c00b001e3e8e95f28mr16484413plk.57.1713880284536; Tue, 23 Apr 2024 06:51:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713880284; cv=pass; d=google.com; s=arc-20160816; b=h2Q7gZAcUnqr7QkKAY9K86bRqEkF7dHZPvKx3a/B+t/mehl5H4LfAOmPUwzz3bKGrk Ws4A26K+sNa/wve/UdJqwjFlyOfT7pRdFYMR8bx3Nay0NNo/W8oRxNkWNFiJXTQbd4SN tgWCXbct+18T/QFM/su6onlVtu7Ooz6tA180j9Taj6uRU6LHexkaeCXfV6q6NjqPwG0U udRpYiy/j+nmofFmw82Z62fU2+uwhbtTsSh/iT7wQEzlQ3G8pLv9tJNnY0qMjGOR8AcB W8aZqCBQIDPY7TEkUz9SricEzK1hdDjwuYL076QjioVYpft1IrHUPEgYoZUYgKMkDIx7 obDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:autocrypt:references :in-reply-to:date:cc:to:from:subject:message-id:dkim-signature; bh=nib8F95UZBHIkvsgKRgDHam5AsiuTEtg6tBahXJN6/Y=; fh=mFRBjBwIyj/OKi2PPG0yezgswR6jjhbSYJMBCZGPc4k=; b=aHo1FbjY6pqKWg+nQTP21RC7xviV/n4Io/pSSTzCTOBbgi40Ucxk3pCfuMovJTp3Fq Ritcbvn7y0yWKz+/wk0cDi6+9QRag8jYBfZfW/WGsFsJhfRDCQp13hxY9jN8jnXWEafY g6wZSOQIIgn7KAW7qAqbzZtJR5crPj3NlEeO6Tkt5PmoOptPQVbE/Srwsb6SWP+/ROSZ Pz+Y4fbkOjimIUAN26QnXXfPzeX1aSga3xodTN6BQOvU+MqSiYdUSlMuYKJHwM5UExp8 hCpKrEkI06PjHFoyjL4uHy9Gotsxrm4qrh3ulsiy0+LgQSQl/7H0vGoXVjyBdaJgVu9o Pq/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="bGN/LraB"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-155306-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d21-20020a170903209500b001dcd4f9fd0dsi8675606plc.455.2024.04.23.06.51.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:51:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155306-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="bGN/LraB"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-155306-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E90D228A57B for ; Tue, 23 Apr 2024 13:49:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E444D138480; Tue, 23 Apr 2024 13:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="bGN/LraB" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4011D136E2D; Tue, 23 Apr 2024 13:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880068; cv=none; b=n4nGNfCN6+IMo6BP1gRzzeDkWcAEIeN5J7n1PgvHRt/ah+CpO3qjz8ZdVykmjcRtDJpb3SMGN0JJML68cvKQZVFwWlhPHLBJKyls1l0G0xjF6lOCf4VOvA1fwrVe31eVJEDtGAnuIJVOP7xZONYDgEvjJfuezeMqDWtvHB0POqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880068; c=relaxed/simple; bh=nib8F95UZBHIkvsgKRgDHam5AsiuTEtg6tBahXJN6/Y=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=cF+uUWZf8Ud2trbxOEkOWgoWIxq/uch4sgrBuDqxzAYCvz0GDBl6ptAvqEDeuDQ14Fk4KRtKaArKR8+1qBB5ucJPfoCgJldWImAyz7HjOnGpMD+qZJ5dvNCgSh26xk5EoRBt1ksx2uUwLnVjUC0CHGcgd1BtrGKfz3HdKtKDGeQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=bGN/LraB; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1713880065; bh=nib8F95UZBHIkvsgKRgDHam5AsiuTEtg6tBahXJN6/Y=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bGN/LraBEVJdD1k/MZ2viZkxUY9oxP8GBJivAx7QzKXInUHc4YACjfmlOB6c3JKXw dEGnt852Qvroj+AmBwv7jOhhUBdzYcrWrKkFM7rsUBIejkTG2cbRPbTpkRzvpj+IN0 s85H/m7gN2t+k7plu8I+s+yqg3d6XRYnNhwX6pl40j3JS942jpttnWY70vxh4+W8OO X5zsD0bH/+I3/NLl7iMNEFlBO/ASG53H1Qj3L3QPmq0KaW1kZiFuEjSiEEfcILrKE/ 8VAp2fSjG9GI2x93npaQCpyz8MbN9g5OW7nlNkr++bUPN8isPe7YepT13hCcFsEmff 6uYBK/T7/JzRg== Received: from nicolas-tpx395.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nicolas) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 0CA4B3782136; Tue, 23 Apr 2024 13:47:42 +0000 (UTC) Message-ID: Subject: Re: [PATCH] media: mediatek: vcodec: Alloc DMA memory with DMA_ATTR_ALLOC_SINGLE_PAGES From: Nicolas Dufresne To: Doug Anderson Cc: Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Mauro Carvalho Chehab , Matthias Brugger , AngeloGioacchino Del Regno , Wei-Shun Chang , Hans Verkuil , =?ISO-8859-1?Q?N=EDcolas?= "F. R. A. Prado" , Rob Herring , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Date: Tue, 23 Apr 2024 09:47:39 -0400 In-Reply-To: References: <20240422100354.1.I58b4456c014a4d678455a4ec09b908b1c71c3017@changeid> <022936a6704d08fbed22e7f241810d857eecaeda.camel@collabora.com> Autocrypt: addr=nicolas.dufresne@collabora.com; prefer-encrypt=mutual; keydata=mQGiBEUQN0MRBACQYceNSezSdMjx7sx6gwKkMghrrODgl3B0eXBTgNp6c431IfOOEsdvkoOh1kwoYcQgbg4MXw6beOltysX4e8fFWsiRkc2nvvRW9ir9kHDm49MkBLqaDjTqOkYKNMiurFW+gozpr/lUW15QqT6v68RYe0zRdtwGZqeLzX2LVuukGwCg4AISzswrrYHNV7vQLcbaUhPgIl0D+gILYT9TJgAEK4YHW+bFRcY+cgUFoLQqQayECMlctKoLOE69nIYOc/hDr9uih1wxrQ/yL0NJvQCohSPyoyLF9b2EuIGhQVp05XP7FzlTxhYvGO/DtO08ec85+bTfVBMV6eeY4MS3ZU+1z7ObD7Pf29YjyTehN2Dan6w1g2rBk5MoA/9nDocSlk4pbFpsYSFmVHsDiAOFje3+iY4ftVDKunKYWMhwRVBjAREOByBagmRau0cLEcElpf4hX5f978GoxSGIsiKoDAlXX+ICDOWC1/EXhEEmBR1gL0QJgiVviNyLfGJlZWnPjw6xhhmtHYWTDxBOP5peztyc2PqeKsLsLWzAr7RDTmljb2xhcyBEdWZyZXNuZSAoQ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uIEluZm9ybWF0aXF1ZSkgPG5pY29sYXMuZHVmcmVzbmVAdXNoZXJicm9va2UuY2E+iGAEExECACAFAkUQN0MCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRBxUwItrAaoHPTnAJ0WGgJJVspoctAvEcI00mtp5WAFGgCgr+E7ItOqZEHAs+xabBgknYZIFPW5Ag0ERRA3UhAIAJ0rxl2HsVg/nSOAUt7U/T/W+RKzVAlD9orCB0pRVvyWNxSr8MHcHmWCxykLuB34ouM4GuDVRKfGnqLzJRBfjs7Ax9K2FI3Odund9xpviLCt1jFC0K XL04RebrFT7xjDfocDaSLFvgxMVs/Jr2/ckKPId1oKvgYgt/o+MzUabKyFB8wIvq4GMtj3LoBKLCie2nCaSt7uVUt6q2t5bNWrd3lO6/mWn7YMc5Hsn33H9pS0+9szw6m3dG08eMKNueDlt72QxiYl2rhjzkT4ltKEkFgYBdyrtIj1UO6eX+YXb4E1rCMJrdjBSgqDPK1sWHC7gliy+izr+XTHuFwlfy8gBpsAAwUIAJJNus64gri4HAL632eqVpza83EphX1IuHzLi1LlMnQ9Tm7XKag46NhmJbOByMG33LwBsBdLjjHQSVkYZFWUifq+NWSFC/kqlb72vW8rBAv64+i3QdfxK9FWbweiRsPpvuHjJQuecbPDJpubLaxKbu2aqLCN5LuHXvdQr6KiXwabT+OJ9AJAqHG7q4IEzg4RNUVn9AS6L8bxqMSocjqpWNBCY2efCVd/c6k4Acv6jXu+wDAZEbWXK+71uaUHExhigBYBpiHGrobe32YlTVE/XEIzKKywhm/Hkn5YKWzumLte6xiD9JhKabmD7uqIvLt2twUpz4BdPzj0dvGlSmvFcaaISQQYEQIACQUCRRA3UgIbDAAKCRBxUwItrAaoHJLyAKDeS3AFowM3f1Y3OFU6XRCTKK2ZhwCfT/7P9WDjkkmiq5AfeOiwVlpuHtM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hey, Le lundi 22 avril 2024 =C3=A0 12:25 -0700, Doug Anderson a =C3=A9crit=C2=A0= : > Hi, >=20 > On Mon, Apr 22, 2024 at 11:27=E2=80=AFAM Nicolas Dufresne > wrote: > >=20 > > Hi, > >=20 > > Le lundi 22 avril 2024 =C3=A0 10:03 -0700, Douglas Anderson a =C3=A9cri= t : > > > As talked about in commit 14d3ae2efeed ("ARM: 8507/1: dma-mapping: Us= e > > > DMA_ATTR_ALLOC_SINGLE_PAGES hint to optimize alloc"), it doesn't > > > really make sense to try to allocate contiguous chunks of memory for > > > video encoding/decoding. Let's switch the Mediatek vcodec driver to > > > pass DMA_ATTR_ALLOC_SINGLE_PAGES and take some of the stress off the > > > memory subsystem. > > >=20 > > > Signed-off-by: Douglas Anderson > > > --- > > > NOTE: I haven't personally done massive amounts of testing with this > > > change, but I originally added the DMA_ATTR_ALLOC_SINGLE_PAGES flag > > > specifically for the video encoding / decoding cases and I know it > > > helped avoid memory problems in the past on other systems. Colleagues > > > of mine have told me that with this change memory problems are harder > > > to reproduce, so it seems like we should consider doing it. > >=20 > > One thing to improve in your patch submission is to avoid abstracting t= he > > problems. Patch review and pulling is based on a technical rational and= very > > rarely on the trust that it helps someone somewhere in some unknown con= text. > > What kind of memory issues are you facing ? What is the technical advan= tage of > > using DMA_ATTR_ALLOC_SINGLE_PAGES over the current approach that helps = fixing > > the issue? I do expect this to be documented in the commit message itse= lf=C3=A9. >=20 > Right. The problem here is that I'm not _directly_ facing any problems > here and I also haven't done massive amounts of analysis of the > Mediatek video codec. I know that some of my colleagues have run into > issues on Mediatek devices where the system starts getting > unresponsive when lots of videos are decoded in parallel. That > reminded me of the old problem I debugged in 2015 on Rockchip > platforms and is talked about a bunch in the referenced commit > 14d3ae2efeed ("ARM: 8507/1: dma-mapping: Use > DMA_ATTR_ALLOC_SINGLE_PAGES hint to optimize alloc") so I wrote up > this patch. The referenced commit contains quite a bit of details > about the problems faced back in 2015. >=20 > When I asked, my colleagues said that my patch seemed to help, though > it was more of a qualitative statement than a quantitative one. >=20 > I wasn't 100% sure if it was worth sending the patch up at this point, > but logically, I think it makes sense. There aren't great reasons to > hog all the large chunks of memory for video decoding. Ok, slowly started retracing this 2016 effort (which now I understand you w= here deeply involved in). Its pretty clear this hint is only used for codecs. On= e thing the explanation seems missing (or that I missed) is that all the enab= led drivers seems to come with a dedicated mmu (dedicated TLB). But this argume= nt seems void if it is not combined with DMA_ATTR_NO_KERNEL_MAPPING to avoid u= sing the main mmu TLB space. There is currently three drivers using S5P_MFC, Han= tro and RKVDEC that uses this hint, only Hantro sets the DMA_ATTR_NO_KERNEL_MAP= PING hint. It would be nice to check if VCODEC needs kernel mapping on the RAW images,= and introduce that hint too while introducing DMA_ATTR_ALLOC_SINGLE_PAGES. But = with a now proper understanding, I also feel like this is wanted , but I'll have= a hard time thinking of a test that shows the performance gain, since it requ= ires specific level of fragmentation in the system to make a difference. Another aspect of the original description that is off, is CODECs doing lin= ear access, while this is mostly true for reconstruction (writes), this is not = true for prediction (reads). What really matters is that the CODECs tiles are mo= st of the time no bigger then a page, or less then a handful of pages. Nicolas