Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5444713rwd; Mon, 5 Jun 2023 03:56:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5UU1ltKmMVSQNeoJk9vxfGVUwyUCgoDHoitCBT6JTWtKTqlRtufgXe5F0k+RQtcLOG1QPO X-Received: by 2002:a05:6359:2e94:b0:129:bc0b:aac2 with SMTP id rp20-20020a0563592e9400b00129bc0baac2mr851710rwb.7.1685962595638; Mon, 05 Jun 2023 03:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685962595; cv=none; d=google.com; s=arc-20160816; b=tPnEkW7zq3j2M9IHWBCDOB030qdyVV/UkyzjOOVfV3SYHmILDAQYhSzZUzCnVxRx3n KBvpzCXYBm75exEAPWFXn/CqO9SLp31ADTC4KO4CwMv46NPBJ5L6StCi65fudazkrLMI p7pGt4935F4qUDyxGdc2uNnqG1khKlmZMFptYpVJmIRdwKgERk7Vz8B/gRqAnSx15KMg PE1rpLAsyqzGcP/d2Xc/W1uE173EPi+RPOfI3iW5A+pW/mC2opIbBH2MPUsI6DH7W940 BHw3eWXQxZidmEjZ/7OHEuDjyR58UZ6m3bL8cYcHL7GmU66SB5A6kNgNfsEQfUgcAXnA uvQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=WoN75TSKMWJWVmmHqoO5fN7OdD5IbKbWGbvqWDzyeBk=; b=kC2ZdB41nNomNwHmh1KwDE53IZcrgysqGJpQ3JJFOQSG/mTbDZhDTwE4e5Y4oVdnK6 7egw1MdClH9HpMJmdTk0YSJPc2VowxACrbAJGLRN4osOhxP+hVD+eQqhFuBXC2lXJQXn 1VJNvX/P33hSy+/3cd2LT8XZw7KcytEH1dz9Vj0rWCMmu3cFNVu7KbPEsOuZYKXfly4I QLSSiKvboHS1YGHo8hMEIPm+GOUqY3UthGpcWSOECByS+6BuqV7ZkTb/+M0g/vpoiUXy QV5daAWEsY/94JbnHCddMDiEUAiavnzrk8nGq7Pl1oc5fBDVevBU/0RQYHfEjyxtbgtW QtrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p24-20020a63f458000000b0051f17a517adsi5448127pgk.492.2023.06.05.03.56.21; Mon, 05 Jun 2023 03:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231882AbjFEK2F convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jun 2023 06:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231861AbjFEK2C (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 7B23FA6 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)