Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3065032lqp; Mon, 25 Mar 2024 19:39:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeT24TvmMIR96vNKXjzG0h6f+LnNruOKkX6Wb+YvENIoL4Rdw/0wSJnJBUKQJEAY1U78/imSUMlnS+aW3HjG4LpjOfkbNhnivQAlcWHw== X-Google-Smtp-Source: AGHT+IFvu1/5g5qvtIDshVZHDwu6WMOGB7jGOp4TwX5nJUtDm5JdEZY4KLEe9PMujPLK9xYV+5b8 X-Received: by 2002:a9d:68d0:0:b0:6e6:cb76:3974 with SMTP id i16-20020a9d68d0000000b006e6cb763974mr7390552oto.19.1711420781930; Mon, 25 Mar 2024 19:39:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711420781; cv=pass; d=google.com; s=arc-20160816; b=aS9gP36K0YTQ5bONSKJtJ4warSp4SqfO5GblKcBt4oPdcScjfcfIWK6MA1bqPdHCwB WQ6AsUyGmHIs5XPXwOK+USkc/ruySjJ/pUtZ9RnYB6NYFE81MG2k6q98j4pQCJ1HtH+9 lZeRtd7XwgmBk36a+4TFqgbxHT7FRF1yKbSn8EZSCLUgYE3tj8h8emz4kur+u9KslmYp G0RyPNmdzpeugoEjfM3o0xyKuKoLqqw/fh2ZIBw60pkDQOcSWgS63PR4TzzmRJgADifx 0xZJdfrQe0uAfVNBmPn35nP9GQU6+CsL3Q/MA590ihwQddYBLhfNwAnohZV+X6twICAi vQ5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=4AgrCK3LU8fuZoVf5zgRFHwqwQjRIG9mTqB1m/TopnI=; fh=x7mNP49pVmYjsnbr4TZ2vx2e0trAvVMBnQZSue7GF80=; b=mdRSnjagSf0ofgKoTWht0oe8ItVpa4eO0eEZhewBs6w8ccspvZtb6SmczPxsbNOPNh bFmhbiK0EQ/30WdaCHXIg8i+d2eOpJ86iZT1quGpRiC0a49owVNn5r+/r6HhSQPlfcpg TGj4zV7qnLg+lsfI/GCYjNJsDIVhbD1j9n6D9kwdyhjbBjVNL3OJ1vat1j2+pfC374dl Pz/+2T1IYVOdIjo1FCbKymwAXntzPT1enyPTIZLXJZ7lkD7HabBq5CbZeISWqFdJP7ou fNYeIjlk0GfvPMw6ExrmgVzPVfYnZCp2xY3sIhVVrCcuCYueyQIULv1jm3tQfWaemQ/r M5Mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iSfXUcQ0; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-118309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h5-20020a631205000000b005dc352a5637si8457885pgl.323.2024.03.25.19.39.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 19:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iSfXUcQ0; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-118309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 353382E7C9A for ; Tue, 26 Mar 2024 02:39:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9122128385; Tue, 26 Mar 2024 02:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="iSfXUcQ0" Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 35DA6128368 for ; Tue, 26 Mar 2024 02:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711420770; cv=none; b=XU04B0drp7Ymj1N5awdr5nKT73ldwyFxVu2XUL755f2CUgvk1mPmaL2a1m7nvkoIsqLwallBVVcqPFGHZ7XTe5OZMjwULmCt9b4IsZawN0yf2IEwtH3c9dDpJ86398kLxW+0a2bxgdLDMgTzwWGbHiq7U+LkBbb/3T73wpJxzXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711420770; c=relaxed/simple; bh=zUMMYSTKNGKXkA4klgoSYnxSaopM3FNL66QpHVmfNgE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=d4niKqVd1uY1mS7LI1eTOCLWWUOyJKx0u73ZAOvpMdmNy+CiLHMJC/g123rIztj/k/UkNADisLBERK16j8Nlw6jzuqQLYk/0ZhvH/CDn/XSbbOj4TGq4Plj4v7VksFEFMJ2146OtYI+f36DhuDc13UXAcchCYFohL2FfI+oR7pY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=iSfXUcQ0; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-60a0579a968so53786647b3.3 for ; Mon, 25 Mar 2024 19:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711420768; x=1712025568; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4AgrCK3LU8fuZoVf5zgRFHwqwQjRIG9mTqB1m/TopnI=; b=iSfXUcQ0sfhhdScDzfGmkMPl6Qn11l26Math5ZKPz5RfF0izu9Yo+8MdgtMix0eHCV UXdhjFw9w8WTILude9R96aveS2qqKxtccuD8eawxjXB8k/Upt2skb+TLx76Jz5atBFOS ffPgR/+4krfUUvfdfsR9R/bOTHFDLi8E6/A1s5OcT8gsBfAy3RukHehu8oZeOO0MjGu1 E35yEH0YkLY6sKas02TqBxQTBJct0POGIiXysrDPnhPJ+72QJddWFYUpDPUufX8F60z8 zw9kM1azKxXtxQWLXjvu+qCM1im+k4jgFgvE/v1mhS51dXJPr+PjB7xySb+jC32fu3AY 2enA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711420768; x=1712025568; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4AgrCK3LU8fuZoVf5zgRFHwqwQjRIG9mTqB1m/TopnI=; b=RNIr2PG/jyiicgP8O05pcv0ki9HjV4ZDovxSxdU4FkHv+zxI8ZOG0uQViIahNtE178 x2iIBQ+aW2NY64Zx3p4/du0gbg//Ncd14WJZenOvzONsuieBo6t1Ima3Zxvz9qWUo6UD CkwRxkcRMYjT66mh7WMygTKyT9okQJZvhkj6vvXcj9+EnLEIobEyNEJ60cUPmXh8f2i/ KXJPpXffgOk/aNMve4LM8ut2bNoYp2CN1kBFk4erJzf0spQHCsGz06GeXZ9R1/e2485i wyABxG0u8FW6uNMpQdfiMrNbJneFJaINJ1olOyOdQY/w7l+x1Sm3+kFTZQ/EzgVCIdq/ j1xA== X-Forwarded-Encrypted: i=1; AJvYcCVAEsHxPNvzkKsJw4Zn9VOihM0FE1o2FC1g3XufulGxqJSFMYifSxZeiCu28rU4JYVwnGRJAVFqPqNAJU0Ys8D+roqS6HpKcNxA1e7u X-Gm-Message-State: AOJu0YzYK7CUw0mZ7se6YiaiKXACQ8wLFBqJ1SfmsUSAOv7n7i7serhk jDcXV4JyW3omK3U47WYrQKGZjD3wlRCYezAJRrt56IGxIzNWq5bFP4PmV8SIEfo= X-Received: by 2002:a0d:e446:0:b0:610:f43d:6f9a with SMTP id n67-20020a0de446000000b00610f43d6f9amr6625429ywe.50.1711420768139; Mon, 25 Mar 2024 19:39:28 -0700 (PDT) Received: from [100.64.0.1] ([136.226.86.189]) by smtp.gmail.com with ESMTPSA id r19-20020a028813000000b00474a1ac6434sm2497058jai.162.2024.03.25.19.39.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Mar 2024 19:39:27 -0700 (PDT) Message-ID: Date: Mon, 25 Mar 2024 21:39:26 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] riscv: nommu: use CSR_TIME* for get_cycles* implementation To: Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20240325164021.3229-1-jszhang@kernel.org> <20240325164021.3229-3-jszhang@kernel.org> Content-Language: en-US From: Samuel Holland In-Reply-To: <20240325164021.3229-3-jszhang@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Jisheng, On 2024-03-25 11:40 AM, Jisheng Zhang wrote: > Per riscv privileged spec, "The time CSR is a read-only shadow of the > memory-mapped mtime register", "On RV32I the timeh CSR is a read-only > shadow of the upper 32 bits of the memory-mapped mtime register, while > time shadows only the lower 32 bits of mtime." Since get_cycles() only > reads the timer, it's fine to use CSR_TIME to implement get_cycles(). Unfortunately there are various implementations (e.g. FU740/Unmatched, probably K210 which this code was originally used for) which do not implement the time CSR, relying on M-mode software to emulate the CSR so S-mode software doesn't notice. So this code is needed to support those platforms when running Linux in M-mode. Maybe there should be an option to assume the time CSR is/is not implemented, like there is for misaligned access? Regards, Samuel > Signed-off-by: Jisheng Zhang > --- > arch/riscv/include/asm/timex.h | 40 ---------------------------------- > 1 file changed, 40 deletions(-) > > diff --git a/arch/riscv/include/asm/timex.h b/arch/riscv/include/asm/timex.h > index a06697846e69..a3fb85d505d4 100644 > --- a/arch/riscv/include/asm/timex.h > +++ b/arch/riscv/include/asm/timex.h > @@ -10,44 +10,6 @@ > > typedef unsigned long cycles_t; > > -#ifdef CONFIG_RISCV_M_MODE > - > -#include > - > -#ifdef CONFIG_64BIT > -static inline cycles_t get_cycles(void) > -{ > - return readq_relaxed(clint_time_val); > -} > -#else /* !CONFIG_64BIT */ > -static inline u32 get_cycles(void) > -{ > - return readl_relaxed(((u32 *)clint_time_val)); > -} > -#define get_cycles get_cycles > - > -static inline u32 get_cycles_hi(void) > -{ > - return readl_relaxed(((u32 *)clint_time_val) + 1); > -} > -#define get_cycles_hi get_cycles_hi > -#endif /* CONFIG_64BIT */ > - > -/* > - * Much like MIPS, we may not have a viable counter to use at an early point > - * in the boot process. Unfortunately we don't have a fallback, so instead > - * we just return 0. > - */ > -static inline unsigned long random_get_entropy(void) > -{ > - if (unlikely(clint_time_val == NULL)) > - return random_get_entropy_fallback(); > - return get_cycles(); > -} > -#define random_get_entropy() random_get_entropy() > - > -#else /* CONFIG_RISCV_M_MODE */ > - > static inline cycles_t get_cycles(void) > { > return csr_read(CSR_TIME); > @@ -60,8 +22,6 @@ static inline u32 get_cycles_hi(void) > } > #define get_cycles_hi get_cycles_hi > > -#endif /* !CONFIG_RISCV_M_MODE */ > - > #ifdef CONFIG_64BIT > static inline u64 get_cycles64(void) > {