From patchwork Tue Apr 9 12:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 1921378 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.a=rsa-sha256 header.s=202305 header.b=Wqty4nu5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VDQx63jYWz1yZm for ; Tue, 9 Apr 2024 22:58:02 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7831788150; Tue, 9 Apr 2024 14:57:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz 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; secure) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b="Wqty4nu5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0ED468817B; Tue, 9 Apr 2024 14:14:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 09A9088173 for ; Tue, 9 Apr 2024 14:14:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=nabijaczleweli@nabijaczleweli.xyz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1712664874; bh=D2ed9BT0RCkQTXzQzGDA+t3yschimo5ULgA58lJrrB8=; h=Date:From:To:Subject:References:In-Reply-To:From; b=Wqty4nu5bXlLVsCgJ1tiT/MvwWY3zpsGZYbY1YxRu9TElR/jiWe3CRAzoxOmlNubs SZUAi/8AZfLZKbrotEz0GH3dlkTiro8xynkuoZR0tqcH/86Uo9E0mZ62Y9iSABJIj6 FGp9JKAX7Sy1N1lvBPO1Z4BTCuZXu/Ubu284XrSerK0FDSQuWOHBXHBXNCLKmvrpEu tIpwQQrSsHBjbTRMoFFvdjh9RGEqK4IPR+IFwEAIEvt+X2LduSsRZoe7YlVMMuTBBv KO93qipYzjiN5bmLZQ9hJ6WjBM9AulOswY6qoDhXq4Lu6csAd6iPuHUxiv1LSQ4Umg 87eHp0fd7nJZQ== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 677F8293E; Tue, 9 Apr 2024 14:14:34 +0200 (CEST) Date: Tue, 9 Apr 2024 14:14:34 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: Dragan Simic , Tom Rini , u-boot@lists.denx.de Subject: [PATCH v4] tools: copyfile: use 64k instead of 512 buffer Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20231221-2-4202cf-dirty X-Mailman-Approved-At: Tue, 09 Apr 2024 14:57:26 +0200 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 This is a trivial but significant optimization: mkimage took >200ms (and 49489 writes (of which 49456 512)), now it takes 110ms (and 419 writes (of which 386 64k)). sendfile is much more appropriate for this and is done in one syscall, but doesn't bring any significant speedups over 64k r/w at the 13M size ranges, so there's no need to introduce #if __linux__ while((size = sendfile(fd_dst, fd_src, NULL, 128 * 1024 * 1024)) > 0) ; if(size != -1) { ret = 0; goto out; } #endif Also extract the buffer size to a macro. Signed-off-by: Ahelenia ZiemiaƄska Reviewed-by: Dragan Simic --- tools/fit_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/fit_common.c b/tools/fit_common.c index 2d417d47..d1cde16c 100644 --- a/tools/fit_common.c +++ b/tools/fit_common.c @@ -23,6 +23,8 @@ #include #include +#define COPYFILE_BUFSIZE (64 * 1024) + void fit_print_header(const void *fit, struct image_tool_params *params) { fit_print_contents(fit); @@ -145,14 +147,14 @@ int copyfile(const char *src, const char *dst) goto out; } - buf = calloc(1, 512); + buf = calloc(1, COPYFILE_BUFSIZE); if (!buf) { printf("Can't allocate buffer to copy file\n"); goto out; } while (1) { - size = read(fd_src, buf, 512); + size = read(fd_src, buf, COPYFILE_BUFSIZE); if (size < 0) { printf("Can't read file %s\n", src); goto out;