[PATCH] SHPC: Fix SHPC Contoller SERR-INT Register bits access
[safe/jmp/linux-2.6] / kernel / hrtimer.c
index 59ec50c..01fa2ae 100644 (file)
@@ -266,7 +266,7 @@ ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
 /*
  * Divide a ktime value by a nanosecond value
  */
-static unsigned long ktime_divns(const ktime_t kt, nsec_t div)
+static unsigned long ktime_divns(const ktime_t kt, s64 div)
 {
        u64 dclc, inc, dns;
        int sft = 0;
@@ -322,7 +322,7 @@ hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
                interval.tv64 = timer->base->resolution.tv64;
 
        if (unlikely(delta.tv64 >= interval.tv64)) {
-               nsec_t incr = ktime_to_ns(interval);
+               s64 incr = ktime_to_ns(interval);
 
                orun = ktime_divns(delta, incr);
                timer->expires = ktime_add_ns(timer->expires, incr * orun);
@@ -374,8 +374,6 @@ static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
        rb_link_node(&timer->node, parent, link);
        rb_insert_color(&timer->node, &base->active);
 
-       timer->state = HRTIMER_PENDING;
-
        if (!base->first || timer->expires.tv64 <
            rb_entry(base->first, struct hrtimer, node)->expires.tv64)
                base->first = &timer->node;
@@ -395,6 +393,7 @@ static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
        if (base->first == &timer->node)
                base->first = rb_next(&timer->node);
        rb_erase(&timer->node, &base->active);
+       timer->node.rb_parent = HRTIMER_INACTIVE;
 }
 
 /*
@@ -405,7 +404,6 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
 {
        if (hrtimer_active(timer)) {
                __remove_hrtimer(timer, base);
-               timer->state = HRTIMER_INACTIVE;
                return 1;
        }
        return 0;
@@ -458,6 +456,7 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(hrtimer_start);
 
 /**
  * hrtimer_try_to_cancel - try to deactivate a timer
@@ -486,6 +485,7 @@ int hrtimer_try_to_cancel(struct hrtimer *timer)
        return ret;
 
 }
+EXPORT_SYMBOL_GPL(hrtimer_try_to_cancel);
 
 /**
  * hrtimer_cancel - cancel a timer and wait for the handler to finish.
@@ -503,8 +503,10 @@ int hrtimer_cancel(struct hrtimer *timer)
 
                if (ret >= 0)
                        return ret;
+               cpu_relax();
        }
 }
+EXPORT_SYMBOL_GPL(hrtimer_cancel);
 
 /**
  * hrtimer_get_remaining - get remaining time for the timer
@@ -523,6 +525,7 @@ ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
 
        return rem;
 }
+EXPORT_SYMBOL_GPL(hrtimer_get_remaining);
 
 #ifdef CONFIG_NO_IDLE_HZ
 /**
@@ -579,7 +582,9 @@ void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
                clock_id = CLOCK_MONOTONIC;
 
        timer->base = &bases[clock_id];
+       timer->node.rb_parent = HRTIMER_INACTIVE;
 }
+EXPORT_SYMBOL_GPL(hrtimer_init);
 
 /**
  * hrtimer_get_res - get the timer resolution for a clock
@@ -599,6 +604,7 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(hrtimer_get_res);
 
 /*
  * Expire the per base hrtimer-queue:
@@ -607,6 +613,9 @@ static inline void run_hrtimer_queue(struct hrtimer_base *base)
 {
        struct rb_node *node;
 
+       if (!base->first)
+               return;
+
        if (base->get_softirq_time)
                base->softirq_time = base->get_softirq_time();
 
@@ -614,31 +623,26 @@ static inline void run_hrtimer_queue(struct hrtimer_base *base)
 
        while ((node = base->first)) {
                struct hrtimer *timer;
-               int (*fn)(void *);
+               int (*fn)(struct hrtimer *);
                int restart;
-               void *data;
 
                timer = rb_entry(node, struct hrtimer, node);
                if (base->softirq_time.tv64 <= timer->expires.tv64)
                        break;
 
                fn = timer->function;
-               data = timer->data;
                set_curr_timer(base, timer);
-               timer->state = HRTIMER_INACTIVE;
                __remove_hrtimer(timer, base);
                spin_unlock_irq(&base->lock);
 
-               restart = fn(data);
+               restart = fn(timer);
 
                spin_lock_irq(&base->lock);
 
-               /* Another CPU has added back the timer */
-               if (timer->state != HRTIMER_INACTIVE)
-                       continue;
-
-               if (restart != HRTIMER_NORESTART)
+               if (restart != HRTIMER_NORESTART) {
+                       BUG_ON(hrtimer_active(timer));
                        enqueue_hrtimer(timer, base);
+               }
        }
        set_curr_timer(base, NULL);
        spin_unlock_irq(&base->lock);
@@ -661,29 +665,28 @@ void hrtimer_run_queues(void)
 /*
  * Sleep related functions:
  */
-
-struct sleep_hrtimer {
-       struct hrtimer timer;
-       struct task_struct *task;
-       int expired;
-};
-
-static int nanosleep_wakeup(void *data)
+static int hrtimer_wakeup(struct hrtimer *timer)
 {
-       struct sleep_hrtimer *t = data;
+       struct hrtimer_sleeper *t =
+               container_of(timer, struct hrtimer_sleeper, timer);
+       struct task_struct *task = t->task;
 
-       t->expired = 1;
-       wake_up_process(t->task);
+       t->task = NULL;
+       if (task)
+               wake_up_process(task);
 
        return HRTIMER_NORESTART;
 }
 
-static int __sched do_nanosleep(struct sleep_hrtimer *t, enum hrtimer_mode mode)
+void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, task_t *task)
 {
-       t->timer.function = nanosleep_wakeup;
-       t->timer.data = t;
-       t->task = current;
-       t->expired = 0;
+       sl->timer.function = hrtimer_wakeup;
+       sl->task = task;
+}
+
+static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
+{
+       hrtimer_init_sleeper(t, current);
 
        do {
                set_current_state(TASK_INTERRUPTIBLE);
@@ -691,18 +694,17 @@ static int __sched do_nanosleep(struct sleep_hrtimer *t, enum hrtimer_mode mode)
 
                schedule();
 
-               if (unlikely(!t->expired)) {
-                       hrtimer_cancel(&t->timer);
-                       mode = HRTIMER_ABS;
-               }
-       } while (!t->expired && !signal_pending(current));
+               hrtimer_cancel(&t->timer);
+               mode = HRTIMER_ABS;
+
+       } while (t->task && !signal_pending(current));
 
-       return t->expired;
+       return t->task == NULL;
 }
 
 static long __sched nanosleep_restart(struct restart_block *restart)
 {
-       struct sleep_hrtimer t;
+       struct hrtimer_sleeper t;
        struct timespec __user *rmtp;
        struct timespec tu;
        ktime_t time;
@@ -735,7 +737,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
                       const enum hrtimer_mode mode, const clockid_t clockid)
 {
        struct restart_block *restart;
-       struct sleep_hrtimer t;
+       struct hrtimer_sleeper t;
        struct timespec tu;
        ktime_t rem;
 
@@ -840,7 +842,7 @@ static void migrate_hrtimers(int cpu)
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
-static int __devinit hrtimer_cpu_notify(struct notifier_block *self,
+static int hrtimer_cpu_notify(struct notifier_block *self,
                                        unsigned long action, void *hcpu)
 {
        long cpu = (long)hcpu;
@@ -864,7 +866,7 @@ static int __devinit hrtimer_cpu_notify(struct notifier_block *self,
        return NOTIFY_OK;
 }
 
-static struct notifier_block __devinitdata hrtimers_nb = {
+static struct notifier_block hrtimers_nb = {
        .notifier_call = hrtimer_cpu_notify,
 };