[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1369604149-13016-11-git-send-email-kosaki.motohiro@gmail.com>
Date: Sun, 26 May 2013 17:35:49 -0400
From: kosaki.motohiro@...il.com
To: linux-kernel@...r.kernel.org
Cc: Olivier Langlois <olivier@...llion01.com>,
Thomas Gleixner <tglx@...utronix.de>,
Frederic Weisbecker <fweisbec@...il.com>,
Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
Subject: [PATCH 8/8] posix-cpu-timers: fix cputimer initialization mistake for {u,s}time
From: KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
When using CPUCLOCK_VIRT or CPUCLOCK_PROF, we need to round an expire up
because jiffies based accounting may point to one jiffy behind at maximum.
So, current code lead to wake up posix timer too early.
This patch adds one jiffy at timer initialization. itimer already has a
similar trick and it match a userland assumption.
Luckily, CPUCLOCK_VIRT and CPUCLOCK_PROF posix timer are undocumented,
standard undefined, and no libc support. So maybe nobody uses them.
However, it still would be nice to fix if possible.
Cc: Olivier Langlois <olivier@...llion01.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
---
kernel/posix-cpu-timers.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 34bb3f1..42874c2 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -339,6 +339,18 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
return do_cpu_clock_timer_sample(which_clock, p, true, false, cpu);
}
+static union cpu_time_count cpu_clock_resolution(clockid_t cpuid)
+{
+ union cpu_time_count ret;
+
+ if (CPUCLOCK_WHICH(cpuid) == CPUCLOCK_SCHED)
+ ret.sched = 1;
+ else
+ ret.cpu = cputime_one_jiffy;
+
+ return ret;
+}
+
static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
{
const pid_t pid = CPUCLOCK_PID(which_clock);
@@ -806,7 +818,15 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int flags,
cpu_clock_sample(timer->it_clock, p, &now);
else
cpu_clock_sample_group(timer->it_clock, p, &now);
+
cpu_time_add(timer->it_clock, &new_expires, now);
+
+ /*
+ * When inaccurate timer, we need to adjust an expire time
+ * because "now" may point to slightly past time.
+ */
+ cpu_time_add(timer->it_clock, &new_expires,
+ cpu_clock_resolution(timer->it_clock));
}
/*
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists