All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzju@redhat.com>
To: linux-rt-users@vger.kernel.org, peterx@redhat.com
Cc: williams@redhat.com, jkacur@redhat.com, nsaenzju@redhat.com
Subject: [PATCH 3/3] oslat: Allow for arch specific timer frequency measurements
Date: Wed,  8 Sep 2021 12:02:09 +0200	[thread overview]
Message-ID: <20210908100209.118609-3-nsaenzju@redhat.com> (raw)
In-Reply-To: <20210908100209.118609-1-nsaenzju@redhat.com>

Some architectures have special purpose registers to query the system
timer's frequency. Let's use that when available.

Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
---
 src/oslat/oslat.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index bd155a6..23ca9b6 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -51,6 +51,9 @@
 # define atomic_inc(ptr)   __sync_add_and_fetch((ptr), 1)
 # if defined(__x86_64__)
 #  define relax()          __asm__ __volatile__("pause" ::: "memory")
+
+#define measure_timer_mhz generic_measure_timer_mhz
+
 static inline void frc(uint64_t *pval)
 {
 	uint32_t low, high;
@@ -61,12 +64,18 @@ static inline void frc(uint64_t *pval)
 }
 # elif defined(__i386__)
 #  define relax()          __asm__ __volatile__("pause" ::: "memory")
+
+#define measure_timer_mhz generic_measure_timer_mhz
+
 static inline void frc(uint64_t *pval)
 {
 	__asm__ __volatile__("rdtsc" : "=A" (*pval));
 }
 # elif defined(__PPC64__)
 #  define relax()          do { } while (0)
+
+#define measure_timer_mhz generic_measure_timer_mhz
+
 static inline void frc(uint64_t *pval)
 {
 	__asm__ __volatile__("mfspr %0, 268\n" : "=r" (*pval));
@@ -74,6 +83,15 @@ static inline void frc(uint64_t *pval)
 # elif defined(__aarch64__)
 #  define relax()          __asm__ __volatile("yield" : : : "memory")
 
+static inline unsigned int measure_timer_mhz(void)
+{
+	unsigned int val;
+
+	__asm__ __volatile__("mrs %0, cntfrq_el0" : "=r" (val));
+
+	return val / 1e6;
+}
+
 static inline void frc(uint64_t *pval)
 {
 
@@ -257,7 +275,7 @@ static cycles_t __measure_timer_hz(void)
 	return (cycles_t) ((e - s) / sec);
 }
 
-static unsigned int measure_timer_mhz(void)
+static unsigned int __attribute__((unused)) generic_measure_timer_mhz(void)
 {
 	cycles_t m, mprev, d;
 
-- 
2.31.1


  parent reply	other threads:[~2021-09-08 10:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 10:02 [PATCH 1/3] oslat: rename cpu_mhz/cpu_hz to timer_mhz/cpu_hz Nicolas Saenz Julienne
2021-09-08 10:02 ` [PATCH 2/3] oslat: Add aarch64 support Nicolas Saenz Julienne
2021-09-08 18:09   ` Peter Xu
2021-09-09 10:10     ` nsaenzju
2021-09-09 18:03       ` Peter Xu
2021-09-10 12:19         ` nsaenzju
2021-09-10 13:33           ` Peter Xu
2021-09-10 14:27             ` nsaenzju
2021-09-10 17:00               ` Peter Xu
2021-09-08 10:02 ` Nicolas Saenz Julienne [this message]
2021-09-08 18:16   ` [PATCH 3/3] oslat: Allow for arch specific timer frequency measurements Peter Xu
2021-09-09 10:29     ` nsaenzju
2021-09-09 18:04       ` Peter Xu
2021-09-08 14:40 ` [PATCH 1/3] oslat: rename cpu_mhz/cpu_hz to timer_mhz/cpu_hz Peter Xu
2021-09-08 16:30   ` nsaenzju
2021-09-08 17:51     ` Peter Xu
2021-09-09  9:41       ` nsaenzju
2021-09-09 18:05         ` Peter Xu

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=20210908100209.118609-3-nsaenzju@redhat.com \
    --to=nsaenzju@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=williams@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.