cpumask: avoid dereferencing struct cpumask
[safe/jmp/linux-2.6] / kernel / time / ntp.c
index aded09b..4800f93 100644 (file)
@@ -71,7 +71,8 @@ static long                   time_reftime;
 
 long                           time_adjust;
 
-static long                    ntp_tick_adj;
+/* constant (boot-param configurable) NTP tick adjustment (upscaled)   */
+static s64                     ntp_tick_adj;
 
 /*
  * NTP methods:
@@ -89,7 +90,7 @@ static void ntp_update_frequency(void)
        second_length            = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
                                                << NTP_SCALE_SHIFT;
 
-       second_length           += (s64)ntp_tick_adj << NTP_SCALE_SHIFT;
+       second_length           += ntp_tick_adj;
        second_length           += time_freq;
 
        tick_nsec                = div_u64(second_length, HZ) >> NTP_SCALE_SHIFT;
@@ -193,8 +194,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
        case TIME_OK:
                break;
        case TIME_INS:
-               xtime.tv_sec--;
-               wall_to_monotonic.tv_sec++;
+               timekeeping_leap_insert(-1);
                time_state = TIME_OOP;
                printk(KERN_NOTICE
                        "Clock: inserting leap second 23:59:60 UTC\n");
@@ -202,9 +202,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
                res = HRTIMER_RESTART;
                break;
        case TIME_DEL:
-               xtime.tv_sec++;
+               timekeeping_leap_insert(1);
                time_tai--;
-               wall_to_monotonic.tv_sec--;
                time_state = TIME_WAIT;
                printk(KERN_NOTICE
                        "Clock: deleting leap second 23:59:59 UTC\n");
@@ -218,7 +217,6 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
                        time_state = TIME_OK;
                break;
        }
-       update_vsyscall(&xtime, clock);
 
        write_sequnlock(&xtime_lock);
 
@@ -235,7 +233,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
  */
 void second_overflow(void)
 {
-       s64 time_adj;
+       s64 delta;
 
        /* Bump the maxerror field */
        time_maxerror += MAXFREQ / NSEC_PER_USEC;
@@ -248,10 +246,11 @@ 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;
+
+       delta            = shift_right(time_offset, SHIFT_PLL + time_constant);
+       time_offset     -= delta;
+       tick_length     += delta;
 
        if (!time_adjust)
                return;
@@ -332,20 +331,37 @@ static void notify_cmos_timer(void)
 static inline void notify_cmos_timer(void) { }
 #endif
 
+/*
+ * Start the leap seconds timer:
+ */
+static inline void ntp_start_leap_timer(struct timespec *ts)
+{
+       long now = ts->tv_sec;
+
+       if (time_status & STA_INS) {
+               time_state = TIME_INS;
+               now += 86400 - now % 86400;
+               hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+
+               return;
+       }
+
+       if (time_status & STA_DEL) {
+               time_state = TIME_DEL;
+               now += 86400 - (now + 1) % 86400;
+               hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
+       }
+}
 
 /*
  * Propagate a new txc->status value into the NTP state:
  */
 static inline void process_adj_status(struct timex *txc, struct timespec *ts)
 {
-       long now;
-
        if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
                time_state = TIME_OK;
                time_status = STA_UNSYNC;
        }
-       /* only set allowed bits */
-       time_status &= STA_RONLY;
 
        /*
         * If we turn on PLL adjustments then reset the
@@ -354,26 +370,18 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
        if (!(time_status & STA_PLL) && (txc->status & STA_PLL))
                time_reftime = xtime.tv_sec;
 
+       /* only set allowed bits */
+       time_status &= STA_RONLY;
        time_status |= txc->status & ~STA_RONLY;
 
        switch (time_state) {
        case TIME_OK:
-       start_timer:
-               now = ts->tv_sec;
-               if (time_status & STA_INS) {
-                       time_state = TIME_INS;
-                       now += 86400 - now % 86400;
-                       hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
-               } else if (time_status & STA_DEL) {
-                       time_state = TIME_DEL;
-                       now += 86400 - (now + 1) % 86400;
-                       hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
-               }
+               ntp_start_leap_timer(ts);
                break;
        case TIME_INS:
        case TIME_DEL:
                time_state = TIME_OK;
-               goto start_timer;
+               ntp_start_leap_timer(ts);
        case TIME_WAIT:
                if (!(time_status & (STA_INS | STA_DEL)))
                        time_state = TIME_OK;
@@ -394,17 +402,19 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 
        if (txc->modes & ADJ_NANO)
                time_status |= STA_NANO;
+
        if (txc->modes & ADJ_MICRO)
                time_status &= ~STA_NANO;
 
        if (txc->modes & ADJ_FREQUENCY) {
-               time_freq = (s64)txc->freq * PPM_SCALE;
+               time_freq = txc->freq * PPM_SCALE;
                time_freq = min(time_freq, MAXFREQ_SCALED);
                time_freq = max(time_freq, -MAXFREQ_SCALED);
        }
 
        if (txc->modes & ADJ_MAXERROR)
                time_maxerror = txc->maxerror;
+
        if (txc->modes & ADJ_ESTERROR)
                time_esterror = txc->esterror;
 
@@ -421,6 +431,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
 
        if (txc->modes & ADJ_OFFSET)
                ntp_update_offset(txc->offset);
+
        if (txc->modes & ADJ_TICK)
                tick_usec = txc->tick;
 
@@ -457,7 +468,7 @@ int do_adjtimex(struct timex *txc)
                if (txc->modes & ADJ_TICK &&
                    (txc->tick <  900000/USER_HZ ||
                     txc->tick > 1100000/USER_HZ))
-                               return -EINVAL;
+                       return -EINVAL;
 
                if (txc->modes & ADJ_STATUS && time_state != TIME_OK)
                        hrtimer_cancel(&leap_timer);
@@ -467,7 +478,6 @@ int do_adjtimex(struct timex *txc)
 
        write_seqlock_irq(&xtime_lock);
 
-       /* If there are input parameters, then process them */
        if (txc->modes & ADJ_ADJTIME) {
                long save_adjust = time_adjust;
 
@@ -477,25 +487,24 @@ int do_adjtimex(struct timex *txc)
                        ntp_update_frequency();
                }
                txc->offset = save_adjust;
-               goto adj_done;
-       }
+       } else {
 
-       /* If there are input parameters, then process them: */
-       if (txc->modes)
-               process_adjtimex_modes(txc, &ts);
+               /* If there are input parameters, then process them: */
+               if (txc->modes)
+                       process_adjtimex_modes(txc, &ts);
 
-       txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
+               txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
                                  NTP_SCALE_SHIFT);
-       if (!(time_status & STA_NANO))
-               txc->offset /= NSEC_PER_USEC;
+               if (!(time_status & STA_NANO))
+                       txc->offset /= NSEC_PER_USEC;
+       }
 
-adj_done:
        result = time_state;    /* mostly `TIME_OK' */
        if (time_status & (STA_UNSYNC|STA_CLOCKERR))
                result = TIME_ERROR;
 
        txc->freq          = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) *
-                                        (s64)PPM_SCALE_INV, NTP_SCALE_SHIFT);
+                                        PPM_SCALE_INV, NTP_SCALE_SHIFT);
        txc->maxerror      = time_maxerror;
        txc->esterror      = time_esterror;
        txc->status        = time_status;
@@ -514,6 +523,7 @@ adj_done:
        txc->calcnt        = 0;
        txc->errcnt        = 0;
        txc->stbcnt        = 0;
+
        write_sequnlock_irq(&xtime_lock);
 
        txc->time.tv_sec = ts.tv_sec;
@@ -529,6 +539,8 @@ adj_done:
 static int __init ntp_tick_adj_setup(char *str)
 {
        ntp_tick_adj = simple_strtol(str, NULL, 0);
+       ntp_tick_adj <<= NTP_SCALE_SHIFT;
+
        return 1;
 }