Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp597570rdb; Tue, 31 Oct 2023 17:19:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgpX3D8IoSX9KDQs15PlXsrnVzw+kii0koFNemi2vAfkTidB9cvj9mGCpxbcKvZhEyrMYF X-Received: by 2002:a05:6808:238b:b0:3b5:656b:f962 with SMTP id bp11-20020a056808238b00b003b5656bf962mr4224115oib.5.1698797973770; Tue, 31 Oct 2023 17:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698797973; cv=none; d=google.com; s=arc-20160816; b=sJMtmvvn0CoS/ZojcPMGiQhD/02tUKlCynnM8eztwGlB4TiGp42Y9xqXmF2C75HUGb /dVYhqm88u1CGxvrpn7j2jbf+tlRNDxXRLWDUAscH5T85bXmzvjJ9yXEAHmJbuYvHjvB B10naYrCtRTjVHwYt6jczEI2Fo2LdjeA7GKN4ol3FovQ4s5v2o6DMMcNJSHMHNra4FO2 y0zeDJpLhkDYj0vjsQgFh24ZwBLRumFgQ89y7hUQzt8sTyJ89NQvGp74oIuezh+8dEj1 dyospHOVp7SkLW4kz9K1F44wqC0/OEjmLKxcd/OYaxFIZM73h3Nar6593xAU6qN3tbV6 //2g== 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=+Jfb6hOBzZpUnQKwLCoqR3E0xQBxJXpYyz1BMSpxkFw=; fh=NvPEvYYb1ljjPtQroLU0Yeq/uN2Mxoa3J4vK70VhuM0=; b=QuO4vQ5gt67A4c6OmCmEx+4C47mGqjiZXBWeWGOdRnErrS16a2hn+FlAUtk0RScWjF a48iu0EcOALJSAS6Yc9uyxslWdXJ+muHCh6T3gZfTrAvcIDSedmFR1l4oNXgg+ayv/kU GUJW83EO36Ri8oFRZF3rvQSIscUnSkmc4hl/dn62XzleFpMaGXDDuif+J96jXw04f87b cfrY8bXx14GoAtqtz0kj87jAiZ+PSQjBfDttwBGgs0BUZ/f+Lbz2IN9olaNN3mJzojzI kskp8omALYTOrW1Z5V5cgNVen870L9lAz/HGfq4365W6u0D+AY/iqP68HQF6PqTaBMym tEcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ltXoNmzt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fi9-20020a056a00398900b006bd20945b23si482119pfb.37.2023.10.31.17.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 17:19:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ltXoNmzt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 755228116E6C; Tue, 31 Oct 2023 17:19:32 -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 S236831AbjKAATa (ORCPT + 99 others); Tue, 31 Oct 2023 20:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345025AbjKAATO (ORCPT ); Tue, 31 Oct 2023 20:19:14 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF2C6B7 for ; Tue, 31 Oct 2023 17:19:11 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b512dd7d5bso4312979b6e.1 for ; Tue, 31 Oct 2023 17:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698797951; x=1699402751; 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=+Jfb6hOBzZpUnQKwLCoqR3E0xQBxJXpYyz1BMSpxkFw=; b=ltXoNmztbe3dRm6fON4mZNJQVoI7nho90UDD7/Ymj6EAw6cx8A0I9I1R3y0Aunwv39 EjCZ5uwodG6P6QmEWfbJ6MOhCZWYTZdePxrkrPZ3RjpdqBXOC6KtjT1O9SQC6GSxIMkZ Lx//Qahj3niHLT/b7df/1Mcou5YBp3ymBttPAJapKcVgIhC5oL58ykcbDEXM/FaSTIwm jsSibH1wQ80nAiPeImoSwhbZvOCMFHl4/dOgt6ZJPbAjOd5bgBFIWPvbl4KVuMhHr4cb J/Eo6rboUFlRw0r9tntJLJYfglbjzinrCP7wpriCpkUw5aeB1375ApXAMMFC/9m1paKM BkeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698797951; x=1699402751; 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=+Jfb6hOBzZpUnQKwLCoqR3E0xQBxJXpYyz1BMSpxkFw=; b=G6hnkTi3GSKgnkQBzCz4ORQhtS6MgAkt+w9vpqkO7JB7RmWY2TLWlhtW2wqKvOTGle Iwgadwm7LGtAnfWp+u4SmZpOstL8Y4kdnjPClwmYqwXozQYrkxI9sMPkax8+XfguYpUp X5WyPIOXw2utlwN4wnH/o+bNjIQcCpI8Ba56pUrwmOZbnFb2Dk/uW4mVeq6HGIPJfsKQ ngswgTLlTB+yLVgCEV6dYpOd5ARont6vKuJnMb4gVW5F+pZMl8gLcB6TLeFXg58iTfet a40JDBHKDjNls5X9p1RYEhrFD+XiyIRb3EDPccCZAxiB/L9xVPYvPZL9lOp2a1sE2UZ/ oWog== X-Gm-Message-State: AOJu0Ywi4iqxlCGMl1ERqE+AmnAqe/cMNN5Or2sFXUu3YRMmRCGDy84A QeUnjo7dcr4oBWg1f8uLZe/0Zw== X-Received: by 2002:a05:6808:1143:b0:3b2:e34f:3495 with SMTP id u3-20020a056808114300b003b2e34f3495mr21939715oiu.33.1698797951261; Tue, 31 Oct 2023 17:19:11 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id n21-20020aca2415000000b003af638fd8e4sm65309oic.55.2023.10.31.17.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 17:19:10 -0700 (PDT) From: Charlie Jenkins Date: Tue, 31 Oct 2023 17:18:52 -0700 Subject: [PATCH v9 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: <20231031-optimize_checksum-v9-2-ea018e69b229@rivosinc.com> References: <20231031-optimize_checksum-v9-0-ea018e69b229@rivosinc.com> In-Reply-To: <20231031-optimize_checksum-v9-0-ea018e69b229@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, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 31 Oct 2023 17:19:32 -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.34.1