Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp446487imn; Mon, 25 Jul 2022 23:06:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u9PKib5FS12d6HJqz0VcE6u/CP34h+XHhYEBTgNtrwZLIx124hnLBYDRNgjPQtB8dvabUD X-Received: by 2002:a17:902:8645:b0:16d:2b60:bc80 with SMTP id y5-20020a170902864500b0016d2b60bc80mr15631789plt.126.1658815571175; Mon, 25 Jul 2022 23:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658815571; cv=none; d=google.com; s=arc-20160816; b=GAB/w4VgBYU5IbOCoynS0Fe3Oe/IrC90asINXhZHJRjPmJ62O0VNLxw/7PenL/JkWv Uji11DD1Q9RiRP+G5tVEPi6rWWwcAJUSRXvQSesTN269m14dgZWuPw3R9EI39U3z1+2G 87hdR3NOTLuiCSqGlpA9bwdEDpTh4GbtA98JkYoMPVGzB7zETFJLLV5XCTFA4l3S/3Hc LBiaZL0mpzhFdwT9wWYrhcSL2W/GOahdE/D7IjAdGLRsPRDwXx1z/eLQvAubUkkIk65U iEcxFu1MwJNfomfOd9M9kcs1l9z0J3wX0A2OY0jRP+zqyqUy/l3pp0m9/ZvaWmZdtFg+ FQTQ== 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=wC2AgKCkoa/FuALgKTQYRYYG1SVq93t6JSMuNrwiiVQ=; b=z37zimXEsUXBAzE7H8X8+6KylmORyBkF0N0XuFda72qg1QjQZqmF/1GrUIfGveAory P91zbOVE+tg3YUVWm6MMzsC9FVHOTD/UWVTqdtCppku+47qw+d8ehNlpo9tICqgWRO+a sfa5EhBmyDlMqoauBi/6EKYMR5ei5PFw5xxT2igWVahBF7gSAqOyvAoHrvtLTUmsjCPL dVE2J4gDRWFexkSAvzUAfoDBVHf9Nh8wdSZbxIzUq3T1oDxq6O4laiwPoYd1ziDYs4H2 XIrt0ChJfJzeL/lz1V3B9604o1YvN+8wG/6k5TqBQ5QrUM8LCjxkl9AcXRwYN0eahJ+x uICg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=F4isfSDJ; 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 p41-20020a056a000a2900b0052bb7e1ef66si16708667pfh.296.2022.07.25.23.05.28; Mon, 25 Jul 2022 23:06:11 -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=F4isfSDJ; 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 S237472AbiGZFtt (ORCPT + 99 others); Tue, 26 Jul 2022 01:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230339AbiGZFts (ORCPT ); Tue, 26 Jul 2022 01:49:48 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3624524BDD for ; Mon, 25 Jul 2022 22:49:46 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-31f1b271dcbso40573107b3.10 for ; Mon, 25 Jul 2022 22:49:46 -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=wC2AgKCkoa/FuALgKTQYRYYG1SVq93t6JSMuNrwiiVQ=; b=F4isfSDJdigZd5IbUyJaKZkLsqKJ0djQ5AJsNPp5sk3hO0Srpfu02Gd+HPjkgrz5wo O+PaCOQyaFPTLB4WTUB8yVUUezS7JlUl8/ZSoHLcV6jckZwGIHBJ1tZepFRTGIu7NQS5 H6jeRvyaDzVzWFxtir2ln7IMoyaT6NHB+P+ew= 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=wC2AgKCkoa/FuALgKTQYRYYG1SVq93t6JSMuNrwiiVQ=; b=IKxfOwyK9L6E21RIqylA6Erzjx0gf7Lbizcul77xUnrdwSXQT8ezFNjvGZJmwQzA69 45MI1iR1o5oq29T+A8I9tW0liJh8LwowH1zJZ1M2H6aCivnn65F1A/iWEcJ+t0UV/e2F dW8v81MRw026tXd5CYXITyHB20oiqwIEkO3BUHU9258XnoB1dkjNk9VWisj0NRTPBc6d ISuXiPxXEnB+DlypQRUF0z36nPIypGNznnP5325wN0ucpNqGyhKvyFZydqVsTiJ/+HlZ bc05JA5GClyyGm167501IacOmwT/abQQqBwp/CtgN/+K9mQ7d3q7UcGVEsVtobnVZqke FETg== X-Gm-Message-State: AJIora+HCNOO2wGKIGe2Q1V2CuOrmsmy5qftdn62cI00g5XBVkmTzV+1 Ww0rUo5k5rwuynpMAcvGGEPulsuj0lvhsySb4BJN X-Received: by 2002:a81:7589:0:b0:31e:620b:e75 with SMTP id q131-20020a817589000000b0031e620b0e75mr12770978ywc.482.1658814584983; Mon, 25 Jul 2022 22:49:44 -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: Atish Patra Date: Mon, 25 Jul 2022 22:49:34 -0700 Message-ID: Subject: Re: [PATCH v7 3/4] RISC-V: Prefer sstc extension if available To: Atish Patra , Stephen Boyd , Palmer Dabbelt Cc: "linux-kernel@vger.kernel.org List" , 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 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 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 :) -- Regards, Atish