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 9DF1DC7EE24 for ; Mon, 5 Jun 2023 10:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbjFEK2E convert rfc822-to-8bit (ORCPT ); Mon, 5 Jun 2023 06:28:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbjFEK2C (ORCPT ); Mon, 5 Jun 2023 06:28:02 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8118AEA for ; Mon, 5 Jun 2023 03:28:00 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-263-SIO9pMM2PmCSq1FrXnM_pA-1; Mon, 05 Jun 2023 11:27:57 +0100 X-MC-Unique: SIO9pMM2PmCSq1FrXnM_pA-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 5 Jun 2023 11:27:46 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 5 Jun 2023 11:27:46 +0100 From: David Laight To: 'Thomas Gleixner' , Muhammad Usama Anjum , Jonathan Corbet , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:DOCUMENTATION" , open list , "Guilherme G. Piccoli" CC: Muhammad Usama Anjum , Steven Noonan , "kernel@collabora.com" Subject: RE: Direct rdtsc call side-effect Thread-Topic: Direct rdtsc call side-effect Thread-Index: AQHZlHOrHGvpd378GUKTvqmuipgWK698BnPA Date: Mon, 5 Jun 2023 10:27:46 +0000 Message-ID: <353732783fde46919fdcf698c326b7ed@AcuMS.aculab.com> References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> In-Reply-To: <87mt1jeax1.ffs@tglx> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org ... > Who would have thought that rdtsc() in applications can be a problem. > Interfaces to query time exist for a reason and it's documented by > Microsoft: > > https://learn.microsoft.com/en-us/windows/win32/dxtecharts/game-timing-and-multicore-processors > > But sure, reading documentation is overrated... That eve says: "Multiprocessor and dual-core systems do not guarantee synchronization of their cycle counters between cores." . > Synchronizing TSC by writing the TSC MSR is fragile as hell. This has > been tried so often and never reliably passed all synchronization tests > on a wide range of systems. > > It kinda works on single socket, but not on larger systems. > > We spent an insane amount of time to make timekeeping correct and I'm > not interested at all to deal with the fallout of such a mechanim. I've wondered whether the TSC ought to be deliberately mis-synchronised? So the high order bits are effectively the cpu number. It has to be said that using it as a time source was fundamentally a bad idea. Sometimes (eg micro benchmarks) you really want a TSC. You can extract one from the performance counters, but it is hard, root only, and the library functions have high and variable overhead. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)