From: John Stultz <john.stultz@linaro.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: "John Stultz" <john.stultz@linaro.org>,
"Jamie Lokier" <jamie@shareable.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Alexander Shishkin" <virtuoso@slind.org>,
"Arve Hjønnevåg" <arve@android.com>
Subject: [PATCH 4/5] timers: Add CLOCK_BOOTTIME hrtimer base
Date: Tue, 15 Feb 2011 20:20:06 -0800 [thread overview]
Message-ID: <1297830007-426-5-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1297830007-426-1-git-send-email-john.stultz@linaro.org>
CLOCK_MONOTONIC stops while the system is in suspend. This is because
to applications system suspend is invisible. However, there is a
growing set of applications that are wanting to be suspend-aware,
but do not want to deal with the complications of CLOCK_REALTIME
(which might jump around if settimeofday is called).
For these applications, I propose a new clockid: CLOCK_BOOTTIME.
CLOCK_BOOTTIME is idential to CLOCK_MONOTONIC, except it also
includes any time spent in suspend.
This patch add hrtimer base for CLOCK_BOOTTIME, using
get_monotonic_boottime/ktime_get_boottime, to allow
in kernel users to set timers against.
CC: Jamie Lokier <jamie@shareable.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Alexander Shishkin <virtuoso@slind.org>
CC: Arve Hjønnevåg <arve@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
include/linux/hrtimer.h | 1 +
include/linux/time.h | 1 +
kernel/hrtimer.c | 16 ++++++++++++----
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 7a9e7ee..6bc1804 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -151,6 +151,7 @@ struct hrtimer_clock_base {
enum hrtimer_base_type {
HRTIMER_BASE_REALTIME,
HRTIMER_BASE_MONOTONIC,
+ HRTIMER_BASE_BOOTTIME,
HRTIMER_MAX_CLOCK_BASES,
};
diff --git a/include/linux/time.h b/include/linux/time.h
index 02d48fb..454a262 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -293,6 +293,7 @@ struct itimerval {
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
+#define CLOCK_BOOTTIME 7
/*
* The IDs of various hardware clocks:
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index e8bf3ad..4c53af1 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -73,6 +73,11 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
.get_time = &ktime_get,
.resolution = KTIME_LOW_RES,
},
+ {
+ .index = CLOCK_BOOTTIME,
+ .get_time = &ktime_get_boottime,
+ .resolution = KTIME_LOW_RES,
+ },
}
};
@@ -90,16 +95,17 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
*/
static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
{
- ktime_t xtim, tomono;
+ ktime_t xtim, mono, boot;
struct timespec xts, tom, slp;
get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &slp);
xtim = timespec_to_ktime(xts);
- tomono = timespec_to_ktime(tom);
+ mono = ktime_add(xtim, timespec_to_ktime(tom));
+ boot = ktime_add(mono, timespec_to_ktime(slp));
base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim;
- base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time =
- ktime_add(xtim, tomono);
+ base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono;
+ base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot;
}
/*
@@ -727,6 +733,7 @@ static int hrtimer_switch_to_hres(void)
base->hres_active = 1;
base->clock_base[HRTIMER_BASE_REALTIME].resolution = KTIME_HIGH_RES;
base->clock_base[HRTIMER_BASE_MONOTONIC].resolution = KTIME_HIGH_RES;
+ base->clock_base[HRTIMER_BASE_BOOTTIME].resolution = KTIME_HIGH_RES;
tick_setup_sched_timer();
@@ -1719,6 +1726,7 @@ void __init hrtimers_init(void)
{
hrtimer_clock_to_base_table[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME;
hrtimer_clock_to_base_table[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC;
+ hrtimer_clock_to_base_table[CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME;
hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
(void *)(long)smp_processor_id());
--
1.7.3.2.146.gca209
next prev parent reply other threads:[~2011-02-16 4:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-16 4:20 [PATCH 0/5] Introduce CLOCK_BOOTTIME John Stultz
2011-02-16 4:20 ` [PATCH 1/5] hrtimers: extend hrtimer base code to handle more then 2 clockids John Stultz
2011-02-16 4:20 ` [PATCH 2/5] time: Introduce get_monotonic_boottime and ktime_get_boottime John Stultz
2011-02-16 4:20 ` [PATCH 3/5] time: Extend get_xtime_and_monotonic_offset() to also return sleep John Stultz
2011-02-16 14:12 ` Jack Stone
2011-02-16 18:19 ` John Stultz
2011-02-16 4:20 ` John Stultz [this message]
2011-02-16 4:20 ` [PATCH 5/5] timers: Export CLOCK_BOOTTIME via the posix timers interface John Stultz
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=1297830007-426-5-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=arve@android.com \
--cc=jamie@shareable.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=virtuoso@slind.org \
/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