Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp817039imi; Fri, 22 Jul 2022 10:05:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t0LxV/dl0dgmVjwWxH3HTN7CoiycuNv/J+QLQAZ0csRGqFB5r/9LohDJS2KQtPQEGryR7W X-Received: by 2002:a17:907:2c4a:b0:72b:5b9b:9c50 with SMTP id hf10-20020a1709072c4a00b0072b5b9b9c50mr658572ejc.636.1658509510121; Fri, 22 Jul 2022 10:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658509510; cv=none; d=google.com; s=arc-20160816; b=II5iFANk7P45lIbXgS3bm4ZbnuX4ufpPZT/OhQO2N1UZDgW/usCe4J+TPpSofqhZuG MUFLTkI0Jhs9b2NzSRqJOCPl2ORJPjPcK4krtoA/JolXXd+k6w2mc5S4WLq2/3pt636I mBGo94UItQveTfnHysTJMmPsXbGtd6lQgS8WPtd6i8WyGqboA4GRgmmmaGb9Z41IxwSf 7CKawB2nmMC4TNTTHvByW/3LDAZPBO+9TzyhyTdaswAdXXyP7xIzaqLqJuUauip1uNs7 78E2VAeCYFSb7fZlxXgrlV2KjzoEE0jD6RHD6XP8mAtDySgIyq5N1Dql+2GQaxUSuT2h VCDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fhiEUpY832dBqpBZs6lVDJUJh/wPjhRPH5Wz0gZOdjs=; b=v6kZppVIKkOH66hgr77al4DrEiZHnanaTAKekBNlynM00fiFdTTIcPxOt1nhFyGUg9 9DymcSN60vYdS5xC0RwW8GqEpRYbHqA/HsSPYRP+dBZ3WSm0Ay3rEzWqG7eBUMX3ATZG TjUyGDFob9uEot8riNtCVrCPQyzqXgxuH3xfCr8Okh4iIH9k1fG4BWdddiAg6rBAeFwd 18F+tl2QputuZ3UyQBeWcFGAQDU+Fc3bwovThGaHt+izeONJkhnI/RkEgQ63CgYUb3s9 Vo4idBr/gIgGJ9hQP/hwQWLbWos3C+OFnQh/CT62bC4NcsbGsoRxsOx+HETTkBqneF+K 3tFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=dlpFbmXI; 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 h9-20020a1709070b0900b0072f2b3bdaa7si5246846ejl.359.2022.07.22.10.04.45; Fri, 22 Jul 2022 10:05:10 -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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=dlpFbmXI; 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 S236039AbiGVQvO (ORCPT + 99 others); Fri, 22 Jul 2022 12:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234456AbiGVQvA (ORCPT ); Fri, 22 Jul 2022 12:51:00 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C4229812 for ; Fri, 22 Jul 2022 09:50:59 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id l14-20020a17090a72ce00b001f20ed3c55dso4682251pjk.5 for ; Fri, 22 Jul 2022 09:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fhiEUpY832dBqpBZs6lVDJUJh/wPjhRPH5Wz0gZOdjs=; b=dlpFbmXItlUG9AvAKQ4H72BXu7Ec0gAYulbojqhVRlPlmOQtGwb0eiZ2TMO2TCDDrj DnL31uggr5tjrAfWw7V9MNiEU/aMiiaCv86V7QRe6dTtRLRyvr/Myez57yefVPu79b9a R3r744egp5g760mv20a1p2v3LqLYnEICd03OzMW1NmHz9mgyBnS6xXAycfkF/JmOa7V0 pBu2teIE9lF7a0FyNp+c9fI/Em3+ZOb4oRMHK4OnKeF3P4aKM5aDtdfr56IcgqXK2kHP by52M9Tm29aOBwPMFiHW4YZ2DWiSLPoihmkCKzsL7cyyoHA4euIFOr/SEF/GcVFvmD2j O6sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fhiEUpY832dBqpBZs6lVDJUJh/wPjhRPH5Wz0gZOdjs=; b=bYsKWH4Ik2S07rUCi7HzOOepjXvqhYaIJh/1ZU3k5r5T0ugTETNpYPTNany8n1ouM6 NPvbIUXf9ii7SaUqvKZnyewoT9b0kgHj/qD9Xz0FGkeMwdr0U7K+odhVMb7KEfvBquLt 4jFEDSneXj4uEn4T3Y/KOCWye8QPOfbV16yJG7D0g4YmDcSQYxRGcnWEHRvNRNCJfQ7s 9kKm1qb+RRU8TKmENDjtApjGIRQvOPS4TEaD1TMWkAhQ2fnRtPlqJ5diy+m7NJSICh/0 qq9cEFKx6+LdnszgAYuedAhVmrs4QV0WJMoMFmgq5tgy6rLOr2D4XCY6nlNKkPbWoBp/ y01A== X-Gm-Message-State: AJIora9MlMEr0IvfkKc7E6iYFgK1xzEn9sBVGZUb9xemjz7Ie58ra9hp XNYMqaeW/bRkje4FFFCYZKQVPHjpJIV/dQ== X-Received: by 2002:a17:902:70cc:b0:16c:60e0:50fb with SMTP id l12-20020a17090270cc00b0016c60e050fbmr443033plt.156.1658508658489; Fri, 22 Jul 2022 09:50:58 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id s7-20020a170902ea0700b0016a3f9e4865sm4028476plg.148.2022.07.22.09.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:50:58 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Atish Patra , Daniel Lezcano , Guo Ren , 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 Subject: [PATCH v7 3/4] RISC-V: Prefer sstc extension if available Date: Fri, 22 Jul 2022 09:50:46 -0700 Message-Id: <20220722165047.519994-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722165047.519994-1-atishp@rivosinc.com> References: <20220722165047.519994-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_PASS 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 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