Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2725812ioo; Tue, 24 May 2022 04:43:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV/nHEtKVKPkFJZEMZJjrZvHFKlHVSHCNr8k+EkSYzsPd1KuGZFb0zEz9vH24/03+FngV5 X-Received: by 2002:a17:907:c25:b0:6fe:f9e2:9c5a with SMTP id ga37-20020a1709070c2500b006fef9e29c5amr5793303ejc.69.1653392621517; Tue, 24 May 2022 04:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653392621; cv=none; d=google.com; s=arc-20160816; b=xFmGsDmiMR3NqiTRU7GcXu6c5voLj05ActDEKmD17MVNQaGwFI3F6C86+SFVXK2JTI Hp4rIKI/tHVzUrl90FCuAS11Zg4PD7AokZx99OAxbHjqVgJD42lqE4U0bMTLi/76v7SG AGPCydGjrSKoUgoIShreDZLqwQ/P+L48ltowSVevh1pJuRE8p2QOq9pHtGkPGq8OG+QA hppP0V9OgvukFCB2SVbbu96H1p/DxcVzLT00qs2SMNPzp9kDuOBTtf4gQZVLbtqlk3Ks CwuzM+qqKOa+sTipptdoRoXbGeC7QurH7QrmYgglC8PtNcE/6pFW7tPDkUWnHL301vRs u4rA== 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=N2TjPYBfTxyr+DNrjNs2M1CQcfw6+WY+gUO3SgZbUV8=; b=FJppOOQILUWz0puht+mcOYdmv3rTX/LoRU0IjhFq3S/clD4U4ZYiMmLcs/fN5/4WOK M20sVjrwdyVIA+qK7sqUUJ/jAc+VQ8CJE7mz+GRE7IfblRYJIO5T/CjGBrr74nUJ8jXW 1w6sNRdH3ZUuJkHadM4x3e9DDdJJOVPEEGLqjGoVwGwEPghjLlIPUDJRRshU2F30Wy5U SSX9lbGXney8heafJtJKHdxbN+J4k4yk1WfEriQ85drZwwXiTbZUda9AjIYIms08EQKc PoeRClfxb5bJ/VyvrnrfeZ63y7mEZRSfYjbPBrcVNEkim/5VEjEXV8LScQ+SK5yj60aV /suQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=CQm5UAeg; 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 gv15-20020a1709072bcf00b006df76385e41si15776020ejc.737.2022.05.24.04.43.16; Tue, 24 May 2022 04:43:41 -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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=CQm5UAeg; 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 S236666AbiEXLaj (ORCPT + 99 others); Tue, 24 May 2022 07:30:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235844AbiEXLaa (ORCPT ); Tue, 24 May 2022 07:30:30 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA7D880C3 for ; Tue, 24 May 2022 04:30:28 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id s28so25128967wrb.7 for ; Tue, 24 May 2022 04:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N2TjPYBfTxyr+DNrjNs2M1CQcfw6+WY+gUO3SgZbUV8=; b=CQm5UAeg1hkuSSsutDNG5mlSigGV02SDoqjU1pCYNr5ah4YevJSWr4AlQwCQwgTADA Rzxq6t0CYWD0MFIzFIMr8eEcThDGPSsKmJB+J43x5VewBMw0wOPN2v2sStD1uD0CcV+5 lMhPO2CuOIiIyfabVPzeLQkFQw3i4iUfhB6CvZq0HgMiLGJ9R+khlNSwcUZoVI1v6JQR fTaGOLJvyrOqKxqeBpyObRLnv8m9iFNcnorpjp5Mljh3Ks4i8eq6kH09cHJ7FGZCKoAC lcYTWNKaE1FjnBW/gzO2bfzncP4dWIxk6CQQa0GO/H2gXyL+cEaFFy6ge2aJgxMRwU0h e4Uw== 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=N2TjPYBfTxyr+DNrjNs2M1CQcfw6+WY+gUO3SgZbUV8=; b=lv0moLxP8iHADCOE6B9vqjZW8Xv0OENzMTxXz8YZnW/1IgAG6e8lXy1eSU/LBwBh5R PDAbX5gNiIaeEnWuo1bl6NsWkOpM/YAJ4Nyf+a3NAWsn4GEZUC2YWEpyWx/ghgfzlPkt w6MxOp2+qzFgmxpwYTbcjM6JfCstbKInw9CAoDnu1t7LNKWNX4vpoVqifoEajNKy6gX3 gAxyc/hHbiYG9wNQb8GMjDIHptUueO5vb1Cbn96uE+cE/YOHjoCVsgwVDnjhBdznRGtr bRnaLO6Rj5fJaLaEzXiUfvMSDRRHBOT7IjqI2/CFEEmDbkPlJ4YYz3NdxueK+GtcvLOv kH6A== X-Gm-Message-State: AOAM533ye11HBKJhEq3Y5WQ5fmUQcF0Qu2EgjjoOoIzYzvvqZ0MoGeXw S4XQe4JdfzrJoKMqBng4+M300Ol2rUqpObOoaIgBCQ== X-Received: by 2002:adf:f001:0:b0:20d:22b:183c with SMTP id j1-20020adff001000000b0020d022b183cmr22457285wro.313.1653391826736; Tue, 24 May 2022 04:30:26 -0700 (PDT) MIME-Version: 1.0 References: <20220426185245.281182-1-atishp@rivosinc.com> <20220426185245.281182-4-atishp@rivosinc.com> In-Reply-To: <20220426185245.281182-4-atishp@rivosinc.com> From: Anup Patel Date: Tue, 24 May 2022 17:00:15 +0530 Message-ID: Subject: Re: [PATCH v3 3/4] RISC-V: Prefer sstc extension if available To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Atish Patra , Damien Le Moal , DTML , Jisheng Zhang , Krzysztof Kozlowski , KVM General , "open list:KERNEL VIRTUAL MACHINE FOR RISC-V (KVM/riscv)" , linux-riscv , Palmer Dabbelt , Paul Walmsley , Rob Herring Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, 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 Wed, Apr 27, 2022 at 12:23 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 | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c > index 1767f8bf2013..d9398ae84a20 100644 > --- a/drivers/clocksource/timer-riscv.c > +++ b/drivers/clocksource/timer-riscv.c > @@ -23,11 +23,24 @@ Add "#define pr_fmt(fmt)" here since you are using pr_info(...) > #include > #include > > +static DEFINE_STATIC_KEY_FALSE(riscv_sstc_available); > + > static int riscv_clock_next_event(unsigned long delta, > struct clock_event_device *ce) > { > + uint64_t next_tval = get_cycles64() + delta; Use "u64" here to be consistent with other parts of the kernel. > + > csr_set(CSR_IE, IE_TIE); > - sbi_set_timer(get_cycles64() + delta); > + if (static_branch_likely(&riscv_sstc_available)) { > +#if __riscv_xlen == 32 Use CONFIG_32BIT here. > + 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 +178,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 > Regards, Anup