Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp896412imj; Thu, 7 Feb 2019 13:42:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+EIEHWQ7mAiHQoxKt78PX7m83SyUlF53K0KnPu5cEOWxf7Q61IaSBfGc4xtaxWQJpp4DJ X-Received: by 2002:a17:902:449:: with SMTP id 67mr10148781ple.310.1549575721559; Thu, 07 Feb 2019 13:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549575721; cv=none; d=google.com; s=arc-20160816; b=fIcc6UQH6AyrU2ECrSOEQakOwDPeBl/b2bNfUQ/Be4UUuh2WYNYY3ZvDSWdEg7wD74 ZnZViuhKTQYpWjl0HZB2WoBhIflqpV8FW7MDAotYoJg5b/w0ifjuu8xlYdBxmsCe8qau 6Fn71Fvf6Zyu8ozMuvkHZ6ZmIW1/lKVr3+rQW4igyE8Vi/ZBGhAQLl9ZUTyNWpzuGyyX Jzcm/V765YM7MVhtcxa2cwXVtc5oUry8GjmqwYIfyhzXGHQV4m7bq61vjRm5FB1nkAau n0P9yyAJ3YpahG3419EaS/U8MnQEBBZyzsJ9qj2LVXEiI/vEE0nDRpiDB3AGsPDLi2Q/ QPhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=KBdKqMbXUimdwtd5OpZODPX6+ne5CmimGfppJJ6iIeg=; b=SD1E/axLY98mcSvbTMA+2enI97PtwbcWggUGF7S+rFcj0l9lyPJ35rgDv3jaM63MjJ 3bEAvWIec2ca0hUCDVatuiWiT4y/MgN6XKqYIrrbx9lf8fsiyR873qVSlevSw87VW6BX 49SjmEGE3U96cHiGJJZpit+5+Tf3hwRWrVr9u04OKsQa3W9SIxOyZVLJg4E14jtd4iJZ QQGYxBD8xJLY2t+26amTqTCCLcZLIavsbB8YR5uVlAC8OJ/z/k+X7X+oAA+01hPkAas7 hhDFT2adCAWC1GYVohrt4CzMZBO2Mp7ipICGIRLrgBa1P5MnPyOaufkvsjVUEMjmJlTG g3QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si107718pld.331.2019.02.07.13.41.43; Thu, 07 Feb 2019 13:42:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726978AbfBGVlY (ORCPT + 99 others); Thu, 7 Feb 2019 16:41:24 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:40698 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbfBGVlY (ORCPT ); Thu, 7 Feb 2019 16:41:24 -0500 Received: from p5492e0d8.dip0.t-ipconnect.de ([84.146.224.216] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1grrPp-0004UV-2a; Thu, 07 Feb 2019 22:41:01 +0100 Date: Thu, 7 Feb 2019 22:40:55 +0100 (CET) From: Thomas Gleixner To: Dmitry Safonov cc: linux-kernel@vger.kernel.org, Andrei Vagin , Adrian Reber , Andrei Vagin , Andy Lutomirski , Andy Tucker , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 03/32] timens: Introduce CLOCK_MONOTONIC offsets In-Reply-To: <20190206001107.16488-4-dima@arista.com> Message-ID: References: <20190206001107.16488-1-dima@arista.com> <20190206001107.16488-4-dima@arista.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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