Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp142486imm; Fri, 31 Aug 2018 20:43:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZBu8I3saS/tZ6Q3dmqlTo+WFWpEAwqtgLR+HnznjF4y5cxVdn9Q6Y1KZk/QDgYBXperB3e X-Received: by 2002:a63:f80a:: with SMTP id n10-v6mr16864395pgh.82.1535773421396; Fri, 31 Aug 2018 20:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535773421; cv=none; d=google.com; s=arc-20160816; b=SgZD1OK1F74ZyfQGAEdPPOWbmEFcCuFrYSCDKi5SN+BGDb2RnMmqyxGKGP8zbpnQLu mnp6osSWoVQ9jLgcMOdwsUxPRKxGK2VfiNA1Nz0yhRD3nxHnPQeFXKXaNLiGC0yjjs1l 2nnihUczvDnieICbLPM0hAXTc3sGiIM1H/7eoP8vmDWWcHMqZRnhfMCyfpN4f6yR0yp3 KY9NK5Mxp89woP3/fitZu1FbqlzrkSvWkPn4l8xFJVboW7hNABPxexS0b9ybqqCbYktz LBXPnvyaralsvaSJX5u/HgpTJTm5DSCMnhKhkJ0+idxZbgMhSzYtMWuKMMXCwZaXCbSL D8+g== 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 :arc-authentication-results; bh=Aws5rmzMbwct66wj3IQFl9pj06Qz71J1eBpzhLFg5IE=; b=d/O0g+Bqqa+WREhNyglwvP6Tr3YpYzaZE+nm0j6QVFMpAlltSPXuLuuGd9t7JRpr7W MHIA/VMK3h26lwSSdvhwCto7bAAtFbQ2zqzF93gYVhQFnnnSPZQCoCBDQs/MjJlovBhJ i3JXte5Nmc8gdnskU/bUlBEIZVkSGdyh9wYdQLFmSf/gr8cwpPkMjJ0+fDTBY9ZKdyZw hBSqLP7VkCXGRDaQu9p0soq8ucpGmDDbveWEohGuch/vqaXvTAEZbnv4NzzcqM7OwtmL EjLSprfEJ5+0v7EXSTMNPopDarp+wZFGhww08jPQR0tG/hXwhkBk5JZTGQoQxHz6gZXJ Nw/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oyVkgGrc; 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 j125-v6si11846806pfc.243.2018.08.31.20.42.53; Fri, 31 Aug 2018 20:43:41 -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=oyVkgGrc; 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 S1726621AbeIAHuT (ORCPT + 99 others); Sat, 1 Sep 2018 03:50:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725923AbeIAHuT (ORCPT ); Sat, 1 Sep 2018 03:50:19 -0400 Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) (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 32C4920845 for ; Sat, 1 Sep 2018 03:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535773192; bh=AAlUFWExg+GuQIMnAgl9hzfjFpVMUPdigaM+LBsspFI=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=oyVkgGrcXeS5BOwjBoDfdAfHEM8imZm2tXPWqLFasLIn9cJ4oPc5c3s4i9ugvFmG9 RQ+SPa8dYpPjukb3Q9jQ/yyzJ2ufDs953Ez5eAylGE07DFiNYeAh6rBZk7Hub/gdKF wWLcOXin+w78CPJ6lbLMUlHDSG6fItgEwbSwA2Nw= Received: by mail-wm0-f46.google.com with SMTP id f21-v6so6796941wmc.5 for ; Fri, 31 Aug 2018 20:39:52 -0700 (PDT) X-Gm-Message-State: APzg51CHvUevmA3NR8Mm8WHiikGkqmuZD/BectJs04j8jUnYMS7OXMTB 1zWS2pAKN85qgtbRW2B8Ufq84Apb1QkJMEfypDCPLA== X-Received: by 2002:a1c:ef0f:: with SMTP id n15-v6mr2035274wmh.116.1535773190659; Fri, 31 Aug 2018 20:39:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:9045:0:0:0:0:0 with HTTP; Fri, 31 Aug 2018 20:39:30 -0700 (PDT) In-Reply-To: <20180901015935.CCF0B18E20A9@virtux64.softrans.com.au> References: <20180901015935.CCF0B18E20A9@virtux64.softrans.com.au> From: Andy Lutomirski Date: Fri, 31 Aug 2018 20:39:30 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO To: Matt Rickard , Florian Weimer Cc: Thomas Gleixner , Andy Lutomirski , Stephen Boyd , John Stultz , X86 ML , LKML Content-Type: multipart/mixed; boundary="0000000000007c59390574c70f69" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000007c59390574c70f69 Content-Type: text/plain; charset="UTF-8" (Hi, Florian!) On Fri, Aug 31, 2018 at 6:59 PM, Matt Rickard wrote: > Process clock_gettime(CLOCK_TAI) in vDSO. > This makes the call about as fast as CLOCK_REALTIME and CLOCK_MONOTONIC: > > nanoseconds > before after clockname > ---- ----- --------- > 233 87 CLOCK_TAI > 96 93 CLOCK_REALTIME > 88 87 CLOCK_MONOTONIC Are you sure you did this right? With the clocksource set to TSC (which is the only reasonable choice unless KVM has seriously cleaned up its act), with retpolines enabled, I get 24ns for CLOCK_MONOTONIC without your patch and 32ns with your patch. And there is indeed a retpoline in the disassembled output: e5: e8 07 00 00 00 callq f1 <__vdso_clock_gettime+0x31> ea: f3 90 pause ec: 0f ae e8 lfence ef: eb f9 jmp ea <__vdso_clock_gettime+0x2a> f1: 48 89 04 24 mov %rax,(%rsp) f5: c3 retq You're probably going to have to set -fno-jump-tables or do something clever like adding a whole array of (seconds, nsec) in gtod and indexing that array by the clock id. Meanwhile, I wrote the following trivial patch to add a __vdso_clock_gettime_monotonic export. It runs in 21ns, and I suspect that the speedup is even a bit bigger when cache-cold because it avoids some branches. What do you all think? Florian, do you think glibc would be willing to add some magic to turn clock_gettime(CLOCK_MONOTONIC, t) into __vdso_clock_gettime_monotonic(t) when CLOCK_MONOTONIC is a constant? --0000000000007c59390574c70f69 Content-Type: text/x-patch; charset="US-ASCII"; name="vclock_gettime_monotonic.patch" Content-Disposition: attachment; filename="vclock_gettime_monotonic.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_jlivghyt0 ZGlmZiAtLWdpdCBhL2FyY2gveDg2L2VudHJ5L3Zkc28vdmNsb2NrX2dldHRpbWUuYyBiL2FyY2gv eDg2L2VudHJ5L3Zkc28vdmNsb2NrX2dldHRpbWUuYwppbmRleCA5MWVkMWJiMmEzYmIuLjRmMjJl OWNiOTdhNSAxMDA2NDQKLS0tIGEvYXJjaC94ODYvZW50cnkvdmRzby92Y2xvY2tfZ2V0dGltZS5j CisrKyBiL2FyY2gveDg2L2VudHJ5L3Zkc28vdmNsb2NrX2dldHRpbWUuYwpAQCAtMzE5LDYgKzMx OSwxNCBAQCBub3RyYWNlIGludCBfX3Zkc29fY2xvY2tfZ2V0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