From: kosaki.motohiro@gmail.com
To: linux-kernel@vger.kernel.org
Cc: Olivier Langlois <olivier@trillion01.com>,
Thomas Gleixner <tglx@linutronix.de>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Subject: [PATCH 8/8] posix-cpu-timers: fix cputimer initialization mistake for {u,s}time
Date: Sun, 26 May 2013 17:35:49 -0400 [thread overview]
Message-ID: <1369604149-13016-11-git-send-email-kosaki.motohiro@gmail.com> (raw)
In-Reply-To: <1369604149-13016-1-git-send-email-kosaki.motohiro@gmail.com>
From: KOSAKI Motohiro <kosaki.motohiro@jp.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@trillion01.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.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
next prev parent reply other threads:[~2013-05-26 21:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 21:35 [PATCH v5 0/8] posix timers fixlet kosaki.motohiro
2013-05-26 21:35 ` [PATCH 1/8] posix-cpu-timers: don't account cpu timer after stopped thread runtime accounting kosaki.motohiro
2013-05-26 21:35 ` [PATCH 2/8] posix-cpu-timers: fix acounting delta_exec twice kosaki.motohiro
2013-06-03 19:07 ` Frederic Weisbecker
2013-05-26 21:35 ` kosaki.motohiro
2013-05-26 21:35 ` [PATCH 3/8] posix-cpu-timers: fix wrong timer initialization kosaki.motohiro
2013-06-18 14:20 ` Frederic Weisbecker
2013-06-18 15:12 ` KOSAKI Motohiro
2013-06-19 20:56 ` Frederic Weisbecker
2013-05-26 21:35 ` [PATCH 4/8] posix-cpu-timers: timer functions should use timer time instead of clock time kosaki.motohiro
2013-05-26 21:35 ` [PATCH 5/8] posix-cpu-timers: check_thread_timers() uses task_sched_runtime() kosaki.motohiro
2013-05-26 21:35 ` [PATCH 6/8] sched: task_sched_runtime introduce micro optimization kosaki.motohiro
2013-06-18 14:27 ` Frederic Weisbecker
2013-06-18 15:17 ` KOSAKI Motohiro
2013-06-18 15:28 ` KOSAKI Motohiro
2013-06-18 17:18 ` Frederic Weisbecker
2013-06-20 8:41 ` KOSAKI Motohiro
2013-05-26 21:35 ` [PATCH 7/8] posix-cpu-timers: cleanup cpu_{clock,timer}_sample{,_group} kosaki.motohiro
2013-05-26 21:35 ` kosaki.motohiro [this message]
2013-05-31 16:26 ` [PATCH v5 0/8] posix timers fixlet KOSAKI Motohiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1369604149-13016-11-git-send-email-kosaki.motohiro@gmail.com \
--to=kosaki.motohiro@gmail.com \
--cc=fweisbec@gmail.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=olivier@trillion01.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®