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 AAD44C7EE25 for ; Tue, 16 May 2023 14:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233070AbjEPOU7 (ORCPT ); Tue, 16 May 2023 10:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233878AbjEPOUb (ORCPT ); Tue, 16 May 2023 10:20:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CFBA7ED9 for ; Tue, 16 May 2023 07:20:18 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684246809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=FkXFAZYIh0haPSOcnt1eOZKRDhLeWlVCTunLq/bj9vc=; b=B5v0P+HYuHs8awq1DZLsQ4kqlnyl0mhVnxUEkFVi9MqzUnYnNGkeqTxrNIotxSalBFC10+ Hlw0xFA09mL3+td7bpsJferpf2xy8sfE9T26w7EHciXWaxM8cOR8rXGVJSR/BMgG9PUft9 zdg1qqcpkMU6y1JYIuIRfudoedFcUqPqKt8WmYGPNM/NBZxO03Aky7h5dKqoVjTXiJ+QCg 85jYUfWlWtAFrILeTDLw1N7e+G+aOt7CNIINPu9PO3ADmJxmHSykCBeixdH7HKJMuRcxO6 aK0Vz4KlXz8wTPGFQsGU/c+hg/247pS2TaHn82bALtxNpRF3fyU6pe5/Khlz2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684246809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=FkXFAZYIh0haPSOcnt1eOZKRDhLeWlVCTunLq/bj9vc=; b=KVIg+5re+0nftM7WOpVd6795CiyX2EXG8Zw4zyBUZ1n/PoatUkzTue/l2YJ8qfmzO+OGGR ssOKcZ4Nhad2cABA== To: Rong Tao Cc: rtoax@foxmail.com, Rong Tao , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/vdso: Use non-serializing instruction rdtsc In-Reply-To: Date: Tue, 16 May 2023 16:20:09 +0200 Message-ID: <87ttwc73za.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rong! On Tue, May 16 2023 at 14:52, Rong Tao wrote: > Replacing rdtscp or 'lfence;rdtsc' with the non-serializable instruction > rdtsc can achieve a 40% performance improvement with only a small loss of > precision. That rdtsc_ordered() is not there to achieve precision. It's there to guarantee correctness. The correctness requirement is that reading clock MONOTONIC is strictly monotonic, i.e. there is no way that you can observe time going backwards. Neither locally nor accross CPUs. As you explained: > The RDTSC instruction is not a serializing instruction. It does not > necessarily wait until all previous instructions have been executed > before reading the counter. Q: What guarantees that this does not speculate deep enough to actually make time go backwards? A: Nothing Conclusion: The fence stays, unless you can prove the contrary under all circumstances and microarchitecture generations. Thanks, tglx