Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp714633rwb; Wed, 26 Jul 2023 01:21:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlHwTXRHcggZPDehnNBD2pm5vca8c2D/QO5SYhFc26sKz2kQkYOzL3m33zAbTvoym94IIqwN X-Received: by 2002:a05:6a20:13cd:b0:137:292a:fdc8 with SMTP id ho13-20020a056a2013cd00b00137292afdc8mr1422027pzc.9.1690359670273; Wed, 26 Jul 2023 01:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690359670; cv=none; d=google.com; s=arc-20160816; b=lCORtL090vMZNWtONJIe+j9ewNmBlkHrd7ze8pZCDrlcec89U1lqLeMcunlSXo3XfP uFjxLkr5Uh3dHF6Ul6Pz1O+LLD7u7AJi6R4Q30DYaPvbXg/w30XrVFLSqyS9YxaT93Vp HJ39g/A1A+yiVIJBHfeT5Q7mQ9uU3QVHzNt2/0AGzcQTUkRCqRwltBXRG7rSd3SLxXwT hU/V1U3kQLUHd7TUWtXZVIYmzbbFxRF83ehi2VPsy6IymYQ1Pd/rYZZiQzmKE0xW8s+r rln7BKMVUTt9xRB1KL1LoJrBiY36UgoFRQxlntHaPRegcLbTa1ewELtEag7lF0N1I3Vc PeXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XBOiXPX2QzyY0i5nmgALbzYaYDYC6Y2vfucDHylj3v8=; fh=AOGxZkvyQJyR8NGd3iiPIU03CDvhNr6/spDLuC8P3pQ=; b=JBsJuw3vV2Tw+7RkteJNglXFOgU9CCNcKrGgbmKD4Zmi3DoWiR+XfeUaeaGKGzgT5g iU/NUY8b/Qak2iT0w8vVg1AnbeTuIxEY/VFMtKUyf9dOonELc0qIoppe9TK0OJeD+MOn qhaiBT1ErpxlpHoANX3NzcYzvE+1/CsWIs+mqpxyYkb46iEwcKijiwzHE12MqGiUd/Zd FNRa5NB1XYLar+IeCNqg+q5bmy6DQ20n3MkKrDpObP0y/eNLpRDg6AtJ9xXtfNFwUFhh 1PNl576JicSFngKBvJR3x0HUCCYRuEbcipZXY0k/aU8ZMSOLPMvxU/mWAhSFH4I1YQ+u lSvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=nSlpnmCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s202-20020a632cd3000000b0053439c1712esi12577681pgs.713.2023.07.26.01.20.56; Wed, 26 Jul 2023 01:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=nSlpnmCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbjGZHzb (ORCPT + 99 others); Wed, 26 Jul 2023 03:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjGZHzB (ORCPT ); Wed, 26 Jul 2023 03:55:01 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0445A2716 for ; Wed, 26 Jul 2023 00:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=XBOiX PX2QzyY0i5nmgALbzYaYDYC6Y2vfucDHylj3v8=; b=nSlpnmCXTfGja3eME4Ebv v56CrtjXNrup3/HNyFGn/pH38jYW6wWyb4WstVvuBkX+aMNi/wE0F22ml5X5vQfi QZ89cTzLazNVHnQoXDt3DPTTapDoA1MAMoMMs8NCnApOOs5LPo7QgN6ORhR1h+XR dRlIXVMj4hsgX8gjiENBKM= Received: from yw-virtual-machine.localdomain (unknown [180.110.115.47]) by zwqz-smtp-mta-g2-4 (Coremail) with SMTP id _____wA33FiWz8BkpmpnBQ--.9036S2; Wed, 26 Jul 2023 15:47:35 +0800 (CST) From: wang_yang To: palmer@dabbelt.com Cc: aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, wang_yang , Wang Yang Subject: [PATCH] RISC-V: Use GCC __builtin_prefetch() to implement prefetch() Date: Wed, 26 Jul 2023 15:47:32 +0800 Message-Id: <20230726074732.32981-1-wang_yang6662023@163.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wA33FiWz8BkpmpnBQ--.9036S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr4xXryfJw1rGF18ury8Zrb_yoW8GFWxpF Z5Crn3WrWrWF1xu3yfJF4kWa1rKrnYgr4avrWxKwn7XFsxAr97tr9akrs8Jrn8JFWrZ34S yFW2qryrXa15AaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRIeHkUUUUU= X-Originating-IP: [180.110.115.47] X-CM-SenderInfo: 5zdqwsp1dqwlawwsijqt6rljoofrz/1S2mbAG49WNftPdKWwABsP X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L4,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 GCC's __builtin_prefetch() was introduced a long time ago, all supported GCC versions have it.So this patch is to use it for implementing the prefetch. RISC-V Cache Management Operation instructions has been supported by GCC last year.you can refer to https://github.com/gcc-mirror/gcc/commit/3df3ca9014f94fe4af07444fea19b4ab29ba8e73 It is worth noting that CPU based on RISC-V should support Zicbop extension. This has been already done on other architectures (see the commit: https://github.com/torvalds/linux/commit/0453fb3c528c5eb3483441a466b24a4cb409eec5). Signed-off-by: Wang Yang --- arch/riscv/include/asm/processor.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index c950a8d9edef..f16d4c85ca5b 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -70,6 +70,17 @@ extern void start_thread(struct pt_regs *regs, extern unsigned long __get_wchan(struct task_struct *p); +#define ARCH_HAS_PREFETCH +static inline void prefetch(const void *ptr) +{ + __builtin_prefetch(ptr, 0, 3); +} + +#define ARCH_HAS_PREFETCHW +static inline void prefetchw(const void *ptr) +{ + __builtin_prefetch(ptr, 1, 3); +} static inline void wait_for_interrupt(void) { -- 2.34.1