Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1896485rwb; Fri, 5 Aug 2022 09:30:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zme1Wk3uc4ZReoUFCNwt5pEzY0L17VivIh6cQhNMcjzE/fFcS9I5mJeaDRFfbRFcvHVvl X-Received: by 2002:a63:d94a:0:b0:412:6986:326e with SMTP id e10-20020a63d94a000000b004126986326emr6460864pgj.56.1659717002334; Fri, 05 Aug 2022 09:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659717002; cv=none; d=google.com; s=arc-20160816; b=fgJ50DxPb77T00OReyfb0LZFsEWvmBsUxcYEmvRs4C/S7t1etWLJ9eHWFTvdMygSFq aS12c9h2gJb5NVmMRbxgm34++oDTgwfBiq43k0wVw0Nq5cEHRascCUmY82B7Npuu0Xm0 GBQo5J5M9U1GDBJrf3oqS/PPgayuVwCUeupmc8XHqTE3URpdazQyyFjSO96y+Mb6de/n Kuh2JQsKR3Oa7Fv/zj5Dk/pZ6u0VVMI/h5G841WfHM2R1f3XZR9kNk4KTauXL3UNCc/D bTYqiVlSmX/WYGZR4terJNz+dKeM/ANg4Lrgy9kwm5/Ila1/1z0FnOIYMwuOdbIcTN+H R7og== 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=eU9F5KTyLXS6Ehm35W4ZJ4KkazoKzToP1yWNY4wU9Kg=; b=v4FT+F7wWouodDKuv4R4XDn8mzhwvDspc4yBtMyNyh95iu4XxJ7O8UoXzLn7mXTiwe e06YJcXdfOREiGUVZUF6NsLGiFSt1w3xJ0cDvsjuvejv54jHCMP4Mt1Lzc2reS+3iubR a05GsifPFACUAR06N+lZ15yZNjmRLJlAU2/YSge3byiMaMOHIII2v0FADrWbrSRtHlRv VSw2tCRGG5Tndx6tgUjk9RuMqqzNcedKjsWVKzor4YK6w72WP4QeDJkMNs4VAVth0ilI fe2M9blc2e7OErCZ0dzJ2EpN0TKU7JepbFBAPlqXWVR3MeVxo86s0yjbaCY5exlzVDMf Ypjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=OTIMcxvV; 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 s127-20020a632c85000000b00419be2b2b2fsi3372801pgs.735.2022.08.05.09.29.45; Fri, 05 Aug 2022 09:30:02 -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=OTIMcxvV; 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 S231545AbiHEQRt (ORCPT + 99 others); Fri, 5 Aug 2022 12:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238340AbiHEQRs (ORCPT ); Fri, 5 Aug 2022 12:17:48 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D5B4C630 for ; Fri, 5 Aug 2022 09:17:46 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-2ef5380669cso28641147b3.9 for ; Fri, 05 Aug 2022 09:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=eU9F5KTyLXS6Ehm35W4ZJ4KkazoKzToP1yWNY4wU9Kg=; b=OTIMcxvVmtHvZYnx9w+o/IIVHMVnFTjtZpg0iBHBJF/Skq2sQZgscB+aLiUJLN0sfj ysp6VTKukTmrHLmujjUvOzPbY2bFxqoHBmuaRFR/pAJBoyv7X1Nu520OafIyx6Qr6bOV +R3D5siCAJFSmOozQy6OIy6w4KtvhRp01pfrA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=eU9F5KTyLXS6Ehm35W4ZJ4KkazoKzToP1yWNY4wU9Kg=; b=OKstBDLoUXGyNw4kn4PkbqMUaGWFQDFivILPkDP6HWm0qvtZJxwUjvzWJR7My1l0BU zAtoxgrERqLHZZww7jygPkZ10/c6WNa9qDGw4IleR6+cXQBrufgSn2oE+ae7aH+JS4+g QcLpuucB2HyXc7UqQFEINPyxz7xcfcQaZ3veEwCrdIWW/vLeuza3NwZDQWnOhe4I72SA /qIDGjvR40t1DZ1bdk+eP8ttq8tLntdbgwd061eFCOGtVNweqOmSjS0r1wif+2CUSqAo Zbcwzaj8hlkRusCqr2UGlu8ztzVwrtSOnkLo8d/ehY60OyTFjZB60jb4ue8hnSY14QqF ozYA== X-Gm-Message-State: ACgBeo39NYXjo0HgcFfYR5aL7MdjH9S9O/Y9TgQpKaSYqWcWSrEorlhf wYZTsbaM3KC151M51BFkMIx8XE/WrOlUFUSKwRzl X-Received: by 2002:a81:5251:0:b0:31f:56c6:b69 with SMTP id g78-20020a815251000000b0031f56c60b69mr6801352ywb.75.1659716265625; Fri, 05 Aug 2022 09:17:45 -0700 (PDT) MIME-Version: 1.0 References: <20220722165047.519994-1-atishp@rivosinc.com> <20220722165047.519994-4-atishp@rivosinc.com> In-Reply-To: From: Atish Patra Date: Fri, 5 Aug 2022 09:17:35 -0700 Message-ID: Subject: Re: [PATCH v7 3/4] RISC-V: Prefer sstc extension if available To: Stephen Boyd , Palmer Dabbelt , Palmer Dabbelt Cc: "linux-kernel@vger.kernel.org List" , Atish Patra , Anup Patel , Albert Ou , Daniel Lezcano , Guo Ren , Heiko Stuebner , "open list:KERNEL VIRTUAL MACHINE FOR RISC-V (KVM/riscv)" , KVM General , linux-riscv , Paolo Bonzini , Paul Walmsley , Rob Herring , Thomas Gleixner , Tsukasa OI , Wei Fu 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=unavailable 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 Mon, Jul 25, 2022 at 10:49 PM Atish Patra wrote: > > On Fri, Jul 22, 2022 at 9:50 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 > > > > Hi Stephen, > Can you please review this whenever you get a chance ? We probably > need an ACK at least :) > Ping ? > -- > Regards, > Atish -- Regards, Atish