Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72199320 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar
Browse files

timekeeping: Add the new CLOCK_MONOTONIC_ACTIVE clock



The planned change to unify the behaviour of the MONOTONIC and BOOTTIME
clocks vs. suspend removes the ability to retrieve the active
non-suspended time of a system.

Provide a new CLOCK_MONOTONIC_ACTIVE clock which returns the active
non-suspended time of the system via clock_gettime().

This preserves the old behaviour of CLOCK_MONOTONIC before the
BOOTTIME/MONOTONIC unification.

This new clock also allows applications to detect programmatically that
the MONOTONIC and BOOTTIME clocks are identical.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kevin Easton <kevin@guarana.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mark Salyzyn <salyzyn@android.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20180301165149.965235774@linutronix.de


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 78b98e3c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ struct tk_read_base {
 * @offs_real:		Offset clock monotonic -> clock realtime
 * @offs_boot:		Offset clock monotonic -> clock boottime
 * @offs_tai:		Offset clock monotonic -> clock tai
 * @time_suspended:	Accumulated suspend time
 * @tai_offset:		The current UTC to TAI offset in seconds
 * @clock_was_set_seq:	The sequence number of clock was set events
 * @cs_was_changed_seq:	The sequence number of clocksource change events
@@ -94,6 +95,7 @@ struct timekeeper {
	ktime_t			offs_real;
	ktime_t			offs_boot;
	ktime_t			offs_tai;
	ktime_t			time_suspended;
	s32			tai_offset;
	unsigned int		clock_was_set_seq;
	u8			cs_was_changed_seq;
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ extern void getrawmonotonic64(struct timespec64 *ts);
extern void ktime_get_ts64(struct timespec64 *ts);
extern time64_t ktime_get_seconds(void);
extern time64_t ktime_get_real_seconds(void);
extern void ktime_get_active_ts64(struct timespec64 *ts);

extern int __getnstimeofday64(struct timespec64 *tv);
extern void getnstimeofday64(struct timespec64 *tv);
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ struct itimerval {
 */
#define CLOCK_SGI_CYCLE			10
#define CLOCK_TAI			11
#define CLOCK_MONOTONIC_ACTIVE		12

#define MAX_CLOCKS			16
#define CLOCKS_MASK			(CLOCK_REALTIME | CLOCK_MONOTONIC)
+2 −0
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp)
	case CLOCK_BOOTTIME:
		get_monotonic_boottime64(tp);
		break;
	case CLOCK_MONOTONIC_ACTIVE:
		ktime_get_active_ts64(tp);
	default:
		return -EINVAL;
	}
+13 −0
Original line number Diff line number Diff line
@@ -263,6 +263,13 @@ static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
	return 0;
}

static int posix_get_monotonic_active(clockid_t which_clock,
				      struct timespec64 *tp)
{
	ktime_get_active_ts64(tp);
	return 0;
}

static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp)
{
	tp->tv_sec = 0;
@@ -1330,6 +1337,11 @@ static const struct k_clock clock_boottime = {
	.timer_arm		= common_hrtimer_arm,
};

static const struct k_clock clock_monotonic_active = {
	.clock_getres		= posix_get_hrtimer_res,
	.clock_get		= posix_get_monotonic_active,
};

static const struct k_clock * const posix_clocks[] = {
	[CLOCK_REALTIME]		= &clock_realtime,
	[CLOCK_MONOTONIC]		= &clock_monotonic,
@@ -1342,6 +1354,7 @@ static const struct k_clock * const posix_clocks[] = {
	[CLOCK_REALTIME_ALARM]		= &alarm_clock,
	[CLOCK_BOOTTIME_ALARM]		= &alarm_clock,
	[CLOCK_TAI]			= &clock_tai,
	[CLOCK_MONOTONIC_ACTIVE]	= &clock_monotonic_active,
};

static const struct k_clock *clockid_to_kclock(const clockid_t id)
Loading