[Patch 1/7] timespec diff utility

Shailabh Nagar
2006-02-27T08:02:50Z

nstimestamp_diff.patch

Add kernel utility function for measuring the
interval (diff) between two timespec values, adjusting for overflow

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

include/linux/time.h | 14 ++++++++++++++
1 files changed, 14 insertions(+)

Index: linux-2.6.16-rc4/include/linux/time.h
===================================================================
--- linux-2.6.16-rc4.orig/include/linux/time.h 2006-02-27 01:20:04.000000000 -0500
+++ linux-2.6.16-rc4/include/linux/time.h 2006-02-27 01:52:49.000000000 -0500
@@ -147,6 +147,20 @@ extern struct timespec ns_to_timespec(co
*/
extern struct timeval ns_to_timeval(const nsec_t nsec);

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

#define NFDBITS __NFDBITS