Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp810035rdb; Fri, 17 Nov 2023 13:31:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg8aSfNNc1VqqCY9ejFcAniFpOyqiMMqHpO8pev2nDQSyuICPz7hgcHdA4naXxYsTGBhrh X-Received: by 2002:a05:6e02:e0f:b0:357:5b68:46e7 with SMTP id a15-20020a056e020e0f00b003575b6846e7mr694049ilk.13.1700256676646; Fri, 17 Nov 2023 13:31:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700256676; cv=none; d=google.com; s=arc-20160816; b=pVu3XX2w0BZDqlLNOPdRTH+kDUL68pi+zuj/Ty98GV5CVMkqx5OdECecyEk9f0cj6n v9H4ey8rKxMNTfENMLiZHUDawrkbXFYGAOnAZn0pLGFovRh3Q0czlq1Ps9YSQ3ngE0lL quL2qZUiVo4pkyaZs3kUk2bQxTlxGL7mjHmrg6s1sRYy89NK7b1zAMypBd5bEOm1O7Pf Pn9Q8p6CWOUeUuhO6KCXDmh5gqzZ9o0J/F1Nb7jPf6EZoj87xIE5/BD3cZy4/8fDD3lO 46tXG/1ZfxWOilakt86sUJkOazQ8plPAuNeZA3Bxln+u8K2OWWPRXdw0MwilxNJThJ/F DtEA== 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=tFkw7Zr5+lsFGiMTF3p4hMDodXgeN/bSu+5QgPVpcIL1LWnDx/BH5jHh21prauDB+6 9cSAl8XjVgyfae7xaMiFZ2W/MRdQDeKZKBjA5+ixs+IqoyFpQ4nnqfwSb76YsnfCVNTa 6fP1KJfYneSPQ1HIGJ3sxL9p2E87GwEuEQjaVXwqFdu7xPwSMgoopchON7OF09KAg0Xc xMSKRnUhxUbo+N83RzUI0a9fKYEHP3OPN31LNag02yYUWhZfsd4cmUbpLv9RqKtLt+YA nR8g6COwgGZIapzfYfs9CSvpcVHtCIBoHWQCi1gonKsGlU2WiyarkhQLVT8zME1qx+9M 3+uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=czjRIg3v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id j36-20020a635524000000b005ad5178d053si2630066pgb.347.2023.11.17.13.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:31:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=czjRIg3v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 85F1280722DC; Fri, 17 Nov 2023 13:31:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235727AbjKQV2r (ORCPT + 99 others); Fri, 17 Nov 2023 16:28:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235884AbjKQV2c (ORCPT ); Fri, 17 Nov 2023 16:28:32 -0500 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D0E1BC5 for ; Fri, 17 Nov 2023 13:28:12 -0800 (PST) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1f06931e4f7so1374094fac.1 for ; Fri, 17 Nov 2023 13:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700256491; x=1700861291; 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=czjRIg3v7lsgfHsW+WWanB2XXXjfFifkb1W/CB1Xun8ObXrzB0WTUbWupN0BG+XbJW GffCYvqqYsacP97FRxpUg1RWotohciQ7DsbQp3XQjNBX9XrJMfhvnyB8nNWU+jD5OD9B bbRfHZulk6gAnMdCbBXsr7FuAZZiFIUXGUsShv6BNQ+FQER/ZVdFrlbzPNZUcQMwhPCh WLiknuiR9m6HJ83MdBed2wVoI2LjZYZFVIu1Yso4CpgBKbnjoynkg7daI04icKBrki5+ tUOc1X2/C3AteCjg8u64zu6Gtx2JJGhK18aCMTPuduawVtePOakUSuV2E/QWnvLChcWn iyYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700256491; x=1700861291; 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=gkzLk9jU8Mm3bZvtE1/uSReQnKOeC37crgFLVZNL5UeyhLrRJDc2PLiYsAqjaDxPtz 8mbaZZHDY9k1pD7m1++/4XRppWo+nzlBBsS9w4zmPUUyPIceCEjaWfH/5vRuIAgcXCKO E6Nkk5Qo+AdusQOAz9opptbUvDyZNN+uuShC4BGMN7Ur2B8+nccH5+rPzBk0pf2X/Vvv v0E1fQ3t/UIl42OQ58GjybuZlj+AUbpYnKrPRSpC8NtMY2aQg5Y75zUbDkEbRT2oB7Ne LjDIXXAg0wTYp53neTi/G65/0p66N5y/LMoR/qZYh2OmZTjIObO4cDNYHuluVL80x2Rf Nz/g== X-Gm-Message-State: AOJu0Ywx4xZ9sqtBHJKwO47JyG6hqyuriKXKjYnHtOu+rZgRQXF29yo1 KZaUZpUiWusfxDwrKtTCfFQdyA== X-Received: by 2002:a05:6870:f608:b0:1e9:efa9:1199 with SMTP id ek8-20020a056870f60800b001e9efa91199mr585055oab.4.1700256491304; Fri, 17 Nov 2023 13:28:11 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id e2-20020a05683013c200b006d3127234d7sm365677otq.8.2023.11.17.13.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:28:10 -0800 (PST) From: Charlie Jenkins Date: Fri, 17 Nov 2023 13:28:00 -0800 Subject: [PATCH v11 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: <20231117-optimize_checksum-v11-2-7d9d954fe361@rivosinc.com> References: <20231117-optimize_checksum-v11-0-7d9d954fe361@rivosinc.com> In-Reply-To: <20231117-optimize_checksum-v11-0-7d9d954fe361@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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 13:31:05 -0800 (PST) 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