netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: netdev@vger.kernel.org, akpm@linux-foundation.org
Subject: [PATCH 08/12] ktime_sub_ns: analog of ktime_add_ns
Date: Wed, 29 Aug 2007 12:58:17 -0700	[thread overview]
Message-ID: <20070829195843.076226125@linux-foundation.org> (raw)
In-Reply-To: 20070829193922.078561651@linux-foundation.org

[-- Attachment #1: ktime_sub_ns.patch --]
[-- Type: text/plain, Size: 2030 bytes --]

Add macro/function to subtract constant nanoseconds.

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>


--- a/include/linux/ktime.h	2007-08-29 11:31:59.000000000 -0700
+++ b/include/linux/ktime.h	2007-08-29 11:41:19.000000000 -0700
@@ -102,6 +102,13 @@ static inline ktime_t ktime_set(const lo
 #define ktime_add_ns(kt, nsval) \
 		({ (ktime_t){ .tv64 = (kt).tv64 + (nsval) }; })
 
+/*
+ * Subtract a ktime_t variable and a scalar nanosecond value.
+ * res = kt - nsval:
+ */
+#define ktime_sub_ns(kt, nsval) \
+		({ (ktime_t){ .tv64 = (kt).tv64 - (nsval) }; })
+
 /* convert a timespec to ktime_t format: */
 static inline ktime_t timespec_to_ktime(struct timespec ts)
 {
@@ -200,6 +207,15 @@ static inline ktime_t ktime_add(const kt
 extern ktime_t ktime_add_ns(const ktime_t kt, u64 nsec);
 
 /**
+ * ktime_sub_ns - Subtract a scalar nanoseconds value to a ktime_t variable
+ * @kt:	        minuend
+ * @nsec:	subtrahend in nanoseconds
+ *
+ * Returns the difference of @kt and @nsec in ktime_t format
+ */
+extern ktime_t ktime_sub_ns(const ktime_t kt, u64 nsec);
+
+/**
  * timespec_to_ktime - convert a timespec to ktime_t format
  * @ts:		the timespec variable to convert
  *
--- a/kernel/hrtimer.c	2007-08-29 11:31:59.000000000 -0700
+++ b/kernel/hrtimer.c	2007-08-29 11:41:19.000000000 -0700
@@ -277,6 +277,30 @@ ktime_t ktime_add_ns(const ktime_t kt, u
 }
 
 EXPORT_SYMBOL_GPL(ktime_add_ns);
+
+/**
+ * ktime_sub_ns - Subract a scalar nanoseconds value to a ktime_t variable
+ * @kt:		minuend
+ * @nsec:	subtrahend in nanoseconds
+ *
+ * Returns the difference of kt and nsec in ktime_t format
+ */
+ktime_t ktime_sub_ns(const ktime_t kt, u64 nsec)
+{
+	ktime_t tmp;
+
+	if (likely(nsec < NSEC_PER_SEC)) {
+		tmp.tv64 = nsec;
+	} else {
+		unsigned long rem = do_div(nsec, NSEC_PER_SEC);
+
+		tmp = ktime_set((long)nsec, rem);
+	}
+
+	return ktime_sub(kt, tmp);
+}
+
+EXPORT_SYMBOL_GPL(ktime_add_ns);
 # endif /* !CONFIG_KTIME_SCALAR */
 
 /*

-- 
Stephen Hemminger <shemminger@linux-foundation.org>


  parent reply	other threads:[~2007-08-29 20:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-29 19:39 [PATCH 0/0] sky2: update for 2.6.24 Stephen Hemminger
2007-08-29 19:58 ` [PATCH 01/12] sky2: fe+ chip support Stephen Hemminger
2007-08-31 13:43   ` Jeff Garzik
2007-09-14 13:38     ` [PATCH] sky2: fix PHY setup on FE-P Stephen Hemminger
2007-08-29 19:58 ` [PATCH 02/12] sky2: use debugfs rename Stephen Hemminger
2007-08-29 19:58 ` [PATCH 03/12] sky2: document GPHY_CTRL bits Stephen Hemminger
2007-08-29 19:58 ` [PATCH 04/12] sky2: dont restrict config space access Stephen Hemminger
2007-08-29 19:58 ` [PATCH 05/12] sky2: advanced error reporting Stephen Hemminger
2007-08-29 19:58 ` [PATCH 06/12] sky2: use pci_config access functions Stephen Hemminger
2007-08-29 19:58 ` [PATCH 07/12] sky2: use net_device internal stats Stephen Hemminger
2007-08-31 13:43   ` Jeff Garzik
2007-08-31 13:59     ` Stephen Hemminger
2007-08-29 19:58 ` Stephen Hemminger [this message]
2007-08-29 19:58 ` [PATCH 09/12] export reciprocal_value for modules Stephen Hemminger
2007-08-29 19:58 ` [PATCH 10/12] sky2: hardware receive timestamp counter Stephen Hemminger
2007-08-29 19:58 ` [PATCH 11/12] sky2: avoid divide in receive path Stephen Hemminger
2007-08-29 19:58 ` [PATCH 12/12] sky2: 1.18 Stephen Hemminger
2007-08-30 20:36 ` [PATCH 0/0] sky2: update for 2.6.24 Stephen Hemminger

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=20070829195843.076226125@linux-foundation.org \
    --to=shemminger@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=jgarzik@pobox.com \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).