From patchwork Fri Nov 17 21:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 166396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp823545vqn; Fri, 17 Nov 2023 13:29:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFM0JdK8JSZ0drSGhrbDfQU+NH93/U0F4LMilBwxyuMb+N3JzC18FhAlQc5OHGRmolSOory X-Received: by 2002:a05:6a00:3687:b0:690:41a1:9b6a with SMTP id dw7-20020a056a00368700b0069041a19b6amr816235pfb.5.1700256577790; Fri, 17 Nov 2023 13:29:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700256577; cv=none; d=google.com; s=arc-20160816; b=rUJaQFgVktHPIk2ON9zhsju2kx42YCeTG2FvhD9y3zdNAnjve0RY43JKNQb6bnf1Fx g0uC0BuNFRp/3VJtRKG/ZDN0Kd3mceh3u3D1BJotBlo5RlfVJygiZRrvRckPM97Ps00C 0fBw0kz3Rlv0jrWiQn0ZbGHFWt6HvUQgC6IoPZcL2Qv2XSYaPnn8nGHOyX85pEM5UQU1 wcfZ2RNwgSVQhWyB6BpUj3LQrf8+sUG6JsSxxAoYDZqdDuGry8sFEIzd9LUkac8ei9R2 KNdHvBxrmWhqhRZzKq1oMQMRp2Z6jInrB3MlnTL1ErjYWYc+n0aUOPttPV8xBxxfWL9x Qtaw== 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 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id u2-20020a631402000000b00565335587absi2640132pgl.802.2023.11.17.13.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:29:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; 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 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id B6E0D8382304; Fri, 17 Nov 2023 13:29:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbjKQV2r (ORCPT + 29 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 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 17 Nov 2023 13:29:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782848241244808495 X-GMAIL-MSGID: 1782848241244808495 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