From patchwork Thu Jan 13 11:32:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 78712 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8FD41B7043 for ; Thu, 13 Jan 2011 22:33:38 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932934Ab1AMLcw (ORCPT ); Thu, 13 Jan 2011 06:32:52 -0500 Received: from mail-fx0-f46.google.com ([209.85.161.46]:39048 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932891Ab1AMLcr (ORCPT ); Thu, 13 Jan 2011 06:32:47 -0500 Received: by mail-fx0-f46.google.com with SMTP id 20so1558131fxm.19 for ; Thu, 13 Jan 2011 03:32:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=ZkEAc/kwrS6z1p6wwKIy+3Pth+z34/7GRrI2tOY9/i8=; b=JE6n2QpO0KQV1R1WUL337SgzccHg389ee1QD2ToJp5FJyOfT/UzOea6GH8ymCwzmEv do/M0kVzNGBQa4VYdA1r75yCBBQvN00mn5ySlMlsUGFFHFkmd5zvAHFXN4Z2CEh49ptX 0DKKu+M/ZDIe0ri8Q+tSKFpnH6sudmOvqsI3c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=jLfLLPubSvNcUZ9wp8tx8TTwtX1FeQZgIDvTkwDOz4d2suXecYnliJiSd2gaZGlHwA 0M5YS9QBs/WQdG7dVAQQCzEH04uBCBan/vquIgpj/AgHKeyFAPVk0dPSr4+i3FVjaQEj iH+MmNbKJipMcnuMpk8HcbnrDZI5UJSQRYbJ8= Received: by 10.103.220.13 with SMTP id x13mr317252muq.110.1294918345039; Thu, 13 Jan 2011 03:32:25 -0800 (PST) Received: from riccoc20.at.omicron.at (vs162244.vserver.de [62.75.162.244]) by mx.google.com with ESMTPS id l3sm1591875fan.2.2011.01.13.03.32.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 13 Jan 2011 03:32:23 -0800 (PST) Date: Thu, 13 Jan 2011 12:32:20 +0100 From: Richard Cochran To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, netdev@vger.kernel.org, Alan Cox , Arnd Bergmann , Christoph Lameter , David Miller , John Stultz , Krzysztof Halasa , Peter Zijlstra , Rodolfo Giometti , Thomas Gleixner Subject: [PATCH V9 02/13] ntp: add ADJ_SETOFFSET mode bit Message-ID: <60566a54842bcf5974d55ed39f387c32ff9cf5cb.1294917348.git.richard.cochran@omicron.at> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Signed-off-by: Richard Cochran --- include/linux/timex.h | 3 ++- kernel/time/ntp.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/include/linux/timex.h b/include/linux/timex.h index 32d852f..800a2c8 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) */ @@ -102,6 +102,7 @@ struct timex { #define ADJ_STATUS 0x0010 /* clock status */ #define ADJ_TIMECONST 0x0020 /* pll time constant */ #define ADJ_TAI 0x0080 /* set TAI offset */ +#define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */ #define ADJ_MICRO 0x1000 /* select microsecond resolution */ #define ADJ_NANO 0x2000 /* select nanosecond resolution */ #define ADJ_TICK 0x4000 /* tick value */ diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index d232189..0c87858 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -482,6 +482,17 @@ int do_adjtimex(struct timex *txc) hrtimer_cancel(&leap_timer); } + if (txc->modes & ADJ_SETOFFSET) { + struct timespec delta; + if ((unsigned long)txc->time.tv_usec >= NSEC_PER_SEC) + return -EINVAL; + delta.tv_sec = txc->time.tv_sec; + delta.tv_nsec = txc->time.tv_usec; + if (!(txc->modes & ADJ_NANO)) + delta.tv_nsec *= 1000; + timekeeping_inject_offset(&delta); + } + getnstimeofday(&ts); write_seqlock_irq(&xtime_lock);