mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: George Anzinger <george@mvista.com>,
	frank@tuxrocks.com, Anton Blanchard <anton@samba.org>,
	benh@kernel.crashing.org, Nishanth Aravamudan <nacc@us.ibm.com>,
	Roman Zippel <zippel@linux-m68k.org>
Subject: [RFC][PATCH - 10/12] NTP cleanup: Use ntp_lock instead of xtime_lock
Date: Fri, 15 Jul 2005 20:06:42 -0700	[thread overview]
Message-ID: <1121483202.28638.6.camel@cog.beaverton.ibm.com> (raw)
In-Reply-To: <1121483160.28638.4.camel@cog.beaverton.ibm.com>

All,
	This patch introduces the ntp_lock which replaces the xtime_lock for
serialization in the NTP subsystem. This further isolates the NTP
subsystem from the time subsystem.

Any comments or feedback would be greatly appreciated.

thanks
-john

linux-2.6.13-rc3_timeofday-ntp-part10_B4.patch
============================================
diff --git a/kernel/ntp.c b/kernel/ntp.c
--- a/kernel/ntp.c
+++ b/kernel/ntp.c
@@ -69,6 +69,8 @@ static int ntp_state    = TIME_OK;      
 long ntp_adjtime_offset;
 static long ntp_next_adjtime_offset;
 
+/* lock for the above variables */
+static seqlock_t ntp_lock = SEQLOCK_UNLOCKED;
 
 #define SEC_PER_DAY 86400
 
@@ -79,7 +81,9 @@ int ntp_advance(unsigned long interval_n
 {
 	static unsigned long interval_sum = 0;
 	long time_adjust_step, delta_nsec;
+	unsigned long flags;
 
+	write_seqlock_irqsave(&ntp_lock, flags);
 
 	/* Some components of the NTP state machine are advanced
 	 * in full second increments (this is a hold-over from
@@ -178,6 +182,7 @@ int ntp_advance(unsigned long interval_n
 		ntp_adjtime_offset = ntp_next_adjtime_offset;
 		ntp_next_adjtime_offset = 0;
 	}
+	write_sequnlock_irqrestore(&ntp_lock, flags);
 
 	return delta_nsec;
 }
@@ -187,13 +192,13 @@ int ntp_advance(unsigned long interval_n
  * offset: current offset
  * tv: timeval holding the current time
  *
- * Private function, called only by ntp_adjtimex
+ * Private function, called only by ntp_adjtimex while holding ntp_lock
  *
  * This function is called when an offset adjustment is requested.
  * It calculates the offset adjustment and manipulates the
  * frequency adjustement accordingly.
  */
-static int ntp_hardupdate(long offset, struct timespec tv)
+static int ntp_hardupdate(long offset, struct timeval tv)
 {
 	int ret;
 	long current_offset, interval;
@@ -256,6 +261,7 @@ int ntp_adjtimex(struct timex *txc)
 {
 	long save_adjust;
 	int result;
+	unsigned long flags;
 
 	/* Now we validate the data before disabling interrupts */
 
@@ -298,7 +304,8 @@ int ntp_adjtimex(struct timex *txc)
 				||(txc->tick > 11000000/USER_HZ)))
 		return -EINVAL;
 
-	write_seqlock_irq(&xtime_lock);
+	write_seqlock_irqsave(&ntp_lock, flags);
+
 	result = ntp_state;       /* mostly `TIME_OK' */
 
 	/* Save for later - semantics of adjtime is to return old value */
@@ -327,7 +334,7 @@ int ntp_adjtimex(struct timex *txc)
 			/* adjtime() is independent from ntp_adjtime() */
 			if ((ntp_next_adjtime_offset = txc->offset) == 0)
 				ntp_adjtime_offset = 0;
-		} else if (ntp_hardupdate(txc->offset, xtime))
+		} else if (ntp_hardupdate(txc->offset, txc->time))
 			result = TIME_ERROR;
 	}
 
@@ -364,8 +371,8 @@ int ntp_adjtimex(struct timex *txc)
 	txc->errcnt = 0;
 	txc->stbcnt = 0;
 
-	write_sequnlock_irq(&xtime_lock);
-	do_gettimeofday(&txc->time);
+	write_sequnlock_irqrestore(&ntp_lock, flags);
+
 	return result;
 }
 
@@ -387,6 +394,8 @@ int ntp_leapsecond(struct timespec now)
 	 * set ahead one second.
 	 */
 	static time_t leaptime = 0;
+	unsigned long flags;
+	write_seqlock_irqsave(&ntp_lock, flags);
 
 	switch (ntp_state) {
 	case TIME_OK:
@@ -429,6 +438,7 @@ int ntp_leapsecond(struct timespec now)
 			ntp_state = TIME_OK;
 	}
 
+	write_sequnlock_irqrestore(&ntp_lock, flags);
 	return 0;
 }
 
@@ -436,14 +446,18 @@ int ntp_leapsecond(struct timespec now)
 /**
  * ntp_clear - Clears the NTP state machine.
  *
- * Must be called while holding a write on the xtime_lock
  */
 void ntp_clear(void)
 {
+	unsigned long flags;
+	write_seqlock_irqsave(&ntp_lock, flags);
+
 	ntp_next_adjtime_offset = 0;		/* stop active adjtime() */
 	ntp_status |= STA_UNSYNC;
 	ntp_maxerror = NTP_PHASE_LIMIT;
 	ntp_esterror = NTP_PHASE_LIMIT;
+
+	write_sequnlock_irqrestore(&ntp_lock, flags);
 }
 
 /**
diff --git a/kernel/time.c b/kernel/time.c
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -222,6 +222,11 @@ int do_adjtimex(struct timex *txc)
 	if (txc->modes && !capable(CAP_SYS_TIME))
 		return -EPERM;
 		
+	/* Note: We set tx->time first,
+	 * because ntp_adjtimex uses it
+	 */
+	do_gettimeofday(&txc->time);
+
 	result = ntp_adjtimex(txc);
 	
 	notify_arch_cmos_timer();



  reply	other threads:[~2005-07-16  3:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-16  2:55 [RFC - 0/12] NTP cleanup work (v. B4) john stultz
2005-07-16  2:57 ` [RFC][PATCH - 1/12] NTP cleanup: Move NTP code into ntp.c john stultz
2005-07-16  2:57   ` [RFC][PATCH - 2/12] NTP cleanup: Move arches to new ntp interfaces john stultz
2005-07-16  2:58     ` [RFC][PATCH - 3/12] NTP cleanup: Remove unused NTP PPS code john stultz
2005-07-16  2:59       ` [RFC][PATCH - 4/12] NTP cleanup: Breakup ntp_adjtimex() john stultz
2005-07-16  3:00         ` [RFC][PATCH - 5/12] NTP cleanup: Break out leapsecond processing john stultz
2005-07-16  3:02           ` [RFC][PATCH - 6/12] NTP cleanup: Clean up ntp_adjtimex() arguement checking john stultz
2005-07-16  3:04             ` [RFC][PATCH - 7/12] NTP cleanup: Cleanup signed shifting logic john stultz
2005-07-16  3:05               ` [RFC][PATCH - 8/12] NTP cleanup: Integrate second_overflow() logic john stultz
2005-07-16  3:06                 ` [RFC][PATCH - 9/12] NTP cleanup: Improve NTP variable names john stultz
2005-07-16  3:06                   ` john stultz [this message]
2005-07-16  3:07                     ` [RFC][PATCH - 11/12] NTP cleanup: Introduce PPM adjustment variables john stultz
2005-07-16  3:09                       ` [RFC][PATCH - 12/12] NTP cleanup: use ppm instead of unit adj returned by ntp_advance john stultz
2005-07-18 11:42   ` [RFC][PATCH - 1/12] NTP cleanup: Move NTP code into ntp.c Pavel Machek
2005-07-20 20:44     ` john stultz
2005-07-17 18:00 ` [RFC - 0/12] NTP cleanup work (v. B4) Roman Zippel
2005-07-20 16:26   ` john stultz
2005-07-21 10:39     ` Roman Zippel
2005-07-26  1:03       ` 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=1121483202.28638.6.camel@cog.beaverton.ibm.com \
    --to=johnstul@us.ibm.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=frank@tuxrocks.com \
    --cc=george@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nacc@us.ibm.com \
    --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

all inboxes | Powered by JetHome®