Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp415630lqb; Tue, 16 Apr 2024 23:04:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwm26wTkoVBmlJ4SnSvLy7dbWkBWKHnFcUpdbdW8slfaV1yJ7+98Tob4Cx7A/wfUGAL8zopSDskltR54TznNqVqjzK4QDBbClPys5rJw== X-Google-Smtp-Source: AGHT+IG1vA/AXjsUbFJu7HTW1ZdB4z69EwzBpkN1XjJWO+1XfVbw4VRYi59a+QIbXJLgKXH96Taz X-Received: by 2002:a17:906:c309:b0:a52:4246:7f65 with SMTP id s9-20020a170906c30900b00a5242467f65mr6744914ejz.35.1713333864360; Tue, 16 Apr 2024 23:04:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713333864; cv=pass; d=google.com; s=arc-20160816; b=FEOYEjuhtU+VTDDL4Tv8LFqCCSc1QpC74WwdusuNb1PLFQK0M4pojd40lxdeK3RMGg 53xC7NM7WqANLWr+v9DvZ0FEMAEowsEtR9MVFfvba0adG7kybVTG4MnpMkvJesZNWF9v 9oShMo1afuT2Hi8W0vnX48X4//5sO9i+zV1Zgb+YTNi0IbmnuBvsiu60TGaHmGROlZqM wbEck5y3hnOH3tGolPEV6P49aO21HoQ1Xa+dn4qEwPdopE2Bnq9FcH4qdXztbzMflP// N5iwfj0EiT2fWGdcscDHlf0GnG8w7b81Yvq5Im95qMtKjJ82/bd6JHWaAzaiYJw7eZPU 9RfQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=emlaPvn8yP0ZKbzvbtaqbLqnMofLE1ThVdu9UJ+caJI=; fh=d7OdmkkuCuGyjS+PVP2O+9Z0oka0qSvQULYxwWaEwVk=; b=j8BUmIi+ayXMD5Q4KSilGPFZlnMRW3DuRok1FT1AwYsFrqxFMpF9uSBLXJ7sdcRZX5 l+ErATAb1eR5OMVdJ4TX7tGC/dbOmjdmtiTyRJy3VZCdFAu4FuEEVOOKZ3disRv4vsXs IQCQNXSZz0bLRyJEAXgFWIWgIdmNO1yvxr8eSvEg8n8uQ6ketc662PRTzbzZHq69gh6N 50HNdxcuFmp9xBJ2rPB2YzZyKVXy2sY5k5tFGetV0toHnzL44Trjka47OkUVWNN7iDeZ avFjPcoXYeRmfsCHbMlvSavDbMjb4A9icLtxnP43Hhwazl3/OYYFf02P+3Nur+o/REjD mTEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=plrDSG6r; arc=pass (i=1 dkim=pass dkdomain=brainfault-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147974-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k21-20020a1709063e1500b00a52393ea7ccsi5228331eji.958.2024.04.16.23.04.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 23:04:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=plrDSG6r; arc=pass (i=1 dkim=pass dkdomain=brainfault-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147974-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id E848D1F22385 for ; Wed, 17 Apr 2024 06:04:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6D1C535D5; Wed, 17 Apr 2024 06:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b="plrDSG6r" Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48B1B535A4 for ; Wed, 17 Apr 2024 06:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713333857; cv=none; b=g7Kbr5U2OAamoSL9jiZ1kNpAbn1mQ+uD4GWUx/zaVhWi4itaIB5aX8zVaSoYfmRHXYtov1D/+FcLX+r3f+7TqNXzV5vDfVK/jdRPPxLQlqn4E706jn5BPtccUKIxLNVWE/CojD/yhz+ZwDCPDGsWblESgtDhWhxg9oQkUMudjMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713333857; c=relaxed/simple; bh=ZGh2Oun/2Xy3zlhfCoEUmiZx6g9yxMw149Z7Exr23Wo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VYwxfYStoPElDY/rMLE+wAnY7DROurByDdGWKBtLgPcYX1xknfBtX8jDrAVGs/MxmTfJzFbY6rvPGKXVwBRm9BiUK0Lj5ouCkEgLqEknhczXdVB3LEpJnIkJi9IuVa3nSbH8bOavRlNv2vU5NVHORbnyL6tcKVLYms/LiZCuM+I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org; spf=none smtp.mailfrom=brainfault.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b=plrDSG6r; arc=none smtp.client-ip=209.85.166.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=brainfault.org Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-36a23d5c31bso24535605ab.2 for ; Tue, 16 Apr 2024 23:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1713333855; x=1713938655; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=emlaPvn8yP0ZKbzvbtaqbLqnMofLE1ThVdu9UJ+caJI=; b=plrDSG6rF+1Ui28n5YoBXb9UqgVzdjU+/Hz98A4/eRAtSPqPfsklNXTYUfadT8gWXj /M9Q9H/RORgs1zrXuDHHj99saYhBSaX/rx7mGD/RdqD7iDxztMzW+1MIVyMYTqVPbAvh 15MpIItXKlQUpSXB+OTgD4npc5b3AVKlySYBEMps5GCr6ywQSxYgPw9MvPHpsdq+pZg4 3bH24uW/LQamR7FtjTLHXS5rjCe7erkUoDpSLCQI5q8lZMbvbsRsJTtmcVQzyYJLiY4N 8EkLEBD2myOcvj44051OZ4x3W+TPov/hX2lEoFps4S7uQRQdh7VAInht002hlgztjZ5a sWYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713333855; x=1713938655; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=emlaPvn8yP0ZKbzvbtaqbLqnMofLE1ThVdu9UJ+caJI=; b=GPPzH7lCMU0qDnlyjbm0RS2jIvRh427p276pecMUajde0hB9+rTzy9E9mcFJtZQSSn /vR8T5/nKJVzwaNQEiECPPbK94IJEx0aZG9YltfLAGOp3AOSo9rc55C0735PqM8AGaka SYf3bs2+4G4UQ3dlHNAdm0by1ah4S3q1snjv/mfGKxzqU7mzxfp5lJR6Y3S8Q/TOQ50u Mer0Z48air5uCBd6gjmCkHUqZyGEstL8+P6R0FLvVwmME+dLKxtLU6fEGgCJ2wbhF3M5 n5vgzKf4rlqnuWL33Rf3zAV40n9MqtX759N/NFPWxfQ+1pAslJrAxLntyYXe6MJdN84m V3VQ== X-Forwarded-Encrypted: i=1; AJvYcCVSFc+hMLsFMvn0Z6YtYv8xuir+3gUUFjz5OwV1gvw8MMItqClToLIuk1yOkClbuTs2cVG8iwDnPKu2z1s1/QjMBydw4iQpl/F8qUay X-Gm-Message-State: AOJu0YzTPzBTPPLxEKV3jhr334Uix3lfnP+V/5DVXSSzLSjJ6O3MfRyy Tc6unc2+jftM5QEJXnHrtAoZX8MpCPHzYRemk00+xZzHbDLo6Gq7oXn+fYNxGCeT4IqCOX8/6Lq r8RKXHzP7CD3uy3cNPDiu2s360OOuyjlylnEnAA== X-Received: by 2002:a92:c542:0:b0:36b:a3:bc93 with SMTP id a2-20020a92c542000000b0036b00a3bc93mr17521625ilj.5.1713333855283; Tue, 16 Apr 2024 23:04:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Anup Patel Date: Wed, 17 Apr 2024 11:34:02 +0530 Message-ID: Subject: Re: [PATCH] clocksource/drivers/timer-riscv: Drop extra CSR write To: Palmer Dabbelt Cc: apatel@ventanamicro.com, samuel.holland@sifive.com, daniel.lezcano@linaro.org, tglx@linutronix.de, aou@eecs.berkeley.edu, Paul Walmsley , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 17, 2024 at 7:20=E2=80=AFAM Palmer Dabbelt = wrote: > > On Wed, 13 Mar 2024 09:56:34 PDT (-0700), apatel@ventanamicro.com wrote: > > On Wed, Mar 13, 2024 at 1:03=E2=80=AFAM Samuel Holland > > wrote: > >> > >> On riscv32, the time comparator value is split across two CSRs. We wri= te > >> both when stopping the timer, but realistically the time is just as > >> unlikely to reach 0xffffffff00000000 as 0xffffffffffffffff, so there i= s > >> no need to write the low CSR. > > > > Even though unlikely, there is still a theoretical possibility of > > counter reaching value 0xffffffff00000000. > > I guess that depends on the timebase frequency, but if my math is right > then we've got some timers that will overflow a 32-bit counter in 10 > minutes -- take that with a grain of salt as they're all 64-bit systems > (we don't have any 32-bit DTs upstream?), but it still seems plausible > for 32-bit overflows to happen here on real systems. > > > The good thing about value 0xffffffffffffffff is that the counter will > > immediately wrap around after reaching it. > > I'm not sure how that's good? Luckily we've got ~100,000 years to > figure out, even on these systems with pretty fast timers ;) The RISC-V server soc spec mandates timer frequency to be at least 100 MHz so we can certainly have 100MHz as the timer frequency and based on this time CSR will overflow in roughly 5840 years. Also, nothing stops a SoC vendor from having a GHz timer frequency. In addition to timer frequency, changing the initial value of time CSR can also impact when the time CSR overflows. This particularly applies to virtualization because KVM RISC-V allows the KVM user space tool to set the desired initial value of time CSR visible to the Guest/VM. For example, if the timer frequency is 10MHz and KVM user space tool sets initial time CSR value to 0xffffffff_00000000 then Guest/VM time CSR will overflow in roughly 7 mins. Regards, Anup > > > Regards, > > Anup > > > > > >> > >> Signed-off-by: Samuel Holland > >> --- > >> > >> drivers/clocksource/timer-riscv.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/t= imer-riscv.c > >> index e66dcbd66566..eaaf01f3c34b 100644 > >> --- a/drivers/clocksource/timer-riscv.c > >> +++ b/drivers/clocksource/timer-riscv.c > >> @@ -35,9 +35,10 @@ static bool riscv_timer_cannot_wake_cpu; > >> static void riscv_clock_event_stop(void) > >> { > >> if (static_branch_likely(&riscv_sstc_available)) { > >> - csr_write(CSR_STIMECMP, ULONG_MAX); > >> if (IS_ENABLED(CONFIG_32BIT)) > >> csr_write(CSR_STIMECMPH, ULONG_MAX); > >> + else > >> + csr_write(CSR_STIMECMP, ULONG_MAX); > >> } else { > >> sbi_set_timer(U64_MAX); > >> } > >> -- > >> 2.43.1 > >> > >> >