]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - kernel/time.c
[PATCH] lockdep: stacktrace subsystem, core
[linux-2.6.git] / kernel / time.c
index bbc8ca194b59ee3687a1ec4ced54a94e4cadbbde..5bd489747643c9e9dced9316cd372bba8f81a9e1 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <linux/module.h>
 #include <linux/timex.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/smp_lock.h>
 #include <linux/syscalls.h>
@@ -154,6 +155,9 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
        static int firsttime = 1;
        int error = 0;
 
+       if (tv && !timespec_valid(tv))
+               return -EINVAL;
+
        error = security_settime(tv, tz);
        if (error)
                return error;
@@ -198,24 +202,6 @@ asmlinkage long sys_settimeofday(struct timeval __user *tv,
        return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
-long pps_offset;               /* pps time offset (us) */
-long pps_jitter = MAXTIME;     /* time dispersion (jitter) (us) */
-
-long pps_freq;                 /* frequency offset (scaled ppm) */
-long pps_stabil = MAXFREQ;     /* frequency dispersion (scaled ppm) */
-
-long pps_valid = PPS_VALID;    /* pps signal watchdog counter */
-
-int pps_shift = PPS_SHIFT;     /* interval duration (s) (shift) */
-
-long pps_jitcnt;               /* jitter limit exceeded */
-long pps_calcnt;               /* calibration intervals */
-long pps_errcnt;               /* calibration errors */
-long pps_stbcnt;               /* stability limit exceeded */
-
-/* hook for a loadable hardpps kernel module */
-void (*hardpps_ptr)(struct timeval *);
-
 /* we call this to notify the arch when the clock is being
  * controlled.  If no such arch routine, do nothing.
  */
@@ -275,7 +261,7 @@ int do_adjtimex(struct timex *txc)
                    result = -EINVAL;
                    goto leave;
                }
-               time_freq = txc->freq - pps_freq;
+               time_freq = txc->freq;
            }
 
            if (txc->modes & ADJ_MAXERROR) {
@@ -308,10 +294,8 @@ int do_adjtimex(struct timex *txc)
                    if ((time_next_adjust = txc->offset) == 0)
                         time_adjust = 0;
                }
-               else if ( time_status & (STA_PLL | STA_PPSTIME) ) {
-                   ltemp = (time_status & (STA_PPSTIME | STA_PPSSIGNAL)) ==
-                           (STA_PPSTIME | STA_PPSSIGNAL) ?
-                           pps_offset : txc->offset;
+               else if (time_status & STA_PLL) {
+                   ltemp = txc->offset;
 
                    /*
                     * Scale the phase adjustment and
@@ -352,23 +336,14 @@ int do_adjtimex(struct timex *txc)
                    }
                    time_freq = min(time_freq, time_tolerance);
                    time_freq = max(time_freq, -time_tolerance);
-               } /* STA_PLL || STA_PPSTIME */
+               } /* STA_PLL */
            } /* txc->modes & ADJ_OFFSET */
            if (txc->modes & ADJ_TICK) {
                tick_usec = txc->tick;
                tick_nsec = TICK_USEC_TO_NSEC(tick_usec);
            }
        } /* txc->modes */
-leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0
-           || ((time_status & (STA_PPSFREQ|STA_PPSTIME)) != 0
-               && (time_status & STA_PPSSIGNAL) == 0)
-           /* p. 24, (b) */
-           || ((time_status & (STA_PPSTIME|STA_PPSJITTER))
-               == (STA_PPSTIME|STA_PPSJITTER))
-           /* p. 24, (c) */
-           || ((time_status & STA_PPSFREQ) != 0
-               && (time_status & (STA_PPSWANDER|STA_PPSERROR)) != 0))
-           /* p. 24, (d) */
+leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
                result = TIME_ERROR;
        
        if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT)
@@ -376,7 +351,7 @@ leave:      if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0
        else {
            txc->offset = shift_right(time_offset, SHIFT_UPDATE);
        }
-       txc->freq          = time_freq + pps_freq;
+       txc->freq          = time_freq;
        txc->maxerror      = time_maxerror;
        txc->esterror      = time_esterror;
        txc->status        = time_status;
@@ -384,14 +359,16 @@ leave:    if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0
        txc->precision     = time_precision;
        txc->tolerance     = time_tolerance;
        txc->tick          = tick_usec;
-       txc->ppsfreq       = pps_freq;
-       txc->jitter        = pps_jitter >> PPS_AVG;
-       txc->shift         = pps_shift;
-       txc->stabil        = pps_stabil;
-       txc->jitcnt        = pps_jitcnt;
-       txc->calcnt        = pps_calcnt;
-       txc->errcnt        = pps_errcnt;
-       txc->stbcnt        = pps_stbcnt;
+
+       /* PPS is not implemented, so these are zero */
+       txc->ppsfreq       = 0;
+       txc->jitter        = 0;
+       txc->shift         = 0;
+       txc->stabil        = 0;
+       txc->jitcnt        = 0;
+       txc->calcnt        = 0;
+       txc->errcnt        = 0;
+       txc->stbcnt        = 0;
        write_sequnlock_irq(&xtime_lock);
        do_gettimeofday(&txc->time);
        notify_arch_cmos_timer();
@@ -433,7 +410,7 @@ EXPORT_SYMBOL(current_kernel_time);
  * current_fs_time - Return FS time
  * @sb: Superblock.
  *
- * Return the current time truncated to the time granuality supported by
+ * Return the current time truncated to the time granularity supported by
  * the fs.
  */
 struct timespec current_fs_time(struct super_block *sb)
@@ -444,11 +421,11 @@ struct timespec current_fs_time(struct super_block *sb)
 EXPORT_SYMBOL(current_fs_time);
 
 /**
- * timespec_trunc - Truncate timespec to a granuality
+ * timespec_trunc - Truncate timespec to a granularity
  * @t: Timespec
- * @gran: Granuality in ns.
+ * @gran: Granularity in ns.
  *
- * Truncate a timespec to a granuality. gran must be smaller than a second.
+ * Truncate a timespec to a granularity. gran must be smaller than a second.
  * Always rounds down.
  *
  * This function should be only used for timestamps returned by
@@ -546,6 +523,7 @@ EXPORT_SYMBOL(do_gettimeofday);
 
 
 #else
+#ifndef CONFIG_GENERIC_TIME
 /*
  * Simulate gettimeofday using do_gettimeofday which only allows a timeval
  * and therefore only yields usec accuracy
@@ -560,28 +538,7 @@ void getnstimeofday(struct timespec *tv)
 }
 EXPORT_SYMBOL_GPL(getnstimeofday);
 #endif
-
-void getnstimestamp(struct timespec *ts)
-{
-       unsigned int seq;
-       struct timespec wall2mono;
-
-       /* synchronize with settimeofday() changes */
-       do {
-               seq = read_seqbegin(&xtime_lock);
-               getnstimeofday(ts);
-               wall2mono = wall_to_monotonic;
-       } while(unlikely(read_seqretry(&xtime_lock, seq)));
-
-       /* adjust to monotonicaly-increasing values */
-       ts->tv_sec += wall2mono.tv_sec;
-       ts->tv_nsec += wall2mono.tv_nsec;
-       while (unlikely(ts->tv_nsec >= NSEC_PER_SEC)) {
-               ts->tv_nsec -= NSEC_PER_SEC;
-               ts->tv_sec++;
-       }
-}
-EXPORT_SYMBOL_GPL(getnstimestamp);
+#endif
 
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
@@ -649,6 +606,43 @@ void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
        ts->tv_nsec = nsec;
 }
 
+/**
+ * ns_to_timespec - Convert nanoseconds to timespec
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timespec representation of the nsec parameter.
+ */
+struct timespec ns_to_timespec(const s64 nsec)
+{
+       struct timespec ts;
+
+       if (!nsec)
+               return (struct timespec) {0, 0};
+
+       ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec);
+       if (unlikely(nsec < 0))
+               set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec);
+
+       return ts;
+}
+
+/**
+ * ns_to_timeval - Convert nanoseconds to timeval
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timeval representation of the nsec parameter.
+ */
+struct timeval ns_to_timeval(const s64 nsec)
+{
+       struct timespec ts = ns_to_timespec(nsec);
+       struct timeval tv;
+
+       tv.tv_sec = ts.tv_sec;
+       tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000;
+
+       return tv;
+}
+
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void)
 {