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-rc6_timeofday-ntp-part10_B5.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;
 
 static long fixed_tick_ns_adj;
 
@@ -78,7 +80,9 @@ void ntp_advance(unsigned long interval_
 {
        static unsigned long interval_sum = 0;
        long time_adjust_step;
+       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
@@ -177,6 +181,8 @@ void ntp_advance(unsigned long interval_
                ntp_adjtime_offset = ntp_next_adjtime_offset;
                ntp_next_adjtime_offset = 0;
        }
+
+       write_sequnlock_irqrestore(&ntp_lock, flags);
 }
 
 /**
@@ -184,13 +190,13 @@ void ntp_advance(unsigned long interval_
  * 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;
@@ -253,6 +259,7 @@ int ntp_adjtimex(struct timex *txc)
 {
        long save_adjust;
        int result;
+       unsigned long flags;
 
        /* Now we validate the data before disabling interrupts */
 
@@ -295,7 +302,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 */
@@ -324,7 +332,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;
        }
 
@@ -361,8 +369,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;
 }
 
@@ -384,6 +392,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:
@@ -426,6 +436,7 @@ int ntp_leapsecond(struct timespec now)
                        ntp_state = TIME_OK;
        }
 
+       write_sequnlock_irqrestore(&ntp_lock, flags);
        return 0;
 }
 
@@ -433,14 +444,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();


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to