From: John Stultz <john.stultz@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: Richard Cochran <richardcochran@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Richard Cochran <richard.cochran@omicron.at>,
John Stultz <john.stultz@linaro.org>
Subject: [PATCH 2/3] ntp: add ADJ_SETOFFSET mode bit
Date: Mon, 27 Dec 2010 15:40:43 -0800 [thread overview]
Message-ID: <1293493244-17583-3-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1293493244-17583-1-git-send-email-john.stultz@linaro.org>
From: Richard Cochran <richardcochran@gmail.com>
This patch adds a new mode bit into the timex structure. When set, the bit
instructs the kernel to add the given time value to the current time.
CC: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <880d82bb8120f73973db27e0c48e949014b1a106.1292512461.git.richard.cochran@omicron.at>
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
include/linux/timex.h | 3 ++-
kernel/time/ntp.c | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 32d852f..82d4b24 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -73,7 +73,7 @@ struct timex {
long tolerance; /* clock frequency tolerance (ppm)
* (read only)
*/
- struct timeval time; /* (read only) */
+ struct timeval time; /* (read only, except for ADJ_SETOFFSET) */
long tick; /* (modified) usecs between clock ticks */
long ppsfreq; /* pps frequency (scaled ppm) (ro) */
@@ -101,6 +101,7 @@ struct timex {
#define ADJ_ESTERROR 0x0008 /* estimated time error */
#define ADJ_STATUS 0x0010 /* clock status */
#define ADJ_TIMECONST 0x0020 /* pll time constant */
+#define ADJ_SETOFFSET 0x0040 /* add 'time' to current time */
#define ADJ_TAI 0x0080 /* set TAI offset */
#define ADJ_MICRO 0x1000 /* select microsecond resolution */
#define ADJ_NANO 0x2000 /* select nanosecond resolution */
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index d232189..e9e3915 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -454,6 +454,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
int do_adjtimex(struct timex *txc)
{
struct timespec ts;
+ ktime_t delta, kt;
int result;
/* Validate the data before disabling interrupts */
@@ -482,8 +483,33 @@ int do_adjtimex(struct timex *txc)
hrtimer_cancel(&leap_timer);
}
+ if (txc->modes & ADJ_SETOFFSET) {
+ /* Validate the delta value. */
+ if (txc->time.tv_sec && txc->time.tv_usec < 0)
+ return -EINVAL;
+
+ if (txc->modes & ADJ_NANO) {
+ struct timespec tmp;
+ tmp.tv_sec = txc->time.tv_sec;
+ tmp.tv_nsec = txc->time.tv_usec;
+ delta = timespec_to_ktime(tmp);
+ } else
+ delta = timeval_to_ktime(txc->time);
+
+ /* Adding the delta should be an "atomic" operation. */
+ local_irq_disable();
+ }
+
getnstimeofday(&ts);
+ if (txc->modes & ADJ_SETOFFSET) {
+ kt = timespec_to_ktime(ts);
+ kt = ktime_add(kt, delta);
+ ts = ktime_to_timespec(kt);
+ do_settimeofday(&ts);
+ local_irq_enable();
+ }
+
write_seqlock_irq(&xtime_lock);
if (txc->modes & ADJ_ADJTIME) {
--
1.7.3.2.146.gca209
next prev parent reply other threads:[~2010-12-27 23:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-27 23:40 [PATCH 0/3] Cleanup ADJ_SETOFFSET patch John Stultz
2010-12-27 23:40 ` [PATCH 1/3] time: Introduce timekeeping_inject_offset John Stultz
2010-12-27 23:40 ` John Stultz [this message]
2010-12-28 20:47 ` [PATCH 2/3] ntp: add ADJ_SETOFFSET mode bit Kuwahara,T.
2011-01-03 20:44 ` John Stultz
2011-01-04 8:37 ` Richard Cochran
2011-01-04 19:08 ` John Stultz
[not found] ` <12d52d09b05.7801197194177918524.-8125715123212004756@gmail.com>
2011-01-05 7:00 ` Richard Cochran
2011-01-04 8:40 ` Richard Cochran
2011-01-04 19:14 ` John Stultz
2010-12-27 23:40 ` [PATCH 3/3] ntp: Change ADJ_SETOFFSET implementation to use timekeeping_inject_offset John Stultz
2010-12-28 11:20 ` [PATCH 0/3] Cleanup ADJ_SETOFFSET patch Richard Cochran
2010-12-28 12:53 ` Richard Cochran
2010-12-28 13:36 ` Richard Cochran
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=1293493244-17583-3-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard.cochran@omicron.at \
--cc=richardcochran@gmail.com \
--cc=tglx@linutronix.de \
/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