public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Suleiman Souhlal <ssouhlal@FreeBSD.org>
To: unlisted-recipients:; (no To-header on input)
Cc: Andi Kleen <ak@suse.de>, Linux Kernel ML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] Introduce a vmonotonic_clock() vsyscall.
Date: Mon, 13 Nov 2006 17:09:29 -0800	[thread overview]
Message-ID: <45591749.90501@FreeBSD.org> (raw)
In-Reply-To: <455916A5.2030402@FreeBSD.org>

This is the vsyscall equivalent of monotonic_clock(), using the per-cpu vxtime.
It returns the number of nanoseconds since boot.

It's intended to be used by processes that need a cheap and nanosecond
resolution time counter.

Signed-off-by:	Suleiman Souhlal <suleiman@google.com>

---
 arch/x86_64/kernel/vsyscall.c |   21 +++++++++++++++++++++
 include/asm-x86_64/vsyscall.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/arch/x86_64/kernel/vsyscall.c b/arch/x86_64/kernel/vsyscall.c
index 9025699..f124cc6 100644
--- a/arch/x86_64/kernel/vsyscall.c
+++ b/arch/x86_64/kernel/vsyscall.c
@@ -52,6 +52,7 @@ #include <asm/unistd.h>
 
 #define	NS_SCALE 10
 #define NSEC_PER_TICK (NSEC_PER_SEC / HZ)
+extern unsigned long long monotonic_base;
 extern unsigned long hpet_tick;
 
 extern unsigned long vxtime_hz;
@@ -108,11 +109,13 @@ void vxtime_update_pcpu(void)
 
 	do {
 		seq = read_seqbegin(&xtime_lock);
+		vxtime.pcpu[cpu].monotonic_base = monotonic_base;
 		vxtime.pcpu[cpu].tv_sec = xtime.tv_sec;
 		vxtime.pcpu[cpu].tv_usec = xtime.tv_nsec / 1000;
 		offset = hpet_readl(HPET_COUNTER) - vxtime.last;
 	} while (read_seqretry(&xtime_lock, seq));
 
+	vxtime.pcpu[cpu].monotonic_base += offset * NSEC_PER_TICK / hpet_tick;
 	vxtime.pcpu[cpu].tv_usec += (offset * vxtime.quot) >> 32;
 	vxtime.pcpu[cpu].last_tsc = get_cycles_sync();
 
@@ -256,6 +259,24 @@ vgetcpu(unsigned *cpu, unsigned *node, s
 	return 0;
 }
 
+unsigned long __vsyscall(3) vmonotonic_clock(void)
+{
+	unsigned long nsec, seq, t;
+	int cpu;
+
+	do {
+		seq = read_seqbegin(&__vxtime.vx_seq);
+		cpu = apicid();
+		nsec = __vxtime.pcpu[cpu].monotonic_base;
+
+		rdtscll(t);
+		nsec += ((t - __vxtime.pcpu[cpu].last_tsc)
+		    * __vxtime.pcpu[cpu].tsc_nsquot) >> NS_SCALE;
+	} while (read_seqretry(&__vxtime.vx_seq, seq) || cpu != apicid());
+
+	return (nsec);
+}
+
 #ifdef CONFIG_SYSCTL
 
 #define SYSCALL 0x050f
diff --git a/include/asm-x86_64/vsyscall.h b/include/asm-x86_64/vsyscall.h
index 707353b..5a10fd0 100644
--- a/include/asm-x86_64/vsyscall.h
+++ b/include/asm-x86_64/vsyscall.h
@@ -31,6 +31,7 @@ #define VGETCPU_RDTSCP	1
 #define VGETCPU_LSL	2
 
 struct vxtime_pcpu {
+	unsigned long monotonic_base;
 	time_t tv_sec;
 	long tv_usec;
 	unsigned long tsc_nsquot;



  parent reply	other threads:[~2006-11-14  1:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-14  1:06 [PATCH 0/2] Make the TSC safe to be used by gettimeofday() Suleiman Souhlal
2006-11-14  1:08 ` [PATCH 1/2] " Suleiman Souhlal
2006-11-14  2:05   ` Andi Kleen
2006-11-14  2:25     ` Suleiman Souhlal
2006-11-14  2:44       ` Andi Kleen
2006-11-14  3:35         ` dean gaudet
2006-11-14  4:22           ` dean gaudet
2006-11-14  3:54         ` Suleiman Souhlal
2006-11-14 11:12           ` Andi Kleen
2006-11-14  1:09 ` Suleiman Souhlal [this message]
2006-11-14  1:50 ` [PATCH 0/2] " Andi Kleen
2006-11-14  2:06   ` Suleiman Souhlal
2006-11-14 11:10     ` [PATCH 0/2] Make the TSC safe to be used by gettimeofday() II Andi Kleen
2006-11-14 12:30     ` [PATCH 0/2] Make the TSC safe to be used by gettimeofday() Shem Multinymous
2006-11-14 17:06       ` Suleiman Souhlal
2006-11-14 18:30         ` Andi Kleen
2006-11-14 21:28     ` Christoph Lameter
2006-11-14  7:42   ` Arjan van de Ven

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=45591749.90501@FreeBSD.org \
    --to=ssouhlal@freebsd.org \
    --cc=ak@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /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