Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4355649imm; Mon, 17 Sep 2018 12:26:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZEJNcU3FvjnWrz3Sk68DVEZq5RwfivNONWpgazwrOJCQ+UxhKJupTumMqwn7qjn4zHPbCd X-Received: by 2002:a63:8e4a:: with SMTP id k71-v6mr24689564pge.45.1537212397298; Mon, 17 Sep 2018 12:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537212397; cv=none; d=google.com; s=arc-20160816; b=pA2AyFsTrlqtaAwo0uvSEtKLAct2N4cj1om882/3G83hOxbMC2PNvshPONtHYTOxZD FoUQEYOh/93qFUw/AuepF3w+mv3V2B0Z6T3mjpkebpOIhectykUqev169d9tobin2N8Y qvZGX4ZUYoddOt/xlg3dxYnL1QiaCSe8s4p0ZZcwf7jC/qqOAi0NmFTMeaIIxb2AcVSI nNO7conSRW9/q9pmTQpyNEs0z0PjEs30Hx5i0Kpahdq1ONO1F62HYRRA6098ygg4Zj8l ojtW2mZi5YjEYpldpFW8z2O7Rhs2qffPio4Cn2uO41Mpwbm/z/PjYOgTZlKtUSVIa+Kj LXhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=tZ9b0Ab4nalkUbxSN1nL2wu1Z6/w1g6okr/GQe36sfU=; b=05qHBxbL/jyNqWdG8flM5DuumHzNw9w9hZQl9HiihC+cvYwdy7arOPlUgXmDW5LEI/ oAzEaHCNYf7FIYCBjTgKYlEr5Chii9AaO11bqa/o8CGIGz+xQgbRWsHIiuBBQ8lDKJNK DbPFBIJYi3rvpEfXtKlukw8BOEjvNPojspE/3j4VaMGJPxtqhBdmwInr2nSiaqU7MpfH DmCCvoZ2EEUN4HAtXkgISOibcFm+Vm+0BwH7lnF7cRKFbdQpixBpiiiEegOKOiF1oqJz yE+qggOq1PjjlYL02DjW9LBUbka51Ldv4+8To+k+fL9ZbPUqEcWz95PWoNOBLn8FQlX7 Bdrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N8mlRCB8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u1-v6si17742200pfc.337.2018.09.17.12.26.22; Mon, 17 Sep 2018 12:26:37 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=N8mlRCB8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeIRAyo (ORCPT + 99 others); Mon, 17 Sep 2018 20:54:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:41602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbeIRAyo (ORCPT ); Mon, 17 Sep 2018 20:54:44 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 14795214FE for ; Mon, 17 Sep 2018 19:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1537212360; bh=Lv+GLupaRo5hCP9HnNMyUrPg84YJuzARl2Fo3aXm3I8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=N8mlRCB8Hwl0tqBme45Fv0emymouOnnhBP8WWS2z6Tph2XN1FGzpWaDZaF5820JMM xZ3qV+7rr+u6+of2xGZC+xnC/rjWeYoysNwN4idz+XFFquzI/iPVmJBYXX/c5MMdCT dN0o4pFQLQgkng5dCeP6XRaIHUxitvbuNlYmnwS4= Received: by mail-wm1-f52.google.com with SMTP id c14-v6so10928058wmb.4 for ; Mon, 17 Sep 2018 12:26:00 -0700 (PDT) X-Gm-Message-State: APzg51CYjpvdml85S9pUWnW4H6zPV6j8GLY7AOUcyCOcGXzaAq0ia5Mt CpuS3E7GitdUkYP9Zr01CwkFne5pWJz1Cdu8ktxIsw== X-Received: by 2002:a1c:8a04:: with SMTP id m4-v6mr12554970wmd.137.1537212358434; Mon, 17 Sep 2018 12:25:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:7810:0:0:0:0:0 with HTTP; Mon, 17 Sep 2018 12:25:38 -0700 (PDT) In-Reply-To: <20180914125118.909646643@linutronix.de> References: <20180914125006.349747096@linutronix.de> <20180914125118.909646643@linutronix.de> From: Andy Lutomirski Date: Mon, 17 Sep 2018 12:25:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [patch 09/11] x86/vdso: Simplify the invalid vclock case To: Thomas Gleixner Cc: LKML , Andy Lutomirski , X86 ML , Peter Zijlstra , Matt Rickard , Stephen Boyd , John Stultz , Florian Weimer , "K. Y. Srinivasan" , Vitaly Kuznetsov , devel@linuxdriverproject.org, Linux Virtualization , Paolo Bonzini , Arnd Bergmann , Juergen Gross Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 14, 2018 at 5:50 AM, Thomas Gleixner wrote: > The code flow for the vclocks is convoluted as it requires the vclocks > which can be invalidated separately from the vsyscall_gtod_data sequence to > store the fact in a separate variable. That's inefficient. > > notrace static int do_hres(clockid_t clk, struct timespec *ts) > { > struct vgtod_ts *base = >od->basetime[clk]; > unsigned int seq; > - int mode; > - u64 ns; > + u64 cycles, ns; > > do { > seq = gtod_read_begin(gtod); > - mode = gtod->vclock_mode; > ts->tv_sec = base->sec; > ns = base->nsec; > - ns += vgetsns(&mode); > + cycles = vgetcyc(gtod->vclock_mode); > + if (unlikely((s64)cycles < 0)) > + return vdso_fallback_gettime(clk, ts); i was contemplating this, and I would suggest one of two optimizations: 1. have all the helpers return a struct containing a u64 and a bool, and use that bool. The compiler should do okay. 2. Be sneaky. Later in the series, you do: if (unlikely((s64)cycles < 0)) return vdso_fallback_gettime(clk, ts); - ns += (cycles - gtod->cycle_last) * gtod->mult; + if (cycles > last) + ns += (cycles - last) * gtod->mult; How about: if (unlikely((s64)cycles <= last)) { if (cycles < 0) [or cycles == -1 or whatever] return vdso_fallback_gettime; } else { ns += (cycles - last) * gtod->mult; } which should actually make this whole mess be essentially free. Also, I'm not entirely convinced that this "last" thing is needed at all. John, what's the scenario under which we need it? --Andy --Andy