Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13083055rwd; Fri, 23 Jun 2023 15:35:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JMg+7kaaZXQwf51vcHLnfZEuPnZ3BA5q9wrcKfEKDj6+RtDgD+1TPs+u10sbwRTOwfYvi X-Received: by 2002:a05:6a20:8f06:b0:122:a808:dbbe with SMTP id b6-20020a056a208f0600b00122a808dbbemr14728436pzk.29.1687559736606; Fri, 23 Jun 2023 15:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687559736; cv=none; d=google.com; s=arc-20160816; b=KfYDcdTqNNaAYeZHMs8w0+ro1DncrK9Zy1XvE0A6eHpg7uE/6Mi0/EIF3JiCgSuS4K zP/eoN84i69CyZC98bCT16HDSRTMYFOBFdeYxUJ4b5dk1lPxkS1EQmplNYOM2Kdv9rgF Ycbu9pMHNIzPN1X3BEXOrn0N8OuvR8gF6otTU08PdP/DB+C5yrDxoYZKciUOktR71FCH TU5A9ilqfEVdOrGoOLcOjH4qj5DYIRCej+fyvnMZDfY/KMS4b8xn4Y8zOYZyhceGK0JC j3bf/lG3HK6ZYTgQcoWaESn1CD0w+UnxNi6e7ehyb8N82ODfSR1oKL+35E7IpzgYbLsj b0Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sZx6+oVqWxI1dOKVQNClxhZWPvsRArizB5EStMZMnN8=; fh=QDZwHF+HEbnhJRJjOddcO7BC0vTfG41Ukz3UUXyKd0M=; b=x4IBsNZ9LDhEOsE0awdSCxmX8oMcFi2HnhjND3VlsVmEH1YXRXw76BVpqF0hafI7ws 0+7CLXdrHotcEgefC21cjHByRji+suiSe1jZo5Jt0zccQYg4/2h2G+5b1G76XPXp7xAx uebAukI8iHKK0XO7/UrA+mNZ8326Ecznt2qDdI/AnFC72SKYLvpYtfen900/KECs8rCb SoDp4H+igP5ASBCZICqhUUOtPsKKfoQNN7As53e2NUwmjks3sK7OXO55kqhdvAlh0pjk TyuBuEsQdsoN3RtLt9VXuQtEmeNO3Ecny5D5HfHyDQ+v0smRfCz70cdx+IEtnO3/EHhe RSAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=f2c2+uJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a190-20020a6390c7000000b005347d6bd7eesi390843pge.141.2023.06.23.15.35.22; Fri, 23 Jun 2023 15:35:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=f2c2+uJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjFWWUu (ORCPT + 99 others); Fri, 23 Jun 2023 18:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232011AbjFWWUq (ORCPT ); Fri, 23 Jun 2023 18:20:46 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCD12940 for ; Fri, 23 Jun 2023 15:20:35 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b55643507dso8578765ad.0 for ; Fri, 23 Jun 2023 15:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687558835; x=1690150835; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sZx6+oVqWxI1dOKVQNClxhZWPvsRArizB5EStMZMnN8=; b=f2c2+uJXWg2ggdJELahXkTmw8NS0Vlee1pomXdIE0kk8Lt8DJlKSY5iypXKPDDOs6K wrDqPIXgzwx+nbXjr83KbOiy5FLoQVFGt+OG4ZVNqITEz/nDcEx5/hwJ2vNaf42EuDAm K+n/0rjM6Ay9V7yM0s9JnvSM9slynHhVVZQAgiIqMW7vU3ap7cE5JOU74jEslDFRAqUM XaPG2ToBREBysGAUDnSjCZ90N0u8/k2GCoupIDmn1EUyPgF3Aq0Vaz+D3WNuYnbe+n1p TuU7AUCIfSXyAgDZPqgRQyjOgV2srBzC3pX/ZaYcMNi8bwn6/wIA7wojudNGkdcCF5YM d8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687558835; x=1690150835; 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=sZx6+oVqWxI1dOKVQNClxhZWPvsRArizB5EStMZMnN8=; b=BAfkOvGmXBO0C3QhjkSzaE5opjADmrK3UuMPHyM/vshvZnMtdt0aQtJgyqSWaTJ5yN eZ+nPI8hWT1SUlgjedEkqjMZlzYWvKCpLbMTodvqOeHqP78Neu6BaN+CRrhmzqNDkdKl y5UFa2rb0Iuj0sXt69a8sDupHawokjmnEGFS6McpA3iRHk0shtj6Bzpfubezu/stQtk3 dvmxzhVrJCqj0lEInBva+Mm6GIf6YPHxoyyd+mHPPz8LsCBAZYCZZ0jSaq7IunoAhR5B uOBiglbTYbXrdpST6/WvQVB4RNvERVlfdY+O+dHY/nzK+pALR3fP2D81R8xdmvTOx7TP FTmQ== X-Gm-Message-State: AC+VfDwPpb55vXYl0DkM5uDghdnFTcehuPn4s1KEREViOYKPY0tfNSas XcEFcA04TiOkZzVGLyPYZlW25g== X-Received: by 2002:a17:902:dac3:b0:1b6:8b70:328f with SMTP id q3-20020a170902dac300b001b68b70328fmr462343plx.6.1687558834840; Fri, 23 Jun 2023 15:20:34 -0700 (PDT) Received: from evan.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id ju20-20020a170903429400b001a80ad9c599sm35535plb.294.2023.06.23.15.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:20:34 -0700 (PDT) From: Evan Green To: Palmer Dabbelt Cc: Simon Hosie , Evan Green , Albert Ou , Alexandre Ghiti , Andrew Jones , Andy Chiu , Anup Patel , Conor Dooley , Greentime Hu , Guo Ren , Heiko Stuebner , Heiko Stuebner , Jisheng Zhang , Jonathan Corbet , Ley Foon Tan , Li Zhengyu , Masahiro Yamada , Palmer Dabbelt , Paul Walmsley , Randy Dunlap , Samuel Holland , Sia Jee Heng , Sunil V L , Xianting Tian , Yangyu Chen , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH 0/2] RISC-V: Probe for misaligned access speed Date: Fri, 23 Jun 2023 15:20:14 -0700 Message-Id: <20230623222016.3742145-1-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current setting for the hwprobe bit indicating misaligned access speed is controlled by a vendor-specific feature probe function. This is essentially a per-SoC table we have to maintain on behalf of each vendor going forward. Let's convert that instead to something we detect at runtime. We have two assembly routines at the heart of our probe: one that does a bunch of word-sized accesses (without aligning its input buffer), and the other that does byte accesses. If we can move a larger number of bytes using misaligned word accesses than we can with the same amount of time doing byte accesses, then we can declare misaligned accesses as "fast". The tradeoff of reducing this maintenance burden is boot time. We spend 4-6 jiffies per core doing this measurement (0-2 on jiffie edge alignment, and 4 on measurement). The timing loop was based on raid6_choose_gen(), which uses (16+1)*N jiffies (where N is the number of algorithms). On my THead C906, I found measurements to be stable across several reboots, and looked like this: [ 0.047582] cpu0: Unaligned word copy 1728 MB/s, byte copy 402 MB/s, misaligned accesses are fast I don't have a machine where misaligned accesses are slow, but I'd be interested to see the results of booting this series if someone did. Evan Green (2): RISC-V: Probe for unaligned access speed RISC-V: alternative: Remove feature_probe_func Documentation/riscv/hwprobe.rst | 8 +-- arch/riscv/errata/thead/errata.c | 8 --- arch/riscv/include/asm/alternative.h | 5 -- arch/riscv/include/asm/cpufeature.h | 2 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/alternative.c | 19 ------- arch/riscv/kernel/copy-noalign.S | 71 +++++++++++++++++++++++++ arch/riscv/kernel/copy-noalign.h | 13 +++++ arch/riscv/kernel/cpufeature.c | 78 ++++++++++++++++++++++++++++ arch/riscv/kernel/smpboot.c | 3 +- 10 files changed, 171 insertions(+), 37 deletions(-) create mode 100644 arch/riscv/kernel/copy-noalign.S create mode 100644 arch/riscv/kernel/copy-noalign.h -- 2.34.1