Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / arch / ia64 / kernel / time.c
index d2f4e26..f638821 100644 (file)
@@ -83,32 +83,36 @@ static struct clocksource *itc_clocksource;
 
 extern cputime_t cycle_to_cputime(u64 cyc);
 
+static void vtime_account_user(struct task_struct *tsk)
+{
+       cputime_t delta_utime;
+       struct thread_info *ti = task_thread_info(tsk);
+
+       if (ti->ac_utime) {
+               delta_utime = cycle_to_cputime(ti->ac_utime);
+               account_user_time(tsk, delta_utime, delta_utime);
+               ti->ac_utime = 0;
+       }
+}
+
 /*
  * Called from the context switch with interrupts disabled, to charge all
  * accumulated times to the current process, and to prepare accounting on
  * the next process.
  */
-void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
+void vtime_task_switch(struct task_struct *prev)
 {
        struct thread_info *pi = task_thread_info(prev);
-       struct thread_info *ni = task_thread_info(next);
-       cputime_t delta_stime, delta_utime;
-       __u64 now;
+       struct thread_info *ni = task_thread_info(current);
 
-       now = ia64_get_itc();
-
-       delta_stime = cycle_to_cputime(pi->ac_stime + (now - pi->ac_stamp));
        if (idle_task(smp_processor_id()) != prev)
-               account_system_time(prev, 0, delta_stime, delta_stime);
+               vtime_account_system(prev);
        else
-               account_idle_time(delta_stime);
+               vtime_account_idle(prev);
 
-       if (pi->ac_utime) {
-               delta_utime = cycle_to_cputime(pi->ac_utime);
-               account_user_time(prev, delta_utime, delta_utime);
-       }
+       vtime_account_user(prev);
 
-       pi->ac_stamp = ni->ac_stamp = now;
+       pi->ac_stamp = ni->ac_stamp;
        ni->ac_stime = ni->ac_utime = 0;
 }
 
@@ -116,29 +120,32 @@ void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
  * Account time for a transition between system, hard irq or soft irq state.
  * Note that this function is called with interrupts enabled.
  */
-void account_system_vtime(struct task_struct *tsk)
+static cputime_t vtime_delta(struct task_struct *tsk)
 {
        struct thread_info *ti = task_thread_info(tsk);
-       unsigned long flags;
        cputime_t delta_stime;
        __u64 now;
 
-       local_irq_save(flags);
-
        now = ia64_get_itc();
 
        delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp));
-       if (irq_count() || idle_task(smp_processor_id()) != tsk)
-               account_system_time(tsk, 0, delta_stime, delta_stime);
-       else
-               account_idle_time(delta_stime);
        ti->ac_stime = 0;
-
        ti->ac_stamp = now;
 
-       local_irq_restore(flags);
+       return delta_stime;
+}
+
+void vtime_account_system(struct task_struct *tsk)
+{
+       cputime_t delta = vtime_delta(tsk);
+
+       account_system_time(tsk, 0, delta, delta);
+}
+
+void vtime_account_idle(struct task_struct *tsk)
+{
+       account_idle_time(vtime_delta(tsk));
 }
-EXPORT_SYMBOL_GPL(account_system_vtime);
 
 /*
  * Called from the timer interrupt handler to charge accumulated user time
@@ -146,14 +153,7 @@ EXPORT_SYMBOL_GPL(account_system_vtime);
  */
 void account_process_tick(struct task_struct *p, int user_tick)
 {
-       struct thread_info *ti = task_thread_info(p);
-       cputime_t delta_utime;
-
-       if (ti->ac_utime) {
-               delta_utime = cycle_to_cputime(ti->ac_utime);
-               account_user_time(p, delta_utime, delta_utime);
-               ti->ac_utime = 0;
-       }
+       vtime_account_user(p);
 }
 
 #endif /* CONFIG_VIRT_CPU_ACCOUNTING */