[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.21.1902072225420.1645@nanos.tec.linutronix.de>
Date: Thu, 7 Feb 2019 22:40:55 +0100 (CET)
From: Thomas Gleixner <tglx@...utronix.de>
To: Dmitry Safonov <dima@...sta.com>
cc: linux-kernel@...r.kernel.org, Andrei Vagin <avagin@...nvz.org>,
Adrian Reber <adrian@...as.de>,
Andrei Vagin <avagin@...il.com>,
Andy Lutomirski <luto@...nel.org>,
Andy Tucker <agtucker@...gle.com>,
Arnd Bergmann <arnd@...db.de>,
Christian Brauner <christian.brauner@...ntu.com>,
Cyrill Gorcunov <gorcunov@...nvz.org>,
Dmitry Safonov <0x7f454c46@...il.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
Jeff Dike <jdike@...toit.com>, Oleg Nesterov <oleg@...hat.com>,
Pavel Emelyanov <xemul@...tuozzo.com>,
Shuah Khan <shuah@...nel.org>,
containers@...ts.linux-foundation.org, criu@...nvz.org,
linux-api@...r.kernel.org, x86@...nel.org
Subject: Re: [PATCH 03/32] timens: Introduce CLOCK_MONOTONIC offsets
On Wed, 6 Feb 2019, Dmitry Safonov wrote:
> #include "timekeeping.h"
> #include "posix-timers.h"
> @@ -1041,6 +1042,9 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
>
> error = kc->clock_get(which_clock, &kernel_tp);
>
> + if (!error && kc->clock_timens_adjust)
> + timens_clock_from_host(which_clock, &kernel_tp);
Why are you adding this conditional instead of sticking the offset
magic into the affected ->clock_get() implementations?
That spares you the switch() and the !offsets conditional.
> +static void clock_timens_fixup(int clockid, struct timespec64 *val, bool to_ns)
> +{
> + struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets;
> + struct timespec64 *offsets = NULL;
> +
> + if (!ns_offsets)
> + return;
> +
> + if (val->tv_sec == 0 && val->tv_nsec == 0)
> + return;
I have no idea why 0/0 is special.
> +
> + switch (clockid) {
> + case CLOCK_MONOTONIC:
> + case CLOCK_MONOTONIC_RAW:
> + case CLOCK_MONOTONIC_COARSE:
> + offsets = &ns_offsets->monotonic_time_offset;
> + break;
> + }
> +
> + if (!offsets)
> + return;
> +
> + if (to_ns)
> + *val = timespec64_add(*val, *offsets);
> + else
> + *val = timespec64_sub(*val, *offsets);
> +}
> +
> +void timens_clock_to_host(int clockid, struct timespec64 *val)
Does this really need to be an out of line call? If you stick this into the
clock_get() implementations then it boils down to:
static inline void timens_add_monotonic(struct timespec64 *ts)
{
struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets;
if (ns_offsets)
*ts = timespec64_add(*ts, ns_offsets->monotonic_time_offset);
}
and
static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp)
{
ktime_get_ts64(tp);
timens_add_monotonic(tp);
return 0;
}
Hmm?
Thanks,
tglx
Powered by blists - more mailing lists