mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephen Eta Zhou <stephen.eta.zhou@gmail.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>,
	 Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
	 Stephen Eta Zhou <stephen.eta.zhou@gmail.com>
Subject: [PATCH v4] clocksource: timer-sp804: Fix read_current_timer() issue when clock source is not registered
Date: Sun, 25 May 2025 16:43:28 +0800	[thread overview]
Message-ID: <20250525-sp804-fix-read_current_timer-v4-1-87a9201fa4ec@gmail.com> (raw)

Register a valid read_current_timer() function for the
SP804 timer on ARM32.

On ARM32 platforms, when the SP804 timer is selected as the clocksource,
the driver does not register a valid read_current_timer() function.
As a result, features that rely on this API—such as rdseed—consistently
return incorrect values.

To fix this, a delay_timer structure is registered during the SP804
driver's initialization. The read_current_timer() function is implemented
using the existing sp804_read() logic, and the timer frequency is reused
from the already-initialized clocksource.

Signed-off-by: Stephen Eta Zhou <stephen.eta.zhou@gmail.com>
---
Changes in v4:
- Dropped redundant `delay.freq = rate;` assignment in `sp804_clocksource_and_sched_clock_init()`
- Dropped redundant `delay.read_current_timer` and `register_current_timer_delay()` lines in `sp804_of_init()`
- No functional changes to the driver logic; these lines were unnecessary as per Daniel's feedback.
- Link to v3: https://lore.kernel.org/all/20250414-sp804-fix-read_current_timer-v3-1-53b3e80d7183@gmail.com

Changes in v3:
- Updated the commit message for clarity and structure
- Link to v2: https://lore.kernel.org/all/BYAPR12MB3205D7A2BAA2712C89E03C4FD5D42@BYAPR12MB3205.namprd12.prod.outlook.com

Changes in v2:
- Added static keyword to struct delay_timer delay
- Integrate sp804_read_delay_timer_read and
  struct delay_timer delay together
- I moved the acquisition of delay.freq to
  sp804_clocksource_and_sched_clock_init.
  sp804_clocksource_and_sched_clock_init has already
  acquired and judged freq, so I can use it directly,
  and in this way I don’t need to consider whether to
  use clk1 or clk2, which can ensure that the clock source
  is available and reliable.
- Added detailed description information in Commit
- Link to v1: https://lore.kernel.org/all/BYAPR12MB3205C9C87EB560CA0CC4984BD5FB2@BYAPR12MB3205.namprd12.prod.outlook.com
---
 drivers/clocksource/timer-sp804.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c
index cd1916c0532507fb3ce7a11bfab4815906e326d5..e82a95ea472478ae096b2bf7abea0d65a7bca480 100644
--- a/drivers/clocksource/timer-sp804.c
+++ b/drivers/clocksource/timer-sp804.c
@@ -21,6 +21,10 @@
 #include <linux/of_irq.h>
 #include <linux/sched_clock.h>
 
+#ifdef CONFIG_ARM
+#include <linux/delay.h>
+#endif
+
 #include "timer-sp.h"
 
 /* Hisilicon 64-bit timer(a variant of ARM SP804) */
@@ -102,6 +106,23 @@ static u64 notrace sp804_read(void)
 	return ~readl_relaxed(sched_clkevt->value);
 }
 
+#ifdef CONFIG_ARM
+static struct delay_timer delay;
+static unsigned long sp804_read_delay_timer_read(void)
+{
+	return sp804_read();
+}
+
+static void sp804_register_delay_timer(int freq)
+{
+	delay.freq = freq;
+	delay.read_current_timer = sp804_read_delay_timer_read;
+	register_current_timer_delay(&delay);
+}
+#else
+static inline void sp804_register_delay_timer(int freq) {}
+#endif
+
 static int __init sp804_clocksource_and_sched_clock_init(void __iomem *base,
 							 const char *name,
 							 struct clk *clk,
@@ -114,6 +135,8 @@ static int __init sp804_clocksource_and_sched_clock_init(void __iomem *base,
 	if (rate < 0)
 		return -EINVAL;
 
+	sp804_register_delay_timer(rate);
+
 	clkevt = sp804_clkevt_get(base);
 
 	writel(0, clkevt->ctrl);
@@ -318,6 +341,7 @@ static int __init sp804_of_init(struct device_node *np, struct sp804_timer *time
 		if (ret)
 			goto err;
 	}
+
 	initialized = true;
 
 	return 0;

---
base-commit: 7ee983c850b40043ac4751836fbd9a2b4d0c5937
change-id: 20250411-sp804-fix-read_current_timer-1c7c5a448c6c

Best regards,
-- 
Stephen Eta Zhou <stephen.eta.zhou@gmail.com>


WARNING: multiple messages have this Message-ID
From: stephen.eta.zhou@gmail.com
To: stephen.eta.zhou@gmail.com
Cc: daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org,
	tglx@linutronix.de
Subject: RE: [PATCH v4] clocksource: timer-sp804: Fix read_current_timer() issue when clock source is not registered
Date: Thu, 23 Oct 2025 14:55:03 +0800	[thread overview]
Message-ID: <20250525-sp804-fix-read_current_timer-v4-1-87a9201fa4ec@gmail.com> (raw)
Message-ID: <20251023065503.Go2mmhoggtKtmYeA8wwCkgkTWtmtySjAeRftD5ZR-S8@z> (raw)
In-Reply-To: <20250525-sp804-fix-read_current_timer-v4-1-87a9201fa4ec@gmail.com>

Hi,

I wanted to follow up on my `[PATCH v4] clocksource: timer-sp804: Fix read_current_timer() issue when clock source is not registered` patch,
which I submitted on Sun, 25 May 2025.

I haven't received any feedback yet.

so just ping....

If any updates or modifications are required, please let me know. 

Thanks.

Best regards,  
Stephen

             reply	other threads:[~2025-05-25  8:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-25  8:43 Stephen Eta Zhou [this message]
2025-10-23  6:55 ` stephen.eta.zhou
2025-11-05 13:00 ` Daniel Lezcano
2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers/timer-sp804: " tip-bot2 for Stephen Eta Zhou
2025-12-15 23:18 ` [PATCH v4] clocksource: timer-sp804: " Guenter Roeck
2025-12-16  5:38   ` stephen.eta.zhou
2025-12-16  5:48     ` Guenter Roeck
2025-12-16  6:05       ` stephen.eta.zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250525-sp804-fix-read_current_timer-v4-1-87a9201fa4ec@gmail.com \
    --to=stephen.eta.zhou@gmail.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®