Skip to content

Commit

Permalink
sched/cputime: Fix cpu_timer_sample_group() double accounting
Browse files Browse the repository at this point in the history
While looking over the cpu-timer code I found that we appear to add
the delta for the calling task twice, through:

  cpu_timer_sample_group()
    thread_group_cputimer()
      thread_group_cputime()
        times->sum_exec_runtime += task_sched_runtime();

    *sample = cputime.sum_exec_runtime + task_delta_exec();

Which would make the sample run ahead, making the sleep short.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/20141112113737.GI10476@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Nov 16, 2014
1 parent 7af6833 commit 23cfa36
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
5 changes: 0 additions & 5 deletions include/linux/kernel_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
return kstat_cpu(cpu).irqs_sum;
}

/*
* Lock/unlock the current runqueue - to extract task statistics:
*/
extern unsigned long long task_delta_exec(struct task_struct *);

extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
extern void account_steal_time(cputime_t);
Expand Down
13 changes: 0 additions & 13 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2499,19 +2499,6 @@ static u64 do_task_delta_exec(struct task_struct *p, struct rq *rq)
return ns;
}

unsigned long long task_delta_exec(struct task_struct *p)
{
unsigned long flags;
struct rq *rq;
u64 ns = 0;

rq = task_rq_lock(p, &flags);
ns = do_task_delta_exec(p, rq);
task_rq_unlock(rq, p, &flags);

return ns;
}

/*
* Return accounted runtime for the task.
* In case the task is currently running, return the runtime plus current's
Expand Down
2 changes: 1 addition & 1 deletion kernel/time/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
*sample = cputime_to_expires(cputime.utime);
break;
case CPUCLOCK_SCHED:
*sample = cputime.sum_exec_runtime + task_delta_exec(p);
*sample = cputime.sum_exec_runtime;
break;
}
return 0;
Expand Down

0 comments on commit 23cfa36

Please sign in to comment.