From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94882C77B7F for ; Tue, 16 May 2023 21:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbjEPVzO (ORCPT ); Tue, 16 May 2023 17:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjEPVzL (ORCPT ); Tue, 16 May 2023 17:55:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646786EA2 for ; Tue, 16 May 2023 14:54:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4627E63FD3 for ; Tue, 16 May 2023 21:53:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E88EC4339C; Tue, 16 May 2023 21:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684274028; bh=c2XN6cZstCHczarNlQBcFrj20ialrTX30SbvpFfFpPA=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=CVWAx9v832/iGK/cokVtpSu11MPkJz0I0Pfc4Ch/61XeqUtJU2S4lRGhjGJBQdKWe VWmLe7/1D3FLyp+Jd4XT8Em05Rn6e2E1Mk0Zfh5FiZsg0jEtpvQpPrkHhacnzKWujA /U+mdYAIaPHWgtye6ksZGmnxMLEw/aOcs0Ar8Cv0iG+6tfRQ+BAKGm1B0waJLUANmS Gq4w8rgZqFlH4zjKwMQL2RkGtyoqc7aiM8RZWnBkGsO4wMGaceYEqAqz9qGatIQdPs LAssY3krj4b3kIfEAaEEjfxmriuc9BICRVGD29TmwIACowgNCCwdWc8Hu5OTenTjUR QYBzWBIYetZQA== Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id EEF2227C0054; Tue, 16 May 2023 17:53:46 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute3.internal (MEProxy); Tue, 16 May 2023 17:53:46 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehledgudeiiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet nhguhicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenuc ggtffrrghtthgvrhhnpeehveelgedvvedtfeehvdeuieetvdeijeegieeivdffgeeukeff tdefuedvieejvdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdgvvhhilhdqtghloh gtkhdqthgvshhtrdgttgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqud duiedukeehieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrghes lhhinhhugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E6A1531A0063; Tue, 16 May 2023 17:53:45 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-431-g1d6a3ebb56-fm-20230511.001-g1d6a3ebb Mime-Version: 1.0 Message-Id: <6d2cf767-a5bb-4df4-bf9c-dcbf3bf82722@app.fastmail.com> In-Reply-To: References: Date: Tue, 16 May 2023 14:53:24 -0700 From: "Andy Lutomirski" To: "Rong Tao" , "Thomas Gleixner" Cc: "Rong Tao" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "the arch/x86 maintainers" , "H. Peter Anvin" , "Linux Kernel Mailing List" Subject: Re: [PATCH] x86/vdso: Use non-serializing instruction rdtsc Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 15, 2023, at 11:52 PM, Rong Tao wrote: > From: Rong Tao > > Replacing rdtscp or 'lfence;rdtsc' with the non-serializable instruction > rdtsc can achieve a 40% performance improvement with only a small loss of > precision. > > The RDTSCP instruction is not a serializing instruction, but it does wait > until all previous instructions have executed and all previous loads are > globally visible. The RDTSC instruction is not a serializing instruction. > It does not necessarily wait until all previous instructions have been > executed before reading the counter. > > Record the time-consuming of vdso clock_gettime(), pseudo code: > > count = 1000 * 1000 * 100; > while (count--) > clock_gettime(CLOCK_REALTIME, &ts); > > Time-consuming comparison: > > Time Consume(ns) | rdtsc_ordered() | rdtsc() | Promote > ------------------+-----------------+-----------+--------- > Physical Machine | 1269147289 | 759067324 | 40% > Guest OS (KVM) | 1756615963 | 995823886 | 43% > > Signed-off-by: Rong Tao Out of curiosity, what happens if you apply that patch and run this thing: https://git.kernel.org/pub/scm/linux/kernel/git/luto/misc-tests.git/tree/evil-clock-test.cc Build it with g++ -O2 and run: ./evil-clock-test -c monotonic --Andy