Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1467768rdh; Fri, 27 Oct 2023 15:44:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHz8cFUb7AGLaCYOOGxU5RBCgILVchuqLyEAReF1XdA0ExA01Jy+jRmnSIwB8RZp0YPcOp X-Received: by 2002:a05:6870:b14d:b0:1e9:88c2:ba80 with SMTP id a13-20020a056870b14d00b001e988c2ba80mr4847408oal.30.1698446662239; Fri, 27 Oct 2023 15:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698446662; cv=none; d=google.com; s=arc-20160816; b=V3qKirxZ0+/Nj5lGqzVqae4Z7CpG+rdIZAJf5dDtL/Pj3Ykl2XKxCNNPvb6TF7dmdf lKDFVtxyR1wTp/s/7uKrV28T9Sy2TR95DaBkQo45upclDB42y+pyIdvXftPUnbz5FAtQ O6U9VKbYW0Nykgg6yXNqDiXEyy/PLFZczcHxxoMKBIuK72Z709imWbGS0xwVZ/CwW00F M7JsDexwjaZ0a7WeZDVALEPEyUZKSe0GDAjELy/xAA7lnzNSmhLNtfGEzXxTvpvu+F1Q Ortx/urGugUq6bKTn8yOporrx/K2J4uZhUxEn0q1s1qaO05VIkW3xTMMZPOQqB9hDUm/ CImQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=lkuVRV2BU2bq68g2g/lXL36oTT7d/CXQaqu3G/K1tPY=; fh=NvPEvYYb1ljjPtQroLU0Yeq/uN2Mxoa3J4vK70VhuM0=; b=b9px5Czjbh/Go6Qe7VmsxLcCCzzZYTrKk15me8B9zjazpkG6gKlej65vZRASsB/Ulv Xe/ewESq+xyc1vOspPEMILQ/UsVB95iyeqcrGt0g0wFRnRV/74B3VLC3wjlTUX2N6OSs kigGjKRy0srDeVvyFpylRMY4P9DzGxHLnCW0Sp8ZrUNBcp1rsMOjcD+v17dHSmxixUnt sMRyMj7UxvG/sKMlevsc9joSqp6ZKpC4jFM+PNcD5D1lN1ZF0ZrZAS+B5gY4rONpUqCQ k8yL2m8bpNAS4QATEpa7JnXRZliEfHRtCF/0zDQhPkeA3sh82iwWvsLYUNbolmKUtLO0 rFRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=l2ea5DKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s132-20020a63778a000000b005b90b2d917asi1636807pgc.278.2023.10.27.15.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:44:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=l2ea5DKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id E443282DFEFB; Fri, 27 Oct 2023 15:44:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346704AbjJ0WoN (ORCPT + 99 others); Fri, 27 Oct 2023 18:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235062AbjJ0WoE (ORCPT ); Fri, 27 Oct 2023 18:44:04 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23171B5 for ; Fri, 27 Oct 2023 15:44:02 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6ce2cf67be2so1553664a34.2 for ; Fri, 27 Oct 2023 15:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698446642; x=1699051442; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lkuVRV2BU2bq68g2g/lXL36oTT7d/CXQaqu3G/K1tPY=; b=l2ea5DKMDmMARdGChQ0Q+yW2sSpAUsjs1Ptoq2mvqCgpf4T8N72tRUdzzkXYh2NHrX JmXF6v/OwZVC6eyh/K0XsXO+dN3zs8mMYqCAxWEswYSdGavaTrpsZtvNMLP3oiXPAT+G Sf+FipAByq9O0cP/hDnMGAtGDEvIlPBTAqifWrZiZ2IbfnFPYPu9dCSiP+Ldugq4e5wN q2dcynfPAfghNziBthbp+bLtmwnKpPoCr3LiAhCuAfGm3nFmoP2Vvw3KMt/ky1XrGBdF RwjjhNdtFj4Hx7mF8yWNeBkE8uBLJAr7x9j3EMROwqTkm5DM+gAQzrkiQCx9qnd4wBdC PfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698446642; x=1699051442; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lkuVRV2BU2bq68g2g/lXL36oTT7d/CXQaqu3G/K1tPY=; b=iivee86GmhnqkevGSHCFA4rAFg/VTW9ADy0DM30munJkw9MbtRQyelOlMZOUBh1ZNS jJzCePAAib7pLlfonHdx1NxBhYmNgMbqiRseNNaSxdrE+xqSBw/kPJ0NVod/CLoYOiW8 Ia++Ae9ow7ouJdtlWcnLGv5+NnNXnM4hShsxBXRLz9xNJ4UDi6MjfVwkoR2fDJguDVN+ LjATVT/rmM2T99B3r4ft/yJIuoGeX7+mpOuzZQYQFiRFM9X/azwyNAvrXNGssEOPy4mo OOtvJZcue8DVY0CT29Ppl87fMQs0fOWIGOJBMucUOHTbWhkBaOtFvCHO/qCCtj2rFZFh Er8A== X-Gm-Message-State: AOJu0YzsNOQO5fMHDAsK/c3S67RaT+N88zZoqXQIP8JE/KD/GsBtYrVM qal1A5MOONNetQRDxO7NtDdUQAn9yqC60+EYtGw= X-Received: by 2002:a05:6830:7190:b0:6c6:3926:8055 with SMTP id el16-20020a056830719000b006c639268055mr4329785otb.6.1698446641925; Fri, 27 Oct 2023 15:44:01 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id t15-20020a9d748f000000b006c61c098d38sm448564otk.21.2023.10.27.15.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:44:01 -0700 (PDT) From: Charlie Jenkins Date: Fri, 27 Oct 2023 15:43:52 -0700 Subject: [PATCH v8 2/5] riscv: Add static key for misaligned accesses MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231027-optimize_checksum-v8-2-feb7101d128d@rivosinc.com> References: <20231027-optimize_checksum-v8-0-feb7101d128d@rivosinc.com> In-Reply-To: <20231027-optimize_checksum-v8-0-feb7101d128d@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , Xiao Wang , Evan Green , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Paul Walmsley , Albert Ou , Arnd Bergmann X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:44:20 -0700 (PDT) Support static branches depending on the value of misaligned accesses. This will be used by a later patch in the series. All cpus must be considered "fast" for this static branch to be flipped. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/cpufeature.h | 3 +++ arch/riscv/kernel/cpufeature.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index b139796392d0..febd9de4373e 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -7,6 +7,7 @@ #define _ASM_CPUFEATURE_H #include +#include #include /* @@ -32,4 +33,6 @@ extern struct riscv_isainfo hart_isa[NR_CPUS]; int check_unaligned_access(void *unused); +DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); + #endif diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 40bb854fcb96..8935481d32da 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -665,6 +666,35 @@ static int check_unaligned_access_all_cpus(void) arch_initcall(check_unaligned_access_all_cpus); +DEFINE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); + +static int set_unaligned_access_static_branches(void) +{ + /* + * This will be called after check_unaligned_access_all_cpus so the + * result of unaligned access speed for all cpus will be available. + */ + + int cpu; + bool fast_misaligned_access_speed = true; + + for_each_online_cpu(cpu) { + int this_perf = per_cpu(misaligned_access_speed, cpu); + + if (this_perf != RISCV_HWPROBE_MISALIGNED_FAST) { + fast_misaligned_access_speed = false; + break; + } + } + + if (fast_misaligned_access_speed) + static_branch_enable(&fast_misaligned_access_speed_key); + + return 0; +} + +arch_initcall_sync(set_unaligned_access_static_branches); + #ifdef CONFIG_RISCV_ALTERNATIVE /* * Alternative patch sites consider 48 bits when determining when to patch -- 2.42.0