]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - kernel/posix-timers.c
Merge branches 'timers/clocksource', 'timers/hpet', 'timers/hrtimers', 'timers/nohz...
[mv-sheeva.git] / kernel / posix-timers.c
index b931d7cedbfa9fd70a47d07535d3b791661ec39a..887c63787de6634b9d46ddcdbb386d5d3ffe5250 100644 (file)
@@ -116,7 +116,7 @@ static DEFINE_SPINLOCK(idr_lock);
  *         must supply functions here, even if the function just returns
  *         ENOSYS.  The standard POSIX timer management code assumes the
  *         following: 1.) The k_itimer struct (sched.h) is used for the
- *         timer.  2.) The list, it_lock, it_clock, it_id and it_process
+ *         timer.  2.) The list, it_lock, it_clock, it_id and it_pid
  *         fields are not modified by timer code.
  *
  *          At this time all functions EXCEPT clock_nanosleep can be
@@ -197,6 +197,11 @@ static int common_timer_create(struct k_itimer *new_timer)
        return 0;
 }
 
+static int no_timer_create(struct k_itimer *new_timer)
+{
+       return -EOPNOTSUPP;
+}
+
 /*
  * Return nonzero if we know a priori this clockid_t value is bogus.
  */
@@ -248,6 +253,7 @@ static __init int init_posix_timers(void)
                .clock_getres = hrtimer_get_res,
                .clock_get = posix_get_monotonic_raw,
                .clock_set = do_posix_clock_nosettime,
+               .timer_create = no_timer_create,
        };
 
        register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -313,7 +319,8 @@ void do_schedule_next_timer(struct siginfo *info)
 
 int posix_timer_event(struct k_itimer *timr, int si_private)
 {
-       int shared, ret;
+       struct task_struct *task;
+       int shared, ret = -1;
        /*
         * FIXME: if ->sigq is queued we can race with
         * dequeue_signal()->do_schedule_next_timer().
@@ -327,8 +334,13 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
         */
        timr->sigq->info.si_sys_private = si_private;
 
-       shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
-       ret = send_sigqueue(timr->sigq, timr->it_process, shared);
+       rcu_read_lock();
+       task = pid_task(timr->it_pid, PIDTYPE_PID);
+       if (task) {
+               shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
+               ret = send_sigqueue(timr->sigq, task, shared);
+       }
+       rcu_read_unlock();
        /* If we failed to send the signal the timer stops. */
        return ret > 0;
 }
@@ -405,7 +417,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
        return ret;
 }
 
-static struct task_struct * good_sigevent(sigevent_t * event)
+static struct pid *good_sigevent(sigevent_t * event)
 {
        struct task_struct *rtn = current->group_leader;
 
@@ -419,7 +431,7 @@ static struct task_struct * good_sigevent(sigevent_t * event)
            ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
                return NULL;
 
-       return rtn;
+       return task_pid(rtn);
 }
 
 void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
@@ -458,6 +470,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
                idr_remove(&posix_timers_id, tmr->it_id);
                spin_unlock_irqrestore(&idr_lock, flags);
        }
+       put_pid(tmr->it_pid);
        sigqueue_free(tmr->sigq);
        kmem_cache_free(posix_timers_cache, tmr);
 }
@@ -471,7 +484,6 @@ sys_timer_create(const clockid_t which_clock,
 {
        struct k_itimer *new_timer;
        int error, new_timer_id;
-       struct task_struct *process;
        sigevent_t event;
        int it_id_set = IT_ID_NOT_SET;
 
@@ -525,11 +537,9 @@ sys_timer_create(const clockid_t which_clock,
                        goto out;
                }
                rcu_read_lock();
-               process = good_sigevent(&event);
-               if (process)
-                       get_task_struct(process);
+               new_timer->it_pid = get_pid(good_sigevent(&event));
                rcu_read_unlock();
-               if (!process) {
+               if (!new_timer->it_pid) {
                        error = -EINVAL;
                        goto out;
                }
@@ -537,8 +547,7 @@ sys_timer_create(const clockid_t which_clock,
                event.sigev_notify = SIGEV_SIGNAL;
                event.sigev_signo = SIGALRM;
                event.sigev_value.sival_int = new_timer->it_id;
-               process = current->group_leader;
-               get_task_struct(process);
+               new_timer->it_pid = get_pid(task_tgid(current));
        }
 
        new_timer->it_sigev_notify     = event.sigev_notify;
@@ -548,7 +557,7 @@ sys_timer_create(const clockid_t which_clock,
        new_timer->sigq->info.si_code  = SI_TIMER;
 
        spin_lock_irq(&current->sighand->siglock);
-       new_timer->it_process = process;
+       new_timer->it_signal = current->signal;
        list_add(&new_timer->list, &current->signal->posix_timers);
        spin_unlock_irq(&current->sighand->siglock);
 
@@ -583,8 +592,7 @@ static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags)
        timr = idr_find(&posix_timers_id, (int)timer_id);
        if (timr) {
                spin_lock(&timr->it_lock);
-               if (timr->it_process &&
-                   same_thread_group(timr->it_process, current)) {
+               if (timr->it_signal == current->signal) {
                        spin_unlock(&idr_lock);
                        return timr;
                }
@@ -639,7 +647,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
            (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
                timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv);
 
-       remaining = ktime_sub(timer->expires, now);
+       remaining = ktime_sub(hrtimer_get_expires(timer), now);
        /* Return 0 only, when the timer is expired and not pending */
        if (remaining.tv64 <= 0) {
                /*
@@ -733,7 +741,7 @@ common_timer_set(struct k_itimer *timr, int flags,
        hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
        timr->it.real.timer.function = posix_timer_fn;
 
-       timer->expires = timespec_to_ktime(new_setting->it_value);
+       hrtimer_set_expires(timer, timespec_to_ktime(new_setting->it_value));
 
        /* Convert interval */
        timr->it.real.interval = timespec_to_ktime(new_setting->it_interval);
@@ -742,14 +750,12 @@ common_timer_set(struct k_itimer *timr, int flags,
        if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) {
                /* Setup correct expiry time for relative timers */
                if (mode == HRTIMER_MODE_REL) {
-                       timer->expires =
-                               ktime_add_safe(timer->expires,
-                                              timer->base->get_time());
+                       hrtimer_add_expires(timer, timer->base->get_time());
                }
                return 0;
        }
 
-       hrtimer_start(timer, timer->expires, mode);
+       hrtimer_start_expires(timer, mode);
        return 0;
 }
 
@@ -833,8 +839,7 @@ retry_delete:
         * This keeps any tasks waiting on the spin lock from thinking
         * they got something (see the lock code above).
         */
-       put_task_struct(timer->it_process);
-       timer->it_process = NULL;
+       timer->it_signal = NULL;
 
        unlock_timer(timer, flags);
        release_posix_timer(timer, IT_ID_SET);
@@ -860,8 +865,7 @@ retry_delete:
         * This keeps any tasks waiting on the spin lock from thinking
         * they got something (see the lock code above).
         */
-       put_task_struct(timer->it_process);
-       timer->it_process = NULL;
+       timer->it_signal = NULL;
 
        unlock_timer(timer, flags);
        release_posix_timer(timer, IT_ID_SET);