]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/hrtimer.c
[PATCH] autofs4 oops fix
[linux-2.6-omap-h63xx.git] / kernel / hrtimer.c
index 64d37a3c594848699d515008cfcf1f50feb4726d..04ccab099e84e3ce01125a540e02f49d216f5943 100644 (file)
@@ -108,6 +108,7 @@ void ktime_get_ts(struct timespec *ts)
        set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
                                ts->tv_nsec + tomono.tv_nsec);
 }
+EXPORT_SYMBOL_GPL(ktime_get_ts);
 
 /*
  * Functions and macros which are different for UP/SMP systems are kept in a
@@ -274,7 +275,7 @@ void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
  * The number of overruns is added to the overrun field.
  */
 unsigned long
-hrtimer_forward(struct hrtimer *timer, const ktime_t interval)
+hrtimer_forward(struct hrtimer *timer, ktime_t interval)
 {
        unsigned long orun = 1;
        ktime_t delta, now;
@@ -286,6 +287,9 @@ hrtimer_forward(struct hrtimer *timer, const ktime_t interval)
        if (delta.tv64 < 0)
                return 0;
 
+       if (interval.tv64 < timer->base->resolution.tv64)
+               interval.tv64 = timer->base->resolution.tv64;
+
        if (unlikely(delta.tv64 >= interval.tv64)) {
                nsec_t incr = ktime_to_ns(interval);
 
@@ -313,7 +317,6 @@ hrtimer_forward(struct hrtimer *timer, const ktime_t interval)
 static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
 {
        struct rb_node **link = &base->active.rb_node;
-       struct list_head *prev = &base->pending;
        struct rb_node *parent = NULL;
        struct hrtimer *entry;
 
@@ -329,22 +332,23 @@ static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
                 */
                if (timer->expires.tv64 < entry->expires.tv64)
                        link = &(*link)->rb_left;
-               else {
+               else
                        link = &(*link)->rb_right;
-                       prev = &entry->list;
-               }
        }
 
        /*
-        * Insert the timer to the rbtree and to the sorted list:
+        * Insert the timer to the rbtree and check whether it
+        * replaces the first pending timer
         */
        rb_link_node(&timer->node, parent, link);
        rb_insert_color(&timer->node, &base->active);
-       list_add(&timer->list, prev);
 
        timer->state = HRTIMER_PENDING;
-}
 
+       if (!base->first || timer->expires.tv64 <
+           rb_entry(base->first, struct hrtimer, node)->expires.tv64)
+               base->first = &timer->node;
+}
 
 /*
  * __remove_hrtimer - internal function to remove a timer
@@ -354,9 +358,11 @@ static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
 static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
 {
        /*
-        * Remove the timer from the sorted list and from the rbtree:
+        * Remove the timer from the rbtree and replace the
+        * first entry pointer if necessary.
         */
-       list_del(&timer->list);
+       if (base->first == &timer->node)
+               base->first = rb_next(&timer->node);
        rb_erase(&timer->node, &base->active);
 }
 
@@ -515,9 +521,8 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
 {
        struct hrtimer_base *bases;
 
-       tp->tv_sec = 0;
        bases = per_cpu(hrtimer_bases, raw_smp_processor_id());
-       tp->tv_nsec = bases[which_clock].resolution;
+       *tp = ktime_to_timespec(bases[which_clock].resolution);
 
        return 0;
 }
@@ -528,16 +533,17 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
 static inline void run_hrtimer_queue(struct hrtimer_base *base)
 {
        ktime_t now = base->get_time();
+       struct rb_node *node;
 
        spin_lock_irq(&base->lock);
 
-       while (!list_empty(&base->pending)) {
+       while ((node = base->first)) {
                struct hrtimer *timer;
                int (*fn)(void *);
                int restart;
                void *data;
 
-               timer = list_entry(base->pending.next, struct hrtimer, list);
+               timer = rb_entry(node, struct hrtimer, node);
                if (now.tv64 <= timer->expires.tv64)
                        break;
 
@@ -707,6 +713,20 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
        return -ERESTART_RESTARTBLOCK;
 }
 
+asmlinkage long
+sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
+{
+       struct timespec tu;
+
+       if (copy_from_user(&tu, rqtp, sizeof(tu)))
+               return -EFAULT;
+
+       if (!timespec_valid(&tu))
+               return -EINVAL;
+
+       return hrtimer_nanosleep(&tu, rmtp, HRTIMER_REL, CLOCK_MONOTONIC);
+}
+
 /*
  * Functions related to boot-time initialization:
  */
@@ -717,7 +737,6 @@ static void __devinit init_hrtimers_cpu(int cpu)
 
        for (i = 0; i < MAX_HRTIMER_BASES; i++) {
                spin_lock_init(&base->lock);
-               INIT_LIST_HEAD(&base->pending);
                base++;
        }
 }