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 F0C64EB64D7 for ; Fri, 16 Jun 2023 13:26:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C2ADA8623E; Fri, 16 Jun 2023 15:26:52 +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="t8WP1goe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4ECE286241; Fri, 16 Jun 2023 15:26:50 +0200 (CEST) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 2686D86232 for ; Fri, 16 Jun 2023 15:26:47 +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-x435.google.com with SMTP id ffacd0b85a97d-3111547c8f9so539526f8f.1 for ; Fri, 16 Jun 2023 06:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1686922006; x=1689514006; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=sQ0dnZaN3CXB6IykUh/2nLF817dmil2ZwxG7rx2OIqA=; b=t8WP1goepgR7LKreg7GKDFIcoY0nt6pqcR7AQNa/yS88rZpiqi7IKdyOyAeu1+n1n0 T9+1/kzYuK5Fxsnfn/PqYbzAGWRy8EhnczXNcNoxzT7LYE9BpCxo9WstlOajDhv7lox2 fIYGm3KSuiN79D0PZo5il41lLRELqCVJ6d7UFUAaNIKVfszyrK+Jl0mF7uu2KIIrvUhI B/mD1MizLE/4ZSUJji+8si1s/sJTj2uWq53WGlSxLrw0Hy2bIUsxwBseNg3XGTrWufTv bsM7j14CTRJjRTh/+K2mOTh9DlMmwVZFpbzMVGpOmZRCDIiF6nRCp3naeXicWBCpO/6o dDlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686922006; x=1689514006; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sQ0dnZaN3CXB6IykUh/2nLF817dmil2ZwxG7rx2OIqA=; b=CWrbDvFEymsce8WsfvH0kP08X8ekWJrSUY08zW+yi3YsqiyKdMtvh/uwa3m38T/O4i EiRrFW8Zsyyh7SNMUAo47rjmaLJScwR9LOHA79ay6G6mkB9qzhjjz35dn578ggu5s5RK ZTGCHnnrFFkIp8jbSLdmaLeopM8ukhrr00C/yJcWxDNi2TilgS1/sqJoqNBFLq1ucUzb 4j8WUGzmb8v34DvBbTGom1uf5eqaVu1xoePIJXWlAusRqw1Tpmp97BSR3x8Yo6VKShYM bO/Ru1YtMLKjibmpf763ba2suwFU9wGxfDT2NTddHlJvWhpnhP3bZp+nFwTjDmM7scyO E4Vw== X-Gm-Message-State: AC+VfDzJfSAvlSS2nzb9gB1R+ETr9xA8ux62c1UzMc+5rSq/FHuqaiOK dEV2LBDJrfvXCNKRpKiak7YEZg== X-Google-Smtp-Source: ACHHUZ5StwiyX/mhb+DT3PF77vKX9rFeonIgxGmawSgHeo+O6FEu/NKJyy/GGKmqmME+wltkx2mPpw== X-Received: by 2002:a5d:4cd2:0:b0:30f:c7f9:315 with SMTP id c18-20020a5d4cd2000000b0030fc7f90315mr1399492wrt.19.1686922006512; Fri, 16 Jun 2023 06:26:46 -0700 (PDT) Received: from [192.168.1.20] ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1]) by smtp.gmail.com with ESMTPSA id r15-20020adfda4f000000b002fe96f0b3acsm23776365wrl.63.2023.06.16.06.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 06:26:46 -0700 (PDT) From: Mattijs Korpershoek Date: Fri, 16 Jun 2023 15:26:38 +0200 Subject: [PATCH] lib: sparse: allocate blkcnt instead of arbitrary small number MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230616-sparse-flash-fix-v1-1-6bafeacc567b@baylibre.com> X-B4-Tracking: v=1; b=H4sIAA1jjGQC/x2NQQqDQAxFryJZN+BM6aC9inQRx9gJ2FGSUgri3 Ru7fLz/+DsYq7DBvdlB+SMma3UIlwZyofpklMkZYhuvbQoJbSM1xnkhKzjLF/scu1sk6qaQwLO RXI9KNZczfJG9WU+xKfv+/zU8juMHCxanansAAAA= To: qianfan Zhao , Sean Anderson Cc: Guillaume La Roque , Gary Bisson , Troy Kisky , u-boot@lists.denx.de, Mattijs Korpershoek X-Mailer: b4 0.12.2 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 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 * blkcnt) as suggested in the original's patch review [2]. With this patch, performance impact is mitigated: Sending sparse 'super' 1/2 (768793 KB) OKAY [ 24.006s] Writing 'super' OKAY [ 15.920s] Sending sparse 'super' 2/2 (629819 KB) OKAY [ 19.651s] Writing 'super' OKAY [ 14.665s] Finished. Total time: 74.346s [1] https://lore.kernel.org/r/20221118121323.4009193-1-gary.bisson@boundarydevices.com [2] https://lore.kernel.org/r/all/43e4c17c-4483-ec8e-f843-9b4c5569bd18@seco.com/ Fixes: 62649165cb02 ("lib: sparse: Make CHUNK_TYPE_RAW buffer aligned") Signed-off-by: Mattijs Korpershoek --- lib/image-sparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/image-sparse.c b/lib/image-sparse.c index 5ec0f94ab3eb..25aed0604192 100644 --- a/lib/image-sparse.c +++ b/lib/image-sparse.c @@ -55,7 +55,7 @@ static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info, void *data, char *response) { - lbaint_t n = blkcnt, write_blks, blks = 0, aligned_buf_blks = 100; + lbaint_t n = blkcnt, write_blks, blks = 0, aligned_buf_blks = blkcnt; uint32_t *aligned_buf = NULL; if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) { --- base-commit: 2f4664f5c3edc55b18d8906f256a4c8e303243c0 change-id: 20230616-sparse-flash-fix-9c2852aa8d16 Best regards, -- Mattijs Korpershoek