From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F579C3DA40 for ; Fri, 7 Jul 2023 14:01:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8C96E861A1; Fri, 7 Jul 2023 16:01:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20221208.gappssmtp.com header.i=@baylibre-com.20221208.gappssmtp.com header.b="uEM3vQw6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8974E863C0; Fri, 7 Jul 2023 16:01:25 +0200 (CEST) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DAE1580181 for ; Fri, 7 Jul 2023 16:01:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkorpershoek@baylibre.com Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-314319c0d3eso1983669f8f.0 for ; Fri, 07 Jul 2023 07:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1688738482; x=1691330482; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+tHJqfXmTzvWg48SMkjdIT6RWV5EXr8HAm5DktokhtU=; b=uEM3vQw608qLmm4DcjHTmIEedM47mqtc0bnf+8BhDzzkWGGMD+U+gIwAUx7SmNEm1I 7p5H7NqA10Vmylisijj+4O5VBkMHqFLn2r1w/gzq6gwOo/7lHjZKsFgSScuuWgnJ5XnG 2bZ70z0kL+V9nP59kgosdAkrx+q70X0qExHJOoyknArVw+J/VujW4bT0eEh8P3B+4vYA C5Tu0bW855D2mEfi1SI15RQmqTWyt56fgPCjdAWTGZsrqlp9g0ej6QEZDk87yzp3NujT x6rmaPOsXyT1uImIWvflWLEQhE2wjfr3Idev6CSfveoM3kOIKTnRSROwSrc8GXxSvSIT tbOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688738482; x=1691330482; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+tHJqfXmTzvWg48SMkjdIT6RWV5EXr8HAm5DktokhtU=; b=XJHbHZL2sR+Eesurlq9k0CPEqImSmYmxYUoXrstcxmxbKig/mioK4Zp5MUTQCA45e4 MIQlvmemLcyuOto/fzZKJvD7ko8an6zwLyEWb4Zze2XggnF4sKgCLO6817QMgKx7Kc7k 2F0v67aoHBFGmYRujhbtltJ2JAypSreyeVqk916PMQJV4DXU90xL4FH6HrOvMSuy0WDa zOJSMpp5CBiAFNDLU8daCUH8SKEP8Lyx5yWqHFup2OPmrm6/veq2Y15CGBl2xA9KCmFs 6jdZnp0KJQhNyshabqqXqH0FTY+2JEq6My+CaCJlg+w7xk46bW0EEc5LE6RW2sCfPy/1 Hc3w== X-Gm-Message-State: ABy/qLbnme0MUQ34sEAjf+m5xnB9Im27vAKkIV/sWnZiZpfqy9yKtbOG JLstIY4wn2RYEIVmvxR//YBojQ== X-Google-Smtp-Source: APBJJlE+Gumxo++hC9D+7h3l0WmAD1IJvhRhq2atAHuHmw/nuCwI4XzUsQzBC2PDf3WZ20tUIAKSPQ== X-Received: by 2002:a5d:6601:0:b0:314:10c1:881d with SMTP id n1-20020a5d6601000000b0031410c1881dmr4334774wru.68.1688738482311; Fri, 07 Jul 2023 07:01:22 -0700 (PDT) Received: from localhost ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1]) by smtp.gmail.com with ESMTPSA id i3-20020a5d5583000000b0030ae53550f5sm4568015wrv.51.2023.07.07.07.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 07:01:21 -0700 (PDT) From: Mattijs Korpershoek To: qianfan , Sean Anderson Cc: Guillaume La Roque , Gary Bisson , Troy Kisky , u-boot@lists.denx.de Subject: Re: [PATCH v2] lib: sparse: allocate FASTBOOT_MAX_BLK_WRITE instead of small number In-Reply-To: <0fb12072-776b-e67c-1a50-4f6272e8213f@163.com> References: <20230616-sparse-flash-fix-v2-1-25717e6cbb27@baylibre.com> <0fb12072-776b-e67c-1a50-4f6272e8213f@163.com> Date: Fri, 07 Jul 2023 16:01:20 +0200 Message-ID: <87jzvbes7j.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi Qianfan, Thank you for your review. On ven., juil. 07, 2023 at 18:54, qianfan wrote: > =E5=9C=A8 2023/7/7 16:13, Mattijs Korpershoek =E5=86=99=E9=81=93: >> Commit 62649165cb02 ("lib: sparse: Make CHUNK_TYPE_RAW buffer aligned") >> fixed cache alignment for systems with a D-CACHE. >> >> However it introduced some performance regressions [1] on system >> flashing huge images, such as Android. >> >> On AM62x SK EVM, we also observe such performance penalty: >> Sending sparse 'super' 1/2 (768793 KB) OKAY [ 23.954s] >> Writing 'super' OKAY [ 75.926s] >> Sending sparse 'super' 2/2 (629819 KB) OKAY [ 19.641s] >> Writing 'super' OKAY [ 62.849s] >> Finished. Total time: 182.474s >> >> The reason for this is that we use an arbitrary small buffer >> (info->blksz * 100) for transferring. >> >> Fix it by using a bigger buffer (info->blksz * FASTBOOT_MAX_BLK_WRITE) >> as suggested in the original's patch review [2]. >> >> With this patch, performance impact is mitigated: >> Sending sparse 'super' 1/2 (768793 KB) OKAY [ 23.912s] >> Writing 'super' OKAY [ 15.780s] >> Sending sparse 'super' 2/2 (629819 KB) OKAY [ 19.581s] >> Writing 'super' OKAY [ 17.192s] >> Finished. Total time: 76.569s >> >> [1] https://lore.kernel.org/r/20221118121323.4009193-1-gary.bisson@bound= arydevices.com >> [2] https://lore.kernel.org/r/all/43e4c17c-4483-ec8e-f843-9b4c5569bd18@s= eco.com/ >> >> Fixes: 62649165cb02 ("lib: sparse: Make CHUNK_TYPE_RAW buffer aligned") >> Signed-off-by: Mattijs Korpershoek >> --- >> Changes in v2: >> - Use FASTBOOT_MAX_BLK_WRITE instead of blkcnt (Qianfan) >> - Link to v1: https://lore.kernel.org/r/20230616-sparse-flash-fix-v1-1-6= bafeacc567b@baylibre.com >> --- >> drivers/fastboot/fb_mmc.c | 2 -- >> include/image-sparse.h | 2 ++ >> lib/image-sparse.c | 3 ++- >> 3 files changed, 4 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c >> index 9d25c402028a..060918e49109 100644 >> --- a/drivers/fastboot/fb_mmc.c >> +++ b/drivers/fastboot/fb_mmc.c >> @@ -19,8 +19,6 @@ >> #include >> #include >>=20=20=20 >> -#define FASTBOOT_MAX_BLK_WRITE 16384 >> - >> #define BOOT_PARTITION_NAME "boot" >>=20=20=20 >> struct fb_mmc_sparse { >> diff --git a/include/image-sparse.h b/include/image-sparse.h >> index 0572dbd0a283..282a0b256498 100644 >> --- a/include/image-sparse.h >> +++ b/include/image-sparse.h >> @@ -7,6 +7,8 @@ >> #include >> #include >>=20=20=20 >> +#define FASTBOOT_MAX_BLK_WRITE 16384 > Hi: > > Just a personal suggestion, define sometings like FASTBOOT_MAX_BLK_WRITE = in > image-sparse.c is very strange. > > Or maybe define a marco such as SPARSE_MAX_BLK_WRITE and set a default > value to 16384, and leave some comments for why we choice this value. I don't agree with having a duplicating between SPARSE_MAX_BLK_WRITE and FASTBOOT_MAX_BLK_WRITE. code comments can rot as well. And FASTBOOT_MAX_BLK_WRITE is used for both sparse and unsparsed image, which is why I chose to not rename it. > > Thanks. >> + >> #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) >>=20=20=20 >> struct sparse_storage { >> diff --git a/lib/image-sparse.c b/lib/image-sparse.c >> index 5ec0f94ab3eb..8f8a67e15804 100644 >> --- a/lib/image-sparse.c >> +++ b/lib/image-sparse.c >> @@ -55,7 +55,8 @@ static lbaint_t write_sparse_chunk_raw(struct sparse_s= torage *info, >> void *data, >> char *response) >> { >> - lbaint_t n =3D blkcnt, write_blks, blks =3D 0, aligned_buf_blks =3D 10= 0; >> + lbaint_t n =3D blkcnt, write_blks, blks =3D 0; >> + lbaint_t aligned_buf_blks =3D FASTBOOT_MAX_BLK_WRITE; >> uint32_t *aligned_buf =3D NULL; >>=20=20=20 >> if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) { >> >> --- >> base-commit: 923de765ee1a5b26310f02cb42dcbad9e2b011c5 >> change-id: 20230616-sparse-flash-fix-9c2852aa8d16 >> >> Best regards,