Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2073555lqe; Tue, 9 Apr 2024 08:50:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWh5ZhD9p5+BOqL/Mr7aJZZrhI4UgC2Hq7zw+vLUCcE3jw/ASuGMiuxyMsw/2I/KLm2TS2jlt85NHl0v3wW6GaCdaPMRsBTWNkAUx1dBQ== X-Google-Smtp-Source: AGHT+IEkBIUP9Bd3iWiAgcyZgZnTXGvoo+g4xGJqyudcOGhCHCPll3lylWaULU4Uq0BCNgPhTlVb X-Received: by 2002:a92:cd87:0:b0:36a:37cc:6d1b with SMTP id r7-20020a92cd87000000b0036a37cc6d1bmr243496ilb.22.1712677816090; Tue, 09 Apr 2024 08:50:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712677816; cv=pass; d=google.com; s=arc-20160816; b=scnztfobJkhR22uPkwHgTWjdED0P0VMIZIUjQ2v5PoiORJIkkNCmU0SXzvvfPODyM7 SasO6wbvkgDmgMhyVqZqdSFAKYIMWOrqVnz//j3BhPUbQFQ3wlbyzxpoiw0C3HzrlrRL S/p8F4cWWivC+YNOpnBWlaIDg2DU/xYYnZMdzhYJfS4XdtgZJlzSQebMnfY5UM+r/npq qZuQqoYhoQRoYzD3uWGbpolqo6Ha2PDVs5P9AZJlPBLxeysPksqxA+x5bMu8k2YtFvra cKDs4dzggbMbufdR7tkCSDE1IUMt84jB2bDIeW6a3Sq+COH27nAT9vlGHsCVaOiYHcDG a20g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=u+DKkIX5S9U7VkZPHNjygrgF5S4v/yaCGSezdsnkBE8=; fh=Rx6KPEc7pEkGnGFMTFogwF4EoQSLPuiYXpLoDgSVyXc=; b=pOQH8Yohesy9HUNIhkwcl0dNiljNnW5xGi7MqBF9oxvDEypRv1QR1+aFtgySqA0dIb cJDtAxcsyyC5gNDQBrnR9XsgaPsXMMUXFMa7TeDljTLXnnkZ/rgqt829tzNOA/m5ZG52 KHo/79Cq2vn6QyxUb2HjFLsEkAvLwmC3DDqZjOQ65w2ucfWQvBB6zLNU6Hrcqp3kAJTt MSrMVs3K+mN4zFZzMRg+ijwS2XB0WjthYqMRbf9ts8XIAouTtOctDKg+fMu9iWb26PN5 FTm54YoVwxEJ+MDEZwCyKfuIi5bulcCKSB+CxahB7isOS/l1gbHBBz7Tf0moM+eSPADP ycEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=erWrqUYz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u4-20020a637904000000b005dc4300d4f0si8601500pgc.444.2024.04.09.08.50.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:50:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=erWrqUYz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 42EC4B246B8 for ; Tue, 9 Apr 2024 15:03:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF652132808; Tue, 9 Apr 2024 15:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="erWrqUYz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B821A136665 for ; Tue, 9 Apr 2024 15:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712674913; cv=none; b=n4UdHZKqYir9G29uD6wNkNDf6imYZ5u9PaBR6MWEgQI0VLzt4MHvsUWqQ8KdMFGw/MKJ3koikDDmUnxJu3K1cWBYW7285p68wYdegIIWWyHg+ZEtXWOx+NkzQ9SuJj6dqjKvCEDAIje+rrXpGJOBcIxuxPIg6qsJ7BrFgFwPvSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712674913; c=relaxed/simple; bh=Q8oZYTQPe7yxE75cZ/ybR1+HKZVuPqvv9xAWvwwsZDM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r2BK2jfY65vl8d4Ajaby0KDo8hW1zy3zmYCaE/J24wVhrx6Khn0TNa8Cmw6bv7dMGIxRIS4tAqteZ54FgrL4MWepFFTyBoU0uDnLJmJ2k8exiy9z3320MXN2vQLgyPWECFh5x4EcwIHkHSmNkM4pScGpb+2+4KcRypqvNqPsJXI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=erWrqUYz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 718E1C433F1; Tue, 9 Apr 2024 15:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712674913; bh=Q8oZYTQPe7yxE75cZ/ybR1+HKZVuPqvv9xAWvwwsZDM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=erWrqUYzXjcyXobCYeBKxEdKina/eHfaim+ZDs8jUfJxvJlqmpfhE9nQFd1Hi06PD 4LwfSGj13rk3Nonpjy0yDfG/0ZHHApJWdrRUWMW4nSHpFY2OATH35My72p0Z92ahft Ri3tMKkglNVrYNT5tHClAE5AEcGufqrW8J/emc3DHShYmx0TiZClXL5jBpxZAXbJDe AsVW9wp7d5njcqSJdx+k1EFO9BD7kkvGZRfp4gM9Rl1tQ2O3lsXjQJefcc8dfWf2AF DcP+94uGbC4IUJqI02PG+e9+lyievw6BXNcVR4r0odJXYMxyyH/XHdaNL3OzQUvJZC I5cnz43Rg1K3g== Date: Tue, 9 Apr 2024 22:48:28 +0800 From: Jisheng Zhang To: Conor Dooley Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Samuel Holland , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] clocksource/drivers/timer-clint: Add option to use CSR instead of mtime Message-ID: References: <20240406112159.1634-1-jszhang@kernel.org> <20240406112159.1634-3-jszhang@kernel.org> <20240409-krypton-employed-b2e0e1b46ddf@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240409-krypton-employed-b2e0e1b46ddf@spud> On Tue, Apr 09, 2024 at 03:26:18PM +0100, Conor Dooley wrote: > On Sat, Apr 06, 2024 at 07:21:58PM +0800, Jisheng Zhang wrote: > > As pointed out by commit ca7810aecdba ("lib: utils/timer: mtimer: add a > > quirk for lacking mtime register") of opensbi: > > > > "T-Head developers surely have a different understanding of time CSR and > > CLINT's mtime register with SiFive ones, that they did not implement > > the mtime register at all -- as shown in openC906 source code, their > > time CSR value is just exposed at the top of their processor IP block > > and expects an external continous counter, which makes it not > > overrideable, and thus mtime register is not implemented, even not for > > reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS > > extended CSR, these systems still rely on the mtimecmp registers to > > generate timer interrupts. This makes it necessary to implement T-Head > > C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing > > reading mtime register and falls back to default code that reads time > > CSR." > > > > To use the clint in RISCV-M NOMMU env on Milkv Duo little core, we > > need to fall back to read time CSR instead of mtime register. Add the > > option for this purpose. > > > > Signed-off-by: Jisheng Zhang > > > diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig > > index 34faa0320ece..7bbdbf2f96a8 100644 > > --- a/drivers/clocksource/Kconfig > > +++ b/drivers/clocksource/Kconfig > > @@ -650,6 +650,15 @@ config CLINT_TIMER > > This option enables the CLINT timer for RISC-V systems. The CLINT > > driver is usually used for NoMMU RISC-V systems. > > > > +config CLINT_USE_CSR_INSTEADOF_MTIME > > + bool "Use TIME CSR instead of the mtime register" > > + depends on CLINT_TIMER > > + help > > + Use TIME CSR instead of mtime register. Enable this option if > > + prefer TIME CSR over MTIME register, or if the implementation > > + doesn't implement the mtime register in CLINT, so fall back on > > + TIME CSR. > > This, as a Kconfig option, seems a bit strange to me. We know at runtime > if we are on a T-Head device without the mtime register and should be > able decide to use the CSR implementation dynamically in that case, > right? Dynamically decision can be done in clocksource/clockevnt: I can patch clint_clocksource.read to point to different clint_rdtime() implementation. But clint timer is also used in NOMMU RISCV-M's get_cycles(), this can't be dynamically chosen w/o an ugly "if (is_c900)" check, and I'm not sure whether this check in get_cycles() will introduce non-trival overhead or not. Or use code patching technology here? Or introduce a function pointer such as unsigned long (*rdtime)(void) for RISCV_M_MODE, then point it to different implementation? Any suggestion is welcome. Thanks