Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4503992rwb; Mon, 8 Aug 2022 02:02:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4W/Z/AlyX2BxbV3VD96iZv8ubY6Wt5eo05BEKCaG4r7WOSCSPgKy8CcG4nkSAYk6itdCcx X-Received: by 2002:a17:90b:35c3:b0:1f5:8a88:3b94 with SMTP id nb3-20020a17090b35c300b001f58a883b94mr15100051pjb.201.1659949358685; Mon, 08 Aug 2022 02:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659949358; cv=none; d=google.com; s=arc-20160816; b=Ybf98/hVTkvp7uFrisk0GE3yEq6t57I7IKVw8B1Zt+BLeOkrYz/KgVkaDthZzK1PO2 v4udMn9G3JMKlDfRgZ+1PNEU6Ur5dRC3QXKR2Gh1oDVcmhnioirSnzLUnEzjiatw/tH9 MzZVjyKBPNu1aaH2fh0Q5R6b8KjMWteUDBHipAZHqVsLk2jD9pwHate5c/wArVw7hNNz AMS3Q58/iWFoMECXO8iH2bE2nl4MlDKa9TGqXJKW+QIpO2voLvboC4tHbBDRik0onjru 9RIIm8f4/zeMLjh6jdjW5Ab9ZuApHsES0OCVg+VSC2KD8aeFcuW0QyYmzm6SpWjrB5eR KACg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nXZ3oM5FDT+81HggnfCqgaDmPsPGSjjDnqm53obzYqk=; b=DDUA9rS8gd//thvID1Tebn/rzGwA+kpjcmlXrXRnfRtYkyvUYyIFehuXsoWvhOOF9O zLl5tPkvnxIOdzbBlYemgY6Zhy0/uWRWIpenkvHpAzRO0qQSrRocUrK9RUQBkxg5ksI0 74orGupHroXUZ4/QX2N+SvAh7zI3IWAWxstB8d5kaRh7xU8tERA8JeyCGSAMyto9DMCy 0i2vDhAOaEiFwwNiBokdS0hKv2W6H644J1wE3scfrrM64WT33fHKJfAbaFo5GwwUOXqt dv5/6cRh3XVv6tkiWy0zkVvlipt4jStT4e852Z6XvChWQ+rVAr53Fg8xhp9DxZL2gJBM eQuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dRlv8aBv; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a635b57000000b0041983a96371si8892623pgm.613.2022.08.08.02.02.23; Mon, 08 Aug 2022 02:02:38 -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=@kernel.org header.s=k20201202 header.b=dRlv8aBv; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238306AbiHHI5Z (ORCPT + 99 others); Mon, 8 Aug 2022 04:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233665AbiHHI5Y (ORCPT ); Mon, 8 Aug 2022 04:57:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F805D90; Mon, 8 Aug 2022 01:57:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C5059B80E2F; Mon, 8 Aug 2022 08:57:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7477AC43140; Mon, 8 Aug 2022 08:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659949040; bh=41hkDjozTj/9771T7sIgIeayf3FHl7toj5PGFhaQaig=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dRlv8aBv9gmYQMMRysynhf3+XtHFgW0vc2MSDpq11XWpjmVBBFePhsFad6FIRSf1W tImr2wyVSdaBHT8jVVAQfiaytLde2W87xEJx4Df/laMM9224zInWE82a7NLGZrryuz 2wtKizJOrLfkkMgUUNaO5tYKddjmEvijmG1/FbwM2BnXNXDpxjskwo5n3/RjUvHFUa N1me2DWIpOScQhDCo0zH5e7U0XnO0jGzxHrsiS6a1R4zmDmoyc7a/Brr4kPuG3cuWd JyqqkVDXHpjQsGSR+u4fr2n0qySMsY4Shs9RB6DPIJ/nF5UlzHVA7hUX3zJDEOAfCc qAg4YUBkDJpVQ== Received: by mail-ot1-f52.google.com with SMTP id m22-20020a0568301e7600b006369227f745so6053488otr.7; Mon, 08 Aug 2022 01:57:20 -0700 (PDT) X-Gm-Message-State: ACgBeo2BKF0Lmw9t2IJMiiXC6DdzkaiQUI+In5GVCrNP6R/Jx13/xEtr tRmDWI0/vP2V6EAOewUkAB6Bcb+64XgBJ9hV2T0= X-Received: by 2002:a05:6830:928:b0:636:aaa7:813b with SMTP id v40-20020a056830092800b00636aaa7813bmr5058008ott.140.1659949039556; Mon, 08 Aug 2022 01:57:19 -0700 (PDT) MIME-Version: 1.0 References: <20220722165047.519994-1-atishp@rivosinc.com> <20220722165047.519994-4-atishp@rivosinc.com> In-Reply-To: <20220722165047.519994-4-atishp@rivosinc.com> From: Guo Ren Date: Mon, 8 Aug 2022 16:57:07 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 3/4] RISC-V: Prefer sstc extension if available To: Atish Patra Cc: linux-kernel@vger.kernel.org, Anup Patel , Albert Ou , Atish Patra , Daniel Lezcano , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Rob Herring , Thomas Gleixner , Tsukasa OI , Wei Fu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Looks good to me. The patch is concise, and static_branch is properly used. Reviewed-by: Guo Ren On Sat, Jul 23, 2022 at 12:51 AM Atish Patra wrote: > > RISC-V ISA has sstc extension which allows updating the next clock event > via a CSR (stimecmp) instead of an SBI call. This should happen dynamically > if sstc extension is available. Otherwise, it will fallback to SBI call > to maintain backward compatibility. > > Reviewed-by: Anup Patel > Signed-off-by: Atish Patra > --- > drivers/clocksource/timer-riscv.c | 25 ++++++++++++++++++++++++- > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c > index 593d5a957b69..05f6cf067289 100644 > --- a/drivers/clocksource/timer-riscv.c > +++ b/drivers/clocksource/timer-riscv.c > @@ -7,6 +7,9 @@ > * either be read from the "time" and "timeh" CSRs, and can use the SBI to > * setup events, or directly accessed using MMIO registers. > */ > + > +#define pr_fmt(fmt) "riscv-timer: " fmt > + > #include > #include > #include > @@ -20,14 +23,28 @@ > #include > #include > #include > +#include > #include > #include > > +static DEFINE_STATIC_KEY_FALSE(riscv_sstc_available); > + > static int riscv_clock_next_event(unsigned long delta, > struct clock_event_device *ce) > { > + u64 next_tval = get_cycles64() + delta; > + > csr_set(CSR_IE, IE_TIE); > - sbi_set_timer(get_cycles64() + delta); > + if (static_branch_likely(&riscv_sstc_available)) { > +#if defined(CONFIG_32BIT) > + csr_write(CSR_STIMECMP, next_tval & 0xFFFFFFFF); > + csr_write(CSR_STIMECMPH, next_tval >> 32); > +#else > + csr_write(CSR_STIMECMP, next_tval); > +#endif > + } else > + sbi_set_timer(next_tval); > + > return 0; > } > > @@ -165,6 +182,12 @@ static int __init riscv_timer_init_dt(struct device_node *n) > if (error) > pr_err("cpu hp setup state failed for RISCV timer [%d]\n", > error); > + > + if (riscv_isa_extension_available(NULL, SSTC)) { > + pr_info("Timer interrupt in S-mode is available via sstc extension\n"); > + static_branch_enable(&riscv_sstc_available); > + } > + > return error; > } > > -- > 2.25.1 > -- Best Regards Guo Ren