public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Roman Zippel <zippel@linux-m68k.org>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 3/5] cleanups ntp.c (from Ingo)
Date: Fri, 14 Mar 2008 21:10:10 -0700	[thread overview]
Message-ID: <1205554210.6122.85.camel@localhost.localdomain> (raw)
In-Reply-To: <1205554018.6122.81.camel@localhost.localdomain>

Make this file more readable by applying a consistent coding style.

No code changed.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

Merged on top of Roman's very similar cleanups.
(In other words: Blame John for the merge screwups).

Signed-off-by: John Stultz <johnstul@us.ibm.com>


Index: linux-2.6/kernel/time/ntp.c
===================================================================
--- linux-2.6.orig/kernel/time/ntp.c	2008-03-14 19:21:02.000000000 -0700
+++ linux-2.6/kernel/time/ntp.c	2008-03-14 20:10:41.000000000 -0700
@@ -1,13 +1,10 @@
 /*
- * linux/kernel/time/ntp.c
- *
  * NTP state machine interfaces and logic.
  *
  * This code was mainly moved from kernel/timer.c and kernel/time.c
  * Please see those files for relevant copyright info and historical
  * changelogs.
  */
-
 #include <linux/mm.h>
 #include <linux/time.h>
 #include <linux/timer.h>
@@ -22,32 +19,35 @@
 /*
  * Timekeeping variables
  */
-unsigned long tick_usec = TICK_USEC; 		/* USER_HZ period (usec) */
-unsigned long tick_nsec;			/* ACTHZ period (nsec) */
-u64 tick_length;
-static u64 tick_length_base;
-
-static struct hrtimer leap_timer;
-
-#define MAX_TICKADJ		500		/* microsecs */
-#define MAX_TICKADJ_SCALED	(((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
-				  NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
+unsigned long		tick_usec = TICK_USEC;	/* USER_HZ period (usec) */
+unsigned long		tick_nsec;		/* ACTHZ period (nsec) */
+u64			tick_length;
+static u64		tick_length_base;
+static const long	max_tickadj = 500;	/* (usec) */
+
+static struct hrtimer	leap_timer;
 
 /*
  * phase-lock loop variables
  */
 /* TIME_ERROR prevents overwriting the CMOS clock */
-static int time_state = TIME_OK;	/* clock synchronization status	*/
-int time_status = STA_UNSYNC;		/* clock status bits		*/
-static long time_tai;			/* TAI offset (s)		*/
-static s64 time_offset;			/* time adjustment (ns)		*/
-static long time_constant = 2;		/* pll time constant		*/
-long time_maxerror = NTP_PHASE_LIMIT;	/* maximum error (us)		*/
-long time_esterror = NTP_PHASE_LIMIT;	/* estimated error (us)		*/
-static s64 time_freq;			/* frequency offset (scaled ns/s)*/
-static long time_reftime;		/* time at last adjustment (s)	*/
-long time_adjust;
-static long ntp_tick_adj;
+static int	time_state = TIME_OK;		/* clock synch status	 */
+int		time_status = STA_UNSYNC;	/* clock status bits	 */
+static long	time_tai;			/* TAI offset (s)	 */
+static s64	time_offset;			/* time adjustment (ns)	 */
+static long	time_constant = 2;		/* pll time constant	 */
+long		time_maxerror = NTP_PHASE_LIMIT;/* maximum error (us)	 */
+long		time_esterror = NTP_PHASE_LIMIT;/* estimated error (us)	 */
+static		s64 time_freq;		/* frequency offset (scaled ns/s)*/
+static long	time_reftime;		/* time at last adjustment (s)	 */
+long		time_adjust;
+static long	ntp_tick_adj;
+
+
+static inline u64 scale_tickadj(u64 adj)
+{
+	return ((adj * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ;
+}
 
 static void ntp_update_frequency(void)
 {
@@ -111,15 +111,15 @@ static void ntp_update_offset(long offse
  */
 void ntp_clear(void)
 {
-	time_adjust = 0;		/* stop active adjtime() */
-	time_status |= STA_UNSYNC;
-	time_maxerror = NTP_PHASE_LIMIT;
-	time_esterror = NTP_PHASE_LIMIT;
+	time_adjust	= 0;		/* stop active adjtime() */
+	time_status	|= STA_UNSYNC;
+	time_maxerror	= NTP_PHASE_LIMIT;
+	time_esterror	= NTP_PHASE_LIMIT;
 
 	ntp_update_frequency();
 
-	tick_length = tick_length_base;
-	time_offset = 0;
+	tick_length	= tick_length_base;
+	time_offset	= 0;
 }
 
 /*
@@ -136,28 +136,32 @@ static enum hrtimer_restart ntp_leap_sec
 	switch (time_state) {
 	case TIME_OK:
 		break;
+
 	case TIME_INS:
 		xtime.tv_sec--;
 		wall_to_monotonic.tv_sec++;
 		time_state = TIME_OOP;
-		printk(KERN_NOTICE "Clock: "
-		       "inserting leap second 23:59:60 UTC\n");
+		printk(KERN_NOTICE
+			 "Clock: inserting leap second 23:59:60 UTC\n");
 		leap_timer.expires = ktime_add_ns(leap_timer.expires,
 						  NSEC_PER_SEC);
 		res = HRTIMER_RESTART;
 		break;
+
 	case TIME_DEL:
 		xtime.tv_sec++;
 		time_tai--;
 		wall_to_monotonic.tv_sec--;
 		time_state = TIME_WAIT;
-		printk(KERN_NOTICE "Clock: "
-		       "deleting leap second 23:59:59 UTC\n");
+		printk(KERN_NOTICE
+			"Clock: deleting leap second 23:59:59 UTC\n");
 		break;
+
 	case TIME_OOP:
 		time_tai++;
 		time_state = TIME_WAIT;
 		/* fall through */
+
 	case TIME_WAIT:
 		if (!(time_status & (STA_INS | STA_DEL)))
 			time_state = TIME_OK;
@@ -193,21 +197,20 @@ void second_overflow(void)
 	 * Compute the phase adjustment for the next second. The offset is
 	 * reduced by a fixed factor times the time constant.
 	 */
-	tick_length = tick_length_base;
-	time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
-	time_offset -= time_adj;
-	tick_length += time_adj;
+	tick_length	= tick_length_base;
+	time_adj	= shift_right(time_offset, SHIFT_PLL + time_constant);
+	time_offset	-= time_adj;
+	tick_length	+= time_adj;
 
 	if (unlikely(time_adjust)) {
-		if (time_adjust > MAX_TICKADJ) {
-			time_adjust -= MAX_TICKADJ;
-			tick_length += MAX_TICKADJ_SCALED;
-		} else if (time_adjust < -MAX_TICKADJ) {
-			time_adjust += MAX_TICKADJ;
-			tick_length -= MAX_TICKADJ_SCALED;
+		if (time_adjust > max_tickadj) {
+			time_adjust -= max_tickadj;
+			tick_length += scale_tickadj(max_tickadj);
+		} else if (time_adjust < -max_tickadj) {
+			time_adjust += max_tickadj;
+			tick_length -= scale_tickadj(max_tickadj);
 		} else {
-			tick_length += (s64)(time_adjust * NSEC_PER_USEC /
-					NTP_INTERVAL_FREQ) << NTP_SCALE_SHIFT;
+			tick_length += scale_tickadj(time_adjust);
 			time_adjust = 0;
 		}
 	}
@@ -216,13 +219,13 @@ void second_overflow(void)
 #ifdef CONFIG_GENERIC_CMOS_UPDATE
 
 /* Disable the cmos update - used by virtualization and embedded */
-int no_sync_cmos_clock  __read_mostly;
+int no_sync_cmos_clock __read_mostly;
 
-static void sync_cmos_clock(unsigned long dummy);
+static void sync_cmos_clock(unsigned long unused);
 
 static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
 
-static void sync_cmos_clock(unsigned long dummy)
+static void sync_cmos_clock(unsigned long unused)
 {
 	struct timespec now, next;
 	int fail = 1;
@@ -234,12 +237,13 @@ static void sync_cmos_clock(unsigned lon
 	 * This code is run on a timer.  If the clock is set, that timer
 	 * may not expire at the correct time.  Thus, we adjust...
 	 */
-	if (!ntp_synced())
+	if (!ntp_synced()) {
 		/*
 		 * Not synced, exit, do not restart a timer (if one is
 		 * running, let it run out).
 		 */
 		return;
+	}
 
 	getnstimeofday(&now);
 	if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2)
@@ -271,7 +275,8 @@ static void notify_cmos_timer(void)
 static inline void notify_cmos_timer(void) { }
 #endif
 
-/* adjtimex mainly allows reading (and writing, if superuser) of
+/*
+ * adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
 int do_adjtimex(struct timex *txc)
@@ -293,10 +298,11 @@ int do_adjtimex(struct timex *txc)
 	}
 
 	/* if the quartz is off by more than 10% something is VERY wrong ! */
-	if (txc->modes & ADJ_TICK)
+	if (txc->modes & ADJ_TICK) {
 		if (txc->tick <  900000/USER_HZ ||
 		    txc->tick > 1100000/USER_HZ)
 			return -EINVAL;
+	}
 
 	if (time_state != TIME_OK && txc->modes & ADJ_STATUS)
 		hrtimer_cancel(&leap_timer);



  reply	other threads:[~2008-03-15  4:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-15  4:04 [PATCH 0/5] time/ntp changes john stultz
2008-03-15  4:05 ` [PATCH 1/5] split clocksource adjustment from clockosurce mult john stultz
2008-03-15  4:06   ` [PATCH 2/5] introduce CLOCK_MONOTONIC_RAW john stultz
2008-03-15  4:10     ` john stultz [this message]
2008-03-15  4:12       ` [PATCH 4/5] ntp.c code flow clenaups (from Ingo) john stultz
2008-03-15  4:15         ` [PATCH 5/5] make more ntp values static john stultz
2008-03-15  5:09           ` Roman Zippel
2008-03-15  4:52         ` [PATCH 4/5] ntp.c code flow clenaups (from Ingo) Roman Zippel
2008-03-15  5:04           ` John Stultz
2008-03-15 12:39         ` Ingo Oeser
2008-03-15 17:24           ` Roman Zippel
2008-03-15  5:06       ` [PATCH 3/5] cleanups ntp.c " Roman Zippel
2008-03-15  9:32       ` Jörg-Volker Peetz
2008-03-15 17:23         ` Roman Zippel
2008-03-15  4:50     ` [PATCH 2/5] introduce CLOCK_MONOTONIC_RAW Roman Zippel
2008-03-18  2:03       ` john stultz
2008-03-18  2:27         ` john stultz
2008-03-26  3:41         ` Roman Zippel
2008-03-15  4:28   ` [PATCH 1/5] split clocksource adjustment from clockosurce mult Roman Zippel
2008-03-15  5:07     ` John Stultz

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=1205554210.6122.85.camel@localhost.localdomain \
    --to=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=zippel@linux-m68k.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