Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2234406pxb; Sat, 2 Oct 2021 10:24:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUcwJKgRW5RWXqScW2IBF/OVeJBDSwv2JBVh2ID7V53SikG1PphXM9PGf3ZNMF8j4slcFQ X-Received: by 2002:a17:906:498b:: with SMTP id p11mr5187354eju.295.1633195494689; Sat, 02 Oct 2021 10:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633195494; cv=none; d=google.com; s=arc-20160816; b=oUFV9SxTI8tedksm9KS1h4WsKalttBhaGafV5/pXWY5OcdqyG/9XVJczVWSKclYT2M +/EaYBsesFAB2fZVH7Bw+hHBOajScCFI0uQHP/1Uswi02/cGlW3Fm3hDJg74IwJtiiF1 IFWAIzYeTFjIV65+Mg5iXk7AHmHyasFYYL8cg5lB7/f9aptAotqdeBk3eSgqkNYGs5fp oUu1bu200DIjmBgwFx8sXRm3ZWrSefgKidjT1CLgfsQFiT7h3Y6FTB2YXOwnZ0WcUTWv sj99NZnHvczLvvHJ/FHg75WDCzEnKJaKTLldkzJoGkHamR6rAs0hjeuaQMAiBCly7/v1 Nx7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=pWCqFFkYasORJJMiOzE5VQLaiyHxduAqYZzlCIytLqQ=; b=rhyT6Nr6HePl8vrB+iJiPr/qz+U5cQ4ZJCJ86QiZf4dJmjyasPPjBbkt/UiBT0GSZd FEoAC2WaJQ97uw7BmIP9OfXHiGld7Fc7O5to1Wu7kVcJM/1lZTdpEEZpq/ujo9uMHelD HauBhizKvkmCFvQgNZPli0P5rZENxEyT8rh42QInAqfyilCrsB1jSntsnoV4193S+DX1 HJnShpVEB05EZ/2gS7Zp3O6Mo2WC2NFNqB/+Z8iz8r9xdwWhXTR9Qwudtv4ASMGj2PzU oMqll1bFt6PEV44V5DOmmhk7FGI8o9Gq7FmdPd4hl4OOIgBtdBNkQHXucV4AOyFcEYUO RbaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=LyKrWMc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si12157372ejm.150.2021.10.02.10.24.29; Sat, 02 Oct 2021 10:24:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=LyKrWMc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbhJBRWr (ORCPT + 99 others); Sat, 2 Oct 2021 13:22:47 -0400 Received: from linux.microsoft.com ([13.77.154.182]:42962 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233451AbhJBRWq (ORCPT ); Sat, 2 Oct 2021 13:22:46 -0400 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by linux.microsoft.com (Postfix) with ESMTPSA id AB94820B4843; Sat, 2 Oct 2021 10:21:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AB94820B4843 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1633195260; bh=pWCqFFkYasORJJMiOzE5VQLaiyHxduAqYZzlCIytLqQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LyKrWMc38OVWl2j9tIYxU3ZFOduqLihYwvTtN171qiIhb3+T9MTX0va4g/YVFU62x XHX/SCETWaXXuR9pGbnaHiejpw9tyr1vCA5lpM5q7KyOAUE5ovJjUjvCHFheHtzO6d w2HUr0aShPeR9dZOpCNqrEpn531swZTi1scougEw= Received: by mail-pg1-f174.google.com with SMTP id m21so12420505pgu.13; Sat, 02 Oct 2021 10:21:00 -0700 (PDT) X-Gm-Message-State: AOAM531Ex9cSTd1a8iAhTIp5KzO6PMIMXBR5d5JXofCXn0uoCXNkt86J SeFtl2LvKyl48L5uf1/rppQM+CcxQrSrxu3enE8= X-Received: by 2002:a65:528a:: with SMTP id y10mr3603950pgp.103.1633195260173; Sat, 02 Oct 2021 10:21:00 -0700 (PDT) MIME-Version: 1.0 References: <20210929172234.31620-1-mcroce@linux.microsoft.com> <20210929172234.31620-2-mcroce@linux.microsoft.com> <20211001112354.GA10720@duo.ucw.cz> In-Reply-To: <20211001112354.GA10720@duo.ucw.cz> From: Matteo Croce Date: Sat, 2 Oct 2021 19:20:24 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 1/3] riscv: optimized memcpy To: Pavel Machek Cc: linux-riscv , Linux Kernel Mailing List , linux-arch , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Emil Renner Berthing , Akira Tsukamoto , Drew Fustini , Bin Meng , David Laight , Guo Ren , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 1, 2021 at 1:23 PM Pavel Machek wrote: > > Hi! > > > From: Matteo Croce > > > > Write a C version of memcpy() which uses the biggest data size allowed, > > without generating unaligned accesses. > > > > The procedure is made of three steps: > > First copy data one byte at time until the destination buffer is aligned > > to a long boundary. > > Then copy the data one long at time shifting the current and the next u8 > > to compose a long at every cycle. > > Finally, copy the remainder one byte at time. > > > > On a BeagleV, the TCP RX throughput increased by 45%: > > > > before: > > > > $ iperf3 -c beaglev > > Connecting to host beaglev, port 5201 > > [ 5] local 192.168.85.6 port 44840 connected to 192.168.85.48 port 5201 > > [ ID] Interval Transfer Bitrate Retr Cwnd > > [ 5] 0.00-1.00 sec 76.4 MBytes 641 Mbits/sec 27 624 KBytes > > [ 5] 1.00-2.00 sec 72.5 MBytes 608 Mbits/sec 0 708 KBytes > > > > after: > > > > $ iperf3 -c beaglev > > Connecting to host beaglev, port 5201 > > [ 5] local 192.168.85.6 port 44864 connected to 192.168.85.48 port 5201 > > [ ID] Interval Transfer Bitrate Retr Cwnd > > [ 5] 0.00-1.00 sec 109 MBytes 912 Mbits/sec 48 559 KBytes > > [ 5] 1.00-2.00 sec 108 MBytes 902 Mbits/sec 0 690 > > KBytes > > That's really quite cool. Could you see if it is your "optimized > unaligned" copy doing the difference?> > > +/* convenience union to avoid cast between different pointer types */ > > +union types { > > + u8 *as_u8; > > + unsigned long *as_ulong; > > + uintptr_t as_uptr; > > +}; > > + > > +union const_types { > > + const u8 *as_u8; > > + unsigned long *as_ulong; > > + uintptr_t as_uptr; > > +}; > > Missing consts here? > > Plus... this is really "interesting" coding style. I'd just use casts > in kernel. > Yes, the one for as_ulong is missing. By using casts I had to use too many of them, making repeated assignments in every function. This is basically the same, with less code :) Cheers, -- per aspera ad upstream