Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1710010iog; Tue, 14 Jun 2022 11:27:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uohr+Dq0CH2dCBr6/qPT/88HIooK/A0Baj22AhhkeQH8PXgsCpnbV75cYsTDonpwrJQY5Z X-Received: by 2002:a17:902:9348:b0:167:8e92:272f with SMTP id g8-20020a170902934800b001678e92272fmr5433943plp.77.1655231244210; Tue, 14 Jun 2022 11:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655231244; cv=none; d=google.com; s=arc-20160816; b=X1BL64A+uus7GGID1WesXoh+iKO2J98SNLXZzYuDiybI2DcUIdMXxMYpyT8eaQXVGa XstxtE/AULJQiZBE7mcNqAXDGYSZazRqGV9qci8G5VE12dcmNdGwK3blItk8LLEyZPPA 2mKxxU/I9kH1KDq7CuB3MYPL7dBRAh3mjh1kkBgPPdm5DEqNc6PWwqoeIDWPX/YLF1wy xP03AGEpwi3jMvMY3WNjrqy//vu1G4QQ+42N5gwJ2Du5n35K112FdbnZ1kr67AfoWdJ+ fh7H5INmQQ62Mb/3Dw4J319OlsIPpVMupKAgo8c5t9JLFFqOdrFwY36wft+D/CruaCt1 ZqsQ== 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=b6GogiLvLlJyAw9fEai9KHL7CPWrIDSYkmrligLXeM0=; b=X7shMbXXtCQkr/U7xdwvO3NlTzwwUM80uuqtEcCUAEdjWEYQQ/hxeGFfxsPvqSvNtj ayVCOWFfqs02bwJCrFR4OgJ4IneSTwkQsOlbhOjwL3/7wPxfc3By+DWOUVdN8R0JEwFc Q8N7sNQZS/dcdqwI+C26Sxph5nXShk9Z5F2R2pSUtdHTwNaAO0xFDRhLfJfAua8lq5y3 AHzo8pJG4eUFgVDDoX4knfFMH8RK28NP/P+uDAFBSWtmvA2vs5bL0E3w3bU9Q1Kb0NIj RT0b3xDrxSwhHU+KnIYCAuXf5N3bSrop9+ErXwB9JDkqRiz7+d0zL+6BUX87empK/p75 rd2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=B+GgFxGS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h64-20020a636c43000000b003fa8e644434si13063949pgc.39.2022.06.14.11.27.11; Tue, 14 Jun 2022 11:27:24 -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=@atishpatra.org header.s=google header.b=B+GgFxGS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236164AbiFNRtU (ORCPT + 99 others); Tue, 14 Jun 2022 13:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344959AbiFNRtO (ORCPT ); Tue, 14 Jun 2022 13:49:14 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537B933E33 for ; Tue, 14 Jun 2022 10:49:12 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-30ec2aa3b6cso37312787b3.11 for ; Tue, 14 Jun 2022 10:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b6GogiLvLlJyAw9fEai9KHL7CPWrIDSYkmrligLXeM0=; b=B+GgFxGSs58Fp+QAQlXmzpKdMTZABypU787d0qHLoDzxlJqoJ1k4nsrK+GLVFQ+4yb VOslI8mnRQ0TpcM6WUwdqCuagPSOtMOkoZw+N9XdOxR5RdGpaoCySoJRza5pOrlznLf8 Qf8S94NeqjsFaIMJTAYxJ8xwx83GP+BwppPgY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b6GogiLvLlJyAw9fEai9KHL7CPWrIDSYkmrligLXeM0=; b=P2Tx6v0c/bhH2L7++zui4JaB3/Nez8eSiWT0tOrBW+5CXIcL1MNvhuoatWMlxluq78 UsRvxqc55K7R9qi6GYO6NQ5TnboLk4iFdYxp5AW7gV5wTXwaiDEosvFXiOV8/dMKsk+p +q+4LbQeKKjmkYBBYLqedGg9VVGlc9nKhRY+XZr+LAImMkOSRFZFV7Ueat5S7ygmI8wG 97Lnkqtlkj6qU3A2CrtzQ6Ruijrt8dlrnoyMVjsL6Wmcspuj3vxCL0WQaL9MldpBfqKS 2PWseCXui2wk5dpewz45ZscxqCR7ntnTHLvfNeDFQXSJIZAE8qyJG0Ut4fQbhvbMjnHK z1EQ== X-Gm-Message-State: AJIora+SGAFGkZ9pKjzY+RvE8jCpIr0v6Bs8yJq30WixLnSsMhPdLZ02 FveGuxkgUGZ804EaYN+ER/4cQrM37vsuuvPy+zQg X-Received: by 2002:a81:1c08:0:b0:30c:cb78:8ae2 with SMTP id c8-20020a811c08000000b0030ccb788ae2mr7150978ywc.194.1655228951516; Tue, 14 Jun 2022 10:49:11 -0700 (PDT) MIME-Version: 1.0 References: <20220527042937.1124009-1-atishp@rivosinc.com> <20220527042937.1124009-4-atishp@rivosinc.com> In-Reply-To: From: Atish Patra Date: Tue, 14 Jun 2022 10:49:00 -0700 Message-ID: Subject: Re: [PATCH v4 3/4] RISC-V: Prefer sstc extension if available To: Anup Patel Cc: Atish Patra , "linux-kernel@vger.kernel.org List" , Albert Ou , Jisheng Zhang , linux-riscv , Palmer Dabbelt , Paul Walmsley , Rob Herring Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 On Thu, Jun 9, 2022 at 9:41 PM Anup Patel wrote: > > On Fri, May 27, 2022 at 9:59 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. > > > > Signed-off-by: Atish Patra > > --- > > drivers/clocksource/timer-riscv.c | 24 +++++++++++++++++++++++- > > 1 file changed, 23 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c > > index 1767f8bf2013..881d9335c92d 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) "timer: " fmt > > The "timer: " prefix is too generic. I suggest to use "riscv-timer: " > as a prefix. > Sured. Fixed in the next version. > > + > > #include > > #include > > #include > > @@ -23,11 +26,24 @@ > > #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 +181,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 > > > > Apart from the minor comment above, this looks good to me. > > Reviewed-by: Anup Patel > > Regards, > Anup -- Regards, Atish