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 655AAC4332F for ; Fri, 18 Nov 2022 12:13:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9801C85248; Fri, 18 Nov 2022 13:13:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=boundarydevices.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=boundarydevices.com header.i=@boundarydevices.com header.b="UsI6u/8M"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 442788524C; Fri, 18 Nov 2022 13:13:31 +0100 (CET) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 13D7585236 for ; Fri, 18 Nov 2022 13:13:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=boundarydevices.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=gary.bisson@boundarydevices.com Received: by mail-wr1-x42c.google.com with SMTP id k8so9041789wrh.1 for ; Fri, 18 Nov 2022 04:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=boundarydevices.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=z7F7YBsoN8crg4H1jv3kgijUwOOIPs9TV5OBwPei2m8=; b=UsI6u/8M6hxkiT+EQn066BS8ZLok3+MAD2hZlyT20ztBOUy1XEN+s6pkGBuwhbceti Gs3oIOY4Dup2Ymq0S1QbtXvGyXxOAgZ9IsJUf+cKB2hBx8sgbGMrD9NziUGsXWThsPdI FA3jlQkEu1a6+cB5HzgGEs3y9y1bl0fJkrKkM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z7F7YBsoN8crg4H1jv3kgijUwOOIPs9TV5OBwPei2m8=; b=k/T7ZDj8OKu8ksclwdmnJ6SXi4rUuSLtExfOCH8GhvSKtHYNeVaKkZ+dfhbCWlGn3s g/ZISHhgvDgLrf1jIbBGy4rlTtK155oTEvSytQa+pdvPyIp69wOGevvHmDaQ8R0nTFw4 BFA/shfKfpVIgl12yIYPQc+hEtU30yF0P43ZlP/bAYQYEXtM9hgDnTuAr6Yun+os4uuX XBh4Da50035eXbfKsptzl6jlpqFh2MPAZV5BzDx6JZwwwy5fzOquJtMAPCxQQ28464YK RCV3fFEiiOH5KHL384Ke5ok1qua8Xg6nDzGkRaUZ2F/cC/jDNkt8eIY6Ml8VdmbbCIp2 Uwzg== X-Gm-Message-State: ANoB5pkuJHqtte4uSQJGOs/XFzT/OMkBpjNMD0P68s/ueNim1gM24lz4 WozI2BVRVsJwZjN1o7oJI9nLIl1QQKYhDQ== X-Google-Smtp-Source: AA0mqf6nItfnK/b12S/rAYf6/04V2/5GGuvLcK8xnv3dIjSZTph6MuTZ/MzkGXtrrD1wQidS5dG0+Q== X-Received: by 2002:a5d:6dcf:0:b0:236:78b7:87c9 with SMTP id d15-20020a5d6dcf000000b0023678b787c9mr4085441wrz.556.1668773608111; Fri, 18 Nov 2022 04:13:28 -0800 (PST) Received: from p1g2.home (2a01cb000f892400bac0522898b75ff0.ipv6.abo.wanadoo.fr. [2a01:cb00:f89:2400:bac0:5228:98b7:5ff0]) by smtp.gmail.com with ESMTPSA id n128-20020a1ca486000000b003c70191f267sm8690547wme.39.2022.11.18.04.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 04:13:27 -0800 (PST) From: Gary Bisson To: u-boot@lists.denx.de Cc: qianfanguijin@163.com, sean.anderson@seco.com, Gary Bisson , Troy Kisky Subject: [PATCH] Revert "lib: sparse: Make CHUNK_TYPE_RAW buffer aligned" Date: Fri, 18 Nov 2022 13:13:23 +0100 Message-Id: <20221118121323.4009193-1-gary.bisson@boundarydevices.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean This reverts commit 62649165cb02ab95b57360bb362886935f524f26. The patch decreased the write performance quite a bit. Here is an example on an i.MX 8M Quad platform. - Before the revert: Sending sparse 'vendor' 1/2 (516436 KB) OKAY [ 5.113s] Writing 'vendor' OKAY [128.335s] Sending sparse 'vendor' 2/2 (76100 KB) OKAY [ 0.802s] Writing 'vendor' OKAY [ 27.902s] - After the revert: Sending sparse 'vendor' 1/2 (516436 KB) OKAY [ 5.310s] Writing 'vendor' OKAY [ 18.041s] Sending sparse 'vendor' 2/2 (76100 KB) OKAY [ 1.244s] Writing 'vendor' OKAY [ 2.663s] Considering that the patch only moves buffer around to avoid a warning message about misaligned buffers, let's keep the best performances. Signed-off-by: Gary Bisson Signed-off-by: Troy Kisky --- lib/image-sparse.c | 69 ++++++---------------------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/lib/image-sparse.c b/lib/image-sparse.c index 5ec0f94ab3e..d80fdbbf58e 100644 --- a/lib/image-sparse.c +++ b/lib/image-sparse.c @@ -46,66 +46,9 @@ #include #include -#include static void default_log(const char *ignored, char *response) {} -static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info, - lbaint_t blk, lbaint_t blkcnt, - void *data, - char *response) -{ - lbaint_t n = blkcnt, write_blks, blks = 0, aligned_buf_blks = 100; - uint32_t *aligned_buf = NULL; - - if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) { - write_blks = info->write(info, blk, n, data); - if (write_blks < n) - goto write_fail; - - return write_blks; - } - - aligned_buf = memalign(ARCH_DMA_MINALIGN, info->blksz * aligned_buf_blks); - if (!aligned_buf) { - info->mssg("Malloc failed for: CHUNK_TYPE_RAW", response); - return -ENOMEM; - } - - while (blkcnt > 0) { - n = min(aligned_buf_blks, blkcnt); - memcpy(aligned_buf, data, n * info->blksz); - - /* write_blks might be > n due to NAND bad-blocks */ - write_blks = info->write(info, blk + blks, n, aligned_buf); - if (write_blks < n) { - free(aligned_buf); - goto write_fail; - } - - blks += write_blks; - data += n * info->blksz; - blkcnt -= n; - } - - free(aligned_buf); - return blks; - -write_fail: - if (IS_ERR_VALUE(write_blks)) { - printf("%s: Write failed, block #" LBAFU " [" LBAFU "] (%lld)\n", - __func__, blk + blks, n, (long long)write_blks); - info->mssg("flash write failure", response); - return write_blks; - } - - /* write_blks < n */ - printf("%s: Write failed, block #" LBAFU " [" LBAFU "]\n", - __func__, blk + blks, n); - info->mssg("flash write failure(incomplete)", response); - return -1; -} - int write_sparse_image(struct sparse_storage *info, const char *part_name, void *data, char *response) { @@ -209,11 +152,15 @@ int write_sparse_image(struct sparse_storage *info, return -1; } - blks = write_sparse_chunk_raw(info, blk, blkcnt, - data, response); - if (blks < 0) + blks = info->write(info, blk, blkcnt, data); + /* blks might be > blkcnt (eg. NAND bad-blocks) */ + if (blks < blkcnt) { + printf("%s: %s" LBAFU " [" LBAFU "]\n", + __func__, "Write failed, block #", + blk, blks); + info->mssg("flash write failure", response); return -1; - + } blk += blks; bytes_written += ((u64)blkcnt) * info->blksz; total_blocks += chunk_header->chunk_sz; -- 2.35.1