All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shailabh Nagar <nagar@watson.ibm.com>
To: Shailabh Nagar <nagar@watson.ibm.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	elsa-devel <elsa-devel@lists.sourceforge.net>,
	lse-tech@lists.sourceforge.net,
	ckrm-tech <ckrm-tech@lists.sourceforge.net>,
	Guillaume Thouvenin <guillaume.thouvenin@bull.net>,
	Jay Lan <jlan@sgi.com>, Jens Axboe <axboe@suse.de>
Subject: [RFC][Patch 1/5] nanosecond timestamps and diffs
Date: Wed, 07 Dec 2005 22:13:01 +0000	[thread overview]
Message-ID: <43975E6D.9000301@watson.ibm.com> (raw)
In-Reply-To: <43975D45.3080801@watson.ibm.com>

Add kernel utility functions for
- nanosecond resolution timestamps, adjusted for lost ticks
- interval (diff) between two such timestamps, in nanoseconds, adjusting
  for overflow

The timestamp part of this patch is identical to the one proposed by
Matt Helsley (as part of adding timestamps to process event connectors)
http://www.uwsg.indiana.edu/hypermail/linux/kernel/0512.0/1373.html

Signed-off-by: Shailabh Nagar <nagar@watson.ibm.com>

 include/linux/time.h |   16 ++++++++++++++++
 kernel/time.c        |   22 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)

Index: linux-2.6.15-rc5/include/linux/time.h
===================================================================
--- linux-2.6.15-rc5.orig/include/linux/time.h
+++ linux-2.6.15-rc5/include/linux/time.h
@@ -95,6 +95,7 @@ struct itimerval;
 extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
 extern int do_getitimer(int which, struct itimerval *value);
 extern void getnstimeofday (struct timespec *tv);
+extern void getnstimestamp(struct timespec *ts);

 extern struct timespec timespec_trunc(struct timespec t, unsigned gran);

@@ -113,6 +114,21 @@ set_normalized_timespec (struct timespec
 	ts->tv_nsec = nsec;
 }

+/*
+ * timespec_nsdiff - Return difference of two timestamps in nanoseconds
+ * In the rare case of @end being earlier than @start, return zero
+ */
+static inline unsigned long long
+timespec_nsdiff(struct timespec *start, struct timespec *end)
+{
+	long long ret;
+
+	ret = end->tv_sec*(1000000000) + end->tv_nsec;
+	ret -= start->tv_sec*(1000000000) + start->tv_nsec;
+	if (ret < 0)
+		return 0;
+	return ret;
+}
 #endif /* __KERNEL__ */

 #define NFDBITS			__NFDBITS
Index: linux-2.6.15-rc5/kernel/time.c
===================================================================
--- linux-2.6.15-rc5.orig/kernel/time.c
+++ linux-2.6.15-rc5/kernel/time.c
@@ -561,6 +561,28 @@ void getnstimeofday(struct timespec *tv)
 EXPORT_SYMBOL_GPL(getnstimeofday);
 #endif

+void getnstimestamp(struct timespec *ts)
+{
+	unsigned int seq;
+	struct timespec wall2mono;
+
+	/* synchronize with settimeofday() changes */
+	do {
+		seq = read_seqbegin(&xtime_lock);
+		getnstimeofday(ts);
+		wall2mono = wall_to_monotonic;
+	} while(unlikely(read_seqretry(&xtime_lock, seq)));
+
+	/* adjust to monotonicaly-increasing values */
+	ts->tv_sec += wall2mono.tv_sec;
+	ts->tv_nsec += wall2mono.tv_nsec;
+	while (unlikely(ts->tv_nsec >= NSEC_PER_SEC)) {
+		ts->tv_nsec -= NSEC_PER_SEC;
+		ts->tv_sec++;
+	}
+}
+EXPORT_SYMBOL_GPL(getnstimestamp);
+
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void)
 {

  reply	other threads:[~2005-12-07 22:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-07 22:08 [RFC][Patch 0/5] Per-task delay accounting Shailabh Nagar
2005-12-07 22:13 ` Shailabh Nagar [this message]
2005-12-12 18:50   ` [Lse-tech] [RFC][Patch 1/5] nanosecond timestamps and diffs Christoph Lameter
2005-12-12 19:31     ` Shailabh Nagar
2005-12-12 19:49       ` john stultz
2005-12-12 20:00         ` Shailabh Nagar
2005-12-12 20:07           ` john stultz
2005-12-13  0:54             ` George Anzinger
2005-12-13  3:48               ` Nish Aravamudan
2005-12-13 18:35         ` Jay Lan
2005-12-13 21:16           ` john stultz
2005-12-13 21:44           ` Shailabh Nagar
2005-12-13 22:13             ` George Anzinger
2005-12-13 23:05           ` [ckrm-tech] " Matt Helsley
2005-12-07 22:15 ` [RFC][Patch 2/5] Per-task delay accounting: Initialization, dynamic turn on/off Shailabh Nagar
2005-12-07 22:23 ` [RFC][Patch 3/5] Per-task delay accounting: Sync block I/O delays Shailabh Nagar
2005-12-07 22:33   ` [ckrm-tech] " Dave Hansen
2005-12-07 23:06     ` Shailabh Nagar
2005-12-07 22:28 ` [RFC][Patch 4/5] Per-task delay accounting: Swap in delays Shailabh Nagar
2005-12-07 22:29 ` [RFC][Patch 5/5] Per-task delay accounting: procfs interface Shailabh Nagar

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=43975E6D.9000301@watson.ibm.com \
    --to=nagar@watson.ibm.com \
    --cc=axboe@suse.de \
    --cc=ckrm-tech@lists.sourceforge.net \
    --cc=elsa-devel@lists.sourceforge.net \
    --cc=guillaume.thouvenin@bull.net \
    --cc=jlan@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lse-tech@lists.sourceforge.net \
    /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.