Commit fa18f7bd authored by KOSAKI Motohiro's avatar KOSAKI Motohiro Committed by Frederic Weisbecker

posix-cpu-timers: don't account cpu timer after stopped thread runtime accounting

When tsk->signal->cputimer->running is 1, signal->cputimer (i.e. per process
timer account) and tsk->sum_sched_runtime (i.e. per thread timer account)
increase at the same pace because update_curr() increases both accounting.

However, there is one exception. When thread exiting, __exit_signal() turns
over task's sum_shced_runtime to sig->sum_sched_runtime, but it doesn't stop
signal->cputimer accounting.

This inconsistency makes POSIX timer wake up too early. This patch fixes it.
Original-patch-by: default avatarOlivier Langlois <olivier@trillion01.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarOlivier Langlois <olivier@trillion01.com>
Signed-off-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent a0b2062b
...@@ -161,6 +161,39 @@ sched_info_switch(struct task_struct *prev, struct task_struct *next) ...@@ -161,6 +161,39 @@ sched_info_switch(struct task_struct *prev, struct task_struct *next)
* on CONFIG_SCHEDSTATS. * on CONFIG_SCHEDSTATS.
*/ */
/**
* cputimer_running - return true if cputimer is running
*
* @tsk: Pointer to target task.
*/
static inline bool cputimer_running(struct task_struct *tsk)
{
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
if (!cputimer->running)
return false;
/*
* After we flush the task's sum_exec_runtime to sig->sum_sched_runtime
* in __exit_signal(), we won't account to the signal struct further
* cputime consumed by that task, even though the task can still be
* ticking after __exit_signal().
*
* In order to keep a consistent behaviour between thread group cputime
* and thread group cputimer accounting, lets also ignore the cputime
* elapsing after __exit_signal() in any thread group timer running.
*
* This makes sure that POSIX CPU clocks and timers are synchronized, so
* that a POSIX CPU timer won't expire while the corresponding POSIX CPU
* clock delta is behind the expiring timer value.
*/
if (unlikely(!tsk->sighand))
return false;
return true;
}
/** /**
* account_group_user_time - Maintain utime for a thread group. * account_group_user_time - Maintain utime for a thread group.
* *
...@@ -176,7 +209,7 @@ static inline void account_group_user_time(struct task_struct *tsk, ...@@ -176,7 +209,7 @@ static inline void account_group_user_time(struct task_struct *tsk,
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
if (!cputimer->running) if (!cputimer_running(tsk))
return; return;
raw_spin_lock(&cputimer->lock); raw_spin_lock(&cputimer->lock);
...@@ -199,7 +232,7 @@ static inline void account_group_system_time(struct task_struct *tsk, ...@@ -199,7 +232,7 @@ static inline void account_group_system_time(struct task_struct *tsk,
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
if (!cputimer->running) if (!cputimer_running(tsk))
return; return;
raw_spin_lock(&cputimer->lock); raw_spin_lock(&cputimer->lock);
...@@ -222,7 +255,7 @@ static inline void account_group_exec_runtime(struct task_struct *tsk, ...@@ -222,7 +255,7 @@ static inline void account_group_exec_runtime(struct task_struct *tsk,
{ {
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
if (!cputimer->running) if (!cputimer_running(tsk))
return; return;
raw_spin_lock(&cputimer->lock); raw_spin_lock(&cputimer->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment