From patchwork Mon Dec 25 04:42:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 18514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp233242dyb; Sun, 24 Dec 2023 20:55:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IF64rcNrfEwZYxxuU1c8E36YiEAcggC+KfzjlUhAXA+i/YkxDEIgM/9q/vnU9RDlv8g9bPG X-Received: by 2002:a17:902:edd0:b0:1c9:cc88:502c with SMTP id q16-20020a170902edd000b001c9cc88502cmr5394867plk.69.1703480106496; Sun, 24 Dec 2023 20:55:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703480106; cv=none; d=google.com; s=arc-20160816; b=QxL5m0rMemyzBy3zT53EQhtZQTthbkhnBHmF6pBPet+bU88jMTrB7Fq7S6mQFpKTkp NYK8tmWkRsFKV2HQNuFBHZqfW7k8zYBBWjvrn4gq0bHEyr59W4QFJWfQhgAaihylfrEj IAcgn8yeltL05Pj699wW3R9SANOEdBktDusvhdQD6MerXeV2QFAjpOpOL0nj92TmuFjt nSQFPiztYauiBk6nB15HLjTX8IHm/A4xCCzt3Nffrh0h3ojtQvTye+t5I9/juGS8EUpb OA3q6iyIn+ChfF+rWpYchWheDXzcI7zfKMJfEs5lu5N2mx5HQ160l8/EzRexhRBhjqM2 no6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=LA6daKzE9/cg6V/4J1YFnZFJh9BeMAT5H5FPrVgQbUg=; fh=ZTT3Py7m/X4mSvw6SK6+TRZhmqxsZi0TneX42+FLUx4=; b=cFs6EoYnIBbkjBRstKJVQv3uc7hyh1xAWkD8/kbigFl54j4M6hu4Skxk/QB1RNiPQ6 mDS6cNBqA03tdBBnPEn6Jbu/SVUbQo8L0n93oAi1figuFFSam/kzvw6SgX6AQjROq3HZ zZ4CpmMfjBQMo1tzLo6fsUVRrS6fGiedY87KeUJ2KEi53Y6to8zf6lePBa3YyuuRnlIn uGibUfZ5k+mhVSCj9qhvVNcFylISHWjQoYdE5DeUdScVN/FHRKC8lsCsDA/ywInsFN3r 7BGukPzPMtKbuZ6LKxevFZkKbQZiR4uNWhrxHgzoby6laYro764obIsCDoj43jC8LogH 5hmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qrat2D9m; spf=pass (google.com: domain of linux-kernel+bounces-10891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u3-20020a17090341c300b001d44b36b701si2050392ple.512.2023.12.24.20.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 20:55:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qrat2D9m; spf=pass (google.com: domain of linux-kernel+bounces-10891-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EA8D3281844 for ; Mon, 25 Dec 2023 04:55:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0061115BB; Mon, 25 Dec 2023 04:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qrat2D9m" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E039EA6 for ; Mon, 25 Dec 2023 04:54:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74E6BC433C7; Mon, 25 Dec 2023 04:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703480091; bh=UArUSyBZsPKxLkpUFilgpFD8aka1iX7bL7/0EeJ4W9s=; h=From:To:Cc:Subject:Date:From; b=Qrat2D9mqhj5ram8CGulN/a4AthJQBzq+uzfRUGEqVXSIEIdizPmerD1Gb9BqkX5j yOScpSvVveHperCPxKtZsxuFilvN/6urpCPsJfjdZTndKgpLv72pa3/9tTaDrfvutM Nzu5gTXzT+kiqck1CCNcUEqWq3AV+HIyWsp+2zID73GSrcNmCUeAH0iDwet5KQiJs+ +77xdqrGRHyrPTZZt8KuNkIjRBj/ahjruXT35opTqY58rphamGKD+utB3Bm/EJlNUr OfW4KpJjZWz8zfl4rLRmu+uanCkWxztq3OKLNvol0FDa+ASb4dvwpiMThiFiPWizz6 SPmxwG+W4/eNA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Eric Biggers , Conor Dooley , Qingfang DENG Subject: [PATCH v4 0/2] riscv: enable EFFICIENT_UNALIGNED_ACCESS and DCACHE_WORD_ACCESS Date: Mon, 25 Dec 2023 12:42:05 +0800 Message-Id: <20231225044207.3821-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786228355624391054 X-GMAIL-MSGID: 1786228355624391054 Some riscv implementations such as T-HEAD's C906, C908, C910 and C920 support efficient unaligned access, for performance reason we want to enable HAVE_EFFICIENT_UNALIGNED_ACCESS on these platforms. To avoid performance regressions on non efficient unaligned access platforms, HAVE_EFFICIENT_UNALIGNED_ACCESS can't be globally selected. To solve this problem, runtime code patching based on the detected speed is a good solution. But that's not easy, it involves lots of work to modify vairous subsystems such as net, mm, lib and so on. This can be done step by step. So let's take an easier solution: add support to efficient unaligned access and hide the support under NONPORTABLE. patch1 introduces RISCV_EFFICIENT_UNALIGNED_ACCESS which depends on NONPORTABLE, if users know during config time that the kernel will be only run on those efficient unaligned access hw platforms, they can enable it. Obviously, generic unified kernel Image shouldn't enable it. patch2 adds support DCACHE_WORD_ACCESS when MMU and RISCV_EFFICIENT_UNALIGNED_ACCESS. Below test program and step shows how much performance can be improved: $ cat tt.c #include #include #include #define ITERATIONS 1000000 #define PATH "123456781234567812345678123456781" int main(void) { unsigned long i; struct stat buf; for (i = 0; i < ITERATIONS; i++) stat(PATH, &buf); return 0; } $ gcc -O2 tt.c $ touch 123456781234567812345678123456781 $ time ./a.out Per my test on T-HEAD C910 platforms, the above test performance is improved by about 7.5%. Since v3: - adopt Eric's suggestions, such as better Kconfig help msg and so on. Since v2: - Don't set "-mstrict-align" CFLAGS if HAVE_EFFICIENT_UNALIGNED_ACCESS - collect Reviewed-by tag Since v1: - fix typo in commit msg - fix build error if NOMMU Jisheng Zhang (2): riscv: introduce RISCV_EFFICIENT_UNALIGNED_ACCESS riscv: select DCACHE_WORD_ACCESS for efficient unaligned access HW arch/riscv/Kconfig | 14 +++++++++++ arch/riscv/Makefile | 2 ++ arch/riscv/include/asm/asm-extable.h | 15 ++++++++++++ arch/riscv/include/asm/word-at-a-time.h | 27 +++++++++++++++++++++ arch/riscv/mm/extable.c | 31 +++++++++++++++++++++++++ 5 files changed, 89 insertions(+)