Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp157745rdb; Wed, 18 Oct 2023 23:37:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZonKZ/BEEvB7Memo7OKuW61OR8NjAHBkODKql+wS+A9YpA155FZCJf061UIbmLrtHiRi9 X-Received: by 2002:a17:902:fb8b:b0:1c9:d111:9b28 with SMTP id lg11-20020a170902fb8b00b001c9d1119b28mr1329337plb.49.1697697476539; Wed, 18 Oct 2023 23:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697697476; cv=none; d=google.com; s=arc-20160816; b=JZfzpYoin8f9SwOEVWrsgD5iKiZ3CO046YbnsasZ1r88LUtIg7YTbRDLfqoc+2KttD D9MhjQLYZfXMnUc/maqdklPh88vKBO0cYe2XxUFvBwsdJQPT6lV1E5UyN5kJI5JFkjCZ MeiJx6X7DagW9yt4F1zW2eL+/bVoSBhmARw5/8XSLd7IMjDMgOlzalPaJV/wshILGb5m W8GDC2Nxr/cPgzuga+7U6eF23hkA2YsKkTXSJvsZQdS1KfdqeYVk8En1hpAuhGkN/sQ0 GmR5moyQq9n4HsA+mujE6//X7LON2VhBBEBgpuawIOL5tKam2N16PjCOUpokDGemvYHn D/vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=kpQXru4Ocw5jht5AZPIJV3HI/HcRYV2t3beJEyZamoc=; fh=baoylpyrCph9pRtWnn0cYkfJfn+lxAWvDKNy8PZADYU=; b=jV4n+455GkxYhjecGYNRyOWrZlyQNo71s7Zpi7YUg5nSq8JUJUNn4Pu1aKeCcguVJu b3cfr+CPJ3Gt3ysmIELDNbIuRyLT9PLkzVLZpJmDqeYBGNFut7N2RLsYTozWi6TE1qDA x+5TdnVtswyKcWNt47LJjH56x/HoAG1afsSAqk8Qax3a7RUGedJOCPpjjHrIJ3RdStSM +KZSNICTeETcOYTd4zhz2LVIOCbho/7WPD/N1S7qynaxkuLMmBJqw6VtVCAdZWei7Iqq wIBmcvICVl7z9que/ex2Rh0uNwgOTHPbKFDzV2v22BZ4JSVIFkkHQ6W1foyeYkuGGVnP eWuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j1-20020a170902690100b001c6223e5675si1433582plk.188.2023.10.18.23.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 23:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 88E13809F386; Wed, 18 Oct 2023 23:37:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbjJSGh2 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 19 Oct 2023 02:37:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbjJSGh1 (ORCPT ); Thu, 19 Oct 2023 02:37:27 -0400 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 516CB10F; Wed, 18 Oct 2023 23:37:25 -0700 (PDT) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-5a7be88e9ccso95905327b3.2; Wed, 18 Oct 2023 23:37:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697697444; x=1698302244; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vXEjMPe8j5c6Nski5KvbyugP8GZIC2bmURRJNkH6ZbQ=; b=R69j6BP1J+jlozEAgOxDCD51nFcrXilKH9YHrnkNjK3423AInUTjseWAEqqjR3QxrF dK6yP2l3t6cdeOpMzPhPiNwKKBjJbL+LbjgEMmn2aFw/oWdx/FWKy0w6JUlIptsxMD/G hrlt1dDpqCMfS0ZHTH750WoP3sAyd2Um6xpZrExoZ0+LLskmP9luIDGdUBLFW/rZl/7o /xSKEt6jSmFJD23+IE1t3Fwjm8MTJ5ApW9QFE1GaiqDIkDXbFrKnbvBE4C+kdcqi2bws D7GehuYoyn6xWbO6oar0KNq21zoia7QQATdSGiGm+9cvvnQaXbVWWN5sFScX5TJUzIP5 3LSQ== X-Gm-Message-State: AOJu0YxWhsn/H2bf9U1n2PcbVPfy2Ai78heATZLCEkmuX5ak3W7M8bMC /KRtG1iBjqNKkcE/HjeTwmdIhhjUYTZ8rw== X-Received: by 2002:a0d:cbd3:0:b0:5a7:b53f:c304 with SMTP id n202-20020a0dcbd3000000b005a7b53fc304mr1696131ywd.37.1697697444045; Wed, 18 Oct 2023 23:37:24 -0700 (PDT) Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com. [209.85.128.174]) by smtp.gmail.com with ESMTPSA id d19-20020a0ddb13000000b005a7db2a0dddsm2199717ywe.3.2023.10.18.23.37.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 23:37:23 -0700 (PDT) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-5a87ac9d245so51099407b3.3; Wed, 18 Oct 2023 23:37:23 -0700 (PDT) X-Received: by 2002:a05:690c:97:b0:577:3d46:f90e with SMTP id be23-20020a05690c009700b005773d46f90emr1622261ywb.32.1697697443165; Wed, 18 Oct 2023 23:37:23 -0700 (PDT) MIME-Version: 1.0 References: <20230818194136.4084400-1-evan@rivosinc.com> <20230818194136.4084400-2-evan@rivosinc.com> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 19 Oct 2023 08:37:09 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 1/2] RISC-V: Probe for unaligned access speed To: "Lad, Prabhakar" Cc: Palmer Dabbelt , Heiko Stuebner , linux-doc@vger.kernel.org, =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Conor Dooley , Guo Ren , Jisheng Zhang , linux-riscv@lists.infradead.org, Jonathan Corbet , Sia Jee Heng , Marc Zyngier , Masahiro Yamada , Greentime Hu , Simon Hosie , Andrew Jones , Albert Ou , Alexandre Ghiti , Ley Foon Tan , Paul Walmsley , Anup Patel , linux-kernel@vger.kernel.org, Xianting Tian , David Laight , Palmer Dabbelt , Andy Chiu , Evan Green Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 23:37:47 -0700 (PDT) Hi Prabahkar, On Thu, Sep 14, 2023 at 9:32 AM Geert Uytterhoeven wrote: > On Wed, Sep 13, 2023 at 7:46 PM Evan Green wrote: > > On Wed, Sep 13, 2023 at 5:36 AM Geert Uytterhoeven wrote: > > > On Fri, Aug 18, 2023 at 9:44 PM Evan Green wrote: > > > > Rather than deferring unaligned access speed determinations to a vendor > > > > function, let's probe them and find out how fast they are. If we > > > > determine that an unaligned word access is faster than N byte accesses, > > > > mark the hardware's unaligned access as "fast". Otherwise, we mark > > > > accesses as slow. > > > > > > > > The algorithm itself runs for a fixed amount of jiffies. Within each > > > > iteration it attempts to time a single loop, and then keeps only the best > > > > (fastest) loop it saw. This algorithm was found to have lower variance from > > > > run to run than my first attempt, which counted the total number of > > > > iterations that could be done in that fixed amount of jiffies. By taking > > > > only the best iteration in the loop, assuming at least one loop wasn't > > > > perturbed by an interrupt, we eliminate the effects of interrupts and > > > > other "warm up" factors like branch prediction. The only downside is it > > > > depends on having an rdtime granular and accurate enough to measure a > > > > single copy. If we ever manage to complete a loop in 0 rdtime ticks, we > > > > leave the unaligned setting at UNKNOWN. > > > > > > > > There is a slight change in user-visible behavior here. Previously, all > > > > boards except the THead C906 reported misaligned access speed of > > > > UNKNOWN. C906 reported FAST. With this change, since we're now measuring > > > > misaligned access speed on each hart, all RISC-V systems will have this > > > > key set as either FAST or SLOW. > > > > > > > > Currently, we don't have a way to confidently measure the difference between > > > > SLOW and EMULATED, so we label anything not fast as SLOW. This will > > > > mislabel some systems that are actually EMULATED as SLOW. When we get > > > > support for delegating misaligned access traps to the kernel (as opposed > > > > to the firmware quietly handling it), we can explicitly test in Linux to > > > > see if unaligned accesses trap. Those systems will start to report > > > > EMULATED, though older (today's) systems without that new SBI mechanism > > > > will continue to report SLOW. > > > > > > > > I've updated the documentation for those hwprobe values to reflect > > > > this, specifically: SLOW may or may not be emulated by software, and FAST > > > > represents means being faster than equivalent byte accesses. The change > > > > in documentation is accurate with respect to both the former and current > > > > behavior. > > > > > > > > Signed-off-by: Evan Green > > > > Acked-by: Conor Dooley > > > > > > Thanks for your patch, which is now commit 584ea6564bcaead2 ("RISC-V: > > > Probe for unaligned access speed") in v6.6-rc1. > > > > > > On the boards I have, I get: > > > > > > rzfive: > > > cpu0: Ratio of byte access time to unaligned word access is > > > 1.05, unaligned accesses are fast > > > > Hrm, I'm a little surprised to be seeing this number come out so close > > to 1. If you reboot a few times, what kind of variance do you get on > > this? > > Rock-solid at 1.05 (even with increased resolution: 1.05853 on 3 tries) After upgrading the firmware from [1] to [2], this changed to "0.00, unaligned accesses are slow". [1] RZ-Five-ETH U-Boot 2020.10-g611c657e43 (Aug 26 2022 - 11:29:06 +0100) [2] OpenSBI v1.3-75-g3cf0ea4 U-Boot 2023.01-00209-g1804c8ab17 (Oct 04 2023 - 13:18:01 +0100) Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds