Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5784356imw; Wed, 20 Jul 2022 12:28:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1udiUD1Yz53ZphCGndhPwUzYEupPeN3SomQyqqliaJAzdBLaFvCG9zyeXtdQrK+MU/FhRK0 X-Received: by 2002:a05:6402:e8d:b0:43b:b989:67a7 with SMTP id h13-20020a0564020e8d00b0043bb98967a7mr4827490eda.365.1658345312288; Wed, 20 Jul 2022 12:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658345312; cv=none; d=google.com; s=arc-20160816; b=SBuwnpSv2OTMUiTPbJT+RKAShkM5IfZZq+9JnFkrsvtKA3vB9fBmFXIAfpTgoDLTa/ AR/Rfl6VvS2UweOrMGMt0rkAmmi8JhJX6WoDZt1ABMI1ESjRNms8IoiVFQO309CAzBXF fPPuAkFrzZxHdzX+6mYPVtoYhn0lMkC5UpJxXMHZWsKZodq7VmpLPUh/6GVPP4cvTtrI 5UXTPfu7/pDKliIcFjWIBjq9IclHojgfEBIaJiB3O+YgmNcs3dpJZ9VwtjC+2GIHxykL +WaQRHwJLK5torNzdVYn7G0HD/SbBXB6pAKEh1mqp5jua55d8AdRn760CuMcH8FJWiKf isFg== 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=k7oAEso24XUyiMu0RhEG3Nlz67s2VkRn8qN/IYX5xGk=; b=fCMAyDH7jetrdbJV6NgEq3/HGmXU73Uxsdy8YtKmYnDhyL+WiCX0lvLF+mcfvdjFMD Ce8QuwvCChlEbkV2dFuY3ZXskMwxIr1CvsN1LfbJbeoMtok/UlZQFknG6I0W1IbtGUMp j3dnxEssK3JOZEhBy/4jaKYrndSNYpCy6OeoQFzzcm84e9AvmG0GFTEg/ETcx+Lc6uoO NW1AzdGmfKZoP10e+0FzBy40qMsVtJszyHOEUHhmvXIJA/qcv8lJqGzYFZQY94+54ow3 6BXrXY12O12Uc01vhRMLukfvVjLrFCfTrjGPJYoRWppw0/AI0zG1/3dtDm5+IaFp5WYX kQtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=sY9xzDFI; 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 ht8-20020a170907608800b0072b4da1abe2si26193624ejc.791.2022.07.20.12.28.06; Wed, 20 Jul 2022 12:28:32 -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=sY9xzDFI; 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 S233339AbiGTTYH (ORCPT + 99 others); Wed, 20 Jul 2022 15:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231863AbiGTTX4 (ORCPT ); Wed, 20 Jul 2022 15:23:56 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44A4857268 for ; Wed, 20 Jul 2022 12:23:56 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id 70so17351071pfx.1 for ; Wed, 20 Jul 2022 12:23:56 -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=k7oAEso24XUyiMu0RhEG3Nlz67s2VkRn8qN/IYX5xGk=; b=sY9xzDFI9X3wzme+LId9I8R9+tn4yaAMLQpEbWaQ3yG2PQ5DtSBnecKXDC1IFimX6t K/qY0qg/2psalruNjlEzf0CEI1o2HccaVgkbFwMlwJj8LXADl7lxeiKjvIzcYUI8q5uJ ttyGd73sE3NX1DqDjAytZoQjw4rUEo0+iIqu765dNAOiICi/0wbNDYOGnMYM7Idiw+f9 dxI0O1CY6sfcSs5MWgNo9pDebidl7EyZEPDZa3unG5xPqkvDeJRoKSNwIckNUA+nvsiS kQry5184T2awXHtc9U47ggv3Fvs0JXytLLjZ9uJzG/lLzy5sXq+hstOnl5ywDIiGBreq hYWw== 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=k7oAEso24XUyiMu0RhEG3Nlz67s2VkRn8qN/IYX5xGk=; b=ixUPIcixBeSNP2YKz8lm3/7SAv9t5Hh9jlqRteosj0Z9O0cAbs7qsrynUURIVtK5sU BRi8gboOd4UqM7SJ8ZaNk+S0T+qtGyuy+mQkNRrX2V8rmy48YEnNnu3DQgayIAvWECw0 +uyCQWlIj6u/TjY5t0Lqlf0L4+512lpXuYE48lezyGpMChEGKsKoKiijJYTDAUyNhWV6 JXH+RZkg0N414PH1o0csdjNDnYeNuwvcFpPRpgZnjBYbE5o2XDJBqT2jq2m8LmX94ReE wP7HezP1beEugi7/DBdKZMJOLs4NhjRDQKRKsQcv7KWsP2J50Cll1aSjeZ+yaSIHfXxD dwSA== X-Gm-Message-State: AJIora/1CaoWqkufJpotjkERK5s/qSGQoUpfbNSdCVDWrJWU32895fQK a2B8adOYtyQc6lcTHiobFT3MkebTo5Nqpg== X-Received: by 2002:a65:4501:0:b0:3fc:4895:283b with SMTP id n1-20020a654501000000b003fc4895283bmr35712773pgq.231.1658345035855; Wed, 20 Jul 2022 12:23:55 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id y23-20020a17090264d700b0016d2e772550sm219902pli.175.2022.07.20.12.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 12:23:55 -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, Liu Shaohua , Niklas Cassel , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Philipp Tomsich , Thomas Gleixner , Tsukasa OI , Wei Fu Subject: [PATCH v5 3/4] RISC-V: Prefer sstc extension if available Date: Wed, 20 Jul 2022 12:23:41 -0700 Message-Id: <20220720192342.3428144-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220720192342.3428144-1-atishp@rivosinc.com> References: <20220720192342.3428144-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 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 593d5a957b69..3f100fb53d82 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 @@ -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