Skip to contentSkip to conversation

posixtimers: Fix posix clock monotonicity v3

PATCH RESEND In review Hidetoshi Seto 1 participant 2 messages Mar 31, 2009 – Apr 1, 2009

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 posixtimers: Fix posix clock monotonicity v3

Impact: Regression fix (against clock_gettime() backwarding bug)

This patch re-introduces a couple of function, task_sched_runtime and thread_group_sched_runtime, which was once removed at the time of 2.6.28-rc1.

These functions protect the sampling of thread/process clock with rq lock. This rq lock is required not to update rq->clock during the sampling.
i.e.
The clock_gettime() may return
((accounted runtime before update) + (delta after update))
that is less than what it should be.

v2 -> v3:
- Rename static helper function __task_delta_exec() to do_task_delta_exec() since -tip tree already has a __task_delta_exec() of different version.

v1 -> v2:
- Revises comments of function and patch description.
- Add note about accuracy of thread group's runtime.

---
 kernel/posix-cpu-timers.c |    7 +++--
 kernel/sched.c            |   65 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 11 deletions(-)
kernel/posix-cpu-timers.c +4 -3
index 8e5d9a6..6f7b869 100644
@@ -224,7 +224,7 @@ static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p,
 		cpu->cpu = virt_ticks(p);
 		break;
 	case CPUCLOCK_SCHED:
-		cpu->sched = p->se.sum_exec_runtime + task_delta_exec(p);
+		cpu->sched = task_sched_runtime(p);
 		break;
 	}
 	return 0;
@@ -305,18 +305,19 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
 {
 	struct task_cputime cputime;
 
-	thread_group_cputime(p, &cputime);
 	switch (CPUCLOCK_WHICH(which_clock)) {
 	default:
 		return -EINVAL;
 	case CPUCLOCK_PROF:
+		thread_group_cputime(p, &cputime);
 		cpu->cpu = cputime_add(cputime.utime, cputime.stime);
 		break;
 	case CPUCLOCK_VIRT:
+		thread_group_cputime(p, &cputime);
 		cpu->cpu = cputime.utime;
 		break;
 	case CPUCLOCK_SCHED:
-		cpu->sched = cputime.sum_exec_runtime + task_delta_exec(p);
+		cpu->sched = thread_group_sched_runtime(p);
 		break;
 	}
 	return 0;
kernel/sched.c +57 -8

82 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#1 lore raw

[tip:sched/urgent] posixtimers, sched: Fix posix clock monotonicity

Commit-ID:  c5f8d99585d7b5b7e857fabf8aefd0174903a98c
Gitweb:     http://git.kernel.org/tip/c5f8d99585d7b5b7e857fabf8aefd0174903a98c
Author:     Hidetoshi Seto <[email protected]>
AuthorDate: Tue, 31 Mar 2009 16:56:03 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2009 16:44:16 +0200

posixtimers, sched: Fix posix clock monotonicity

Impact: Regression fix (against clock_gettime() backwarding bug)

This patch re-introduces a couple of functions, task_sched_runtime and thread_group_sched_runtime, which was once removed at the time of 2.6.28-rc1.

These functions protect the sampling of thread/process clock with rq lock. This rq lock is required not to update rq->clock during the sampling.

i.e.
The clock_gettime() may return
((accounted runtime before update) + (delta after update))
that is less than what it should be.

v2 -> v3:
- Rename static helper function __task_delta_exec() to do_task_delta_exec() since -tip tree already has a __task_delta_exec() of different version.

v1 -> v2:
- Revises comments of function and patch description.
- Add note about accuracy of thread group's runtime.

LKML-Reference: <[email protected]>

---
 kernel/posix-cpu-timers.c |    7 +++--
 kernel/sched.c            |   65 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 11 deletions(-)
kernel/posix-cpu-timers.c +4 -3
index fa07da9..4318c30 100644
@@ -224,7 +224,7 @@ static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p,
 		cpu->cpu = virt_ticks(p);
 		break;
 	case CPUCLOCK_SCHED:
-		cpu->sched = p->se.sum_exec_runtime + task_delta_exec(p);
+		cpu->sched = task_sched_runtime(p);
 		break;
 	}
 	return 0;
@@ -240,18 +240,19 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
 {
 	struct task_cputime cputime;
 
-	thread_group_cputime(p, &cputime);
 	switch (CPUCLOCK_WHICH(which_clock)) {
 	default:
 		return -EINVAL;
 	case CPUCLOCK_PROF:
+		thread_group_cputime(p, &cputime);
 		cpu->cpu = cputime_add(cputime.utime, cputime.stime);
 		break;
 	case CPUCLOCK_VIRT:
+		thread_group_cputime(p, &cputime);
 		cpu->cpu = cputime.utime;
 		break;
 	case CPUCLOCK_SCHED:
-		cpu->sched = cputime.sum_exec_runtime + task_delta_exec(p);
+		cpu->sched = thread_group_sched_runtime(p);
 		break;
 	}
 	return 0;
kernel/sched.c +57 -8

82 lines not on this page · raw message