Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5838532rwd; Mon, 5 Jun 2023 09:11:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5h5jczukowxRUO+So2GcByUPDF0gjPfapTLpq7KaWWkXEbuCvk65HjhAizS0aiCSzMXrE0 X-Received: by 2002:a17:902:7fc7:b0:1ae:44f0:82d0 with SMTP id t7-20020a1709027fc700b001ae44f082d0mr3424146plb.43.1685981499544; Mon, 05 Jun 2023 09:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685981499; cv=none; d=google.com; s=arc-20160816; b=p6FQ7IDOi5+Gf+oUz5cOYzmx/7XOzd481OmlLzncLFlkGKVhUGb8zTAUU9RpDJbT3i zoU7AkUS0KEMp6fHqSONPnS8G2pWUvona3bwX8IMuHP1okjTLKxnUSBBd5Z3CCe08QwE nx8hk264hQDMYU/a8OcwJwHmdUvfXEyJ7D37N9k0Azun/s3uHBvy28iOd3iwoMhR5ipv UOpJemy21o6S7bsY5ztYuUyGCU+Ilfuh55Z3Vv8DgoqM2FheluV8EzcI/pjQ8wewnf/i 1TMqAZSXNwV4pmjWNRPdPyB/fW8QKGReorfsESQtsaByAWfKCL1AO1+NDZlADysLzCNz xYWw== 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=tWcLYa+7bNXoqm0uU+Y/TpY/zbwTzKzpsszC21tO5Yg=; b=T3mqqPMY15XdbzruOOGS5KqnRWjdE5o3sgPXbp8NlYncpaoXtLSkQHhGPvnxkxcGdL riQ/LQzRrYkdEr1GbRB2dBVISqOSweyZgc3sFrB9ScmPYJj7aLVt9idCyHDM8ybp7W/j D1pWMs7plz39eTpBqZfVqlVEoJ4Zw9W06iPNZFuUQZYWoB1GKK9yvd6G/RbheQ3YMpiU MWhqjMoMY5PJGbL2jVRcWvTGkFCd7TFZQ5Govk+N1vqs1eDqs4zqLPMgPf+57udc2aDG COyr8idRWygo+2s1d8/ID9pwr+LR59Ou9raZHKkPlCMAgVNBijF/BUMdREOMJz+ODRXs tLVA== 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 d14-20020a170902cece00b001992f451a28si5840940plg.384.2023.06.05.09.11.27; Mon, 05 Jun 2023 09:11:39 -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 S229455AbjFEPyk convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jun 2023 11:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjFEPyi (ORCPT ); Mon, 5 Jun 2023 11:54:38 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D51294 for ; Mon, 5 Jun 2023 08:54:36 -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-98-9yYpkgM7No6H2Bh9opR73w-1; Mon, 05 Jun 2023 16:54:34 +0100 X-MC-Unique: 9yYpkgM7No6H2Bh9opR73w-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 5 Jun 2023 16:54:22 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 5 Jun 2023 16:54:22 +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: Steven Noonan , "kernel@collabora.com" Subject: RE: Direct rdtsc call side-effect Thread-Topic: Direct rdtsc call side-effect Thread-Index: AQHZlHOrHGvpd378GUKTvqmuipgWK698BnPAgAA4NYCAACHzkA== Date: Mon, 5 Jun 2023 15:54:22 +0000 Message-ID: References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> <353732783fde46919fdcf698c326b7ed@AcuMS.aculab.com> <87jzwi55qo.ffs@tglx> In-Reply-To: <87jzwi55qo.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 From: Thomas Gleixner > Sent: 05 June 2023 15:44 > > On Mon, Jun 05 2023 at 10:27, David Laight wrote: > > It has to be said that using it as a time source was fundamentally > > a bad idea. > > Too bad you weren't around many moons ago and educated us on that. That > would have saved us lots of trouble and work. Indeed :-) I do remember thinking the TSC was really a good time source when I first saw it being done about 30 years ago. > > > 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. > > Interesting view that high end databases are considered micro benchmarks > which need root access. I'm thinking of benchmarking the IP checksum code where you are trying to find out how many bytes/clock the loop is doing. On recent x86-64 the theoretical limit (without fighting AVX) 1s 16 bytes/clock, I've measured 12, 8 is relatively easy. (The current asm code runs at 4 on older cpu, doesn't get much above 6 at all.) What happens is that the cpu frequency speeds up as soon as the test starts but the TSC frequency stays constants. So you can only use the TSC to measure time, not execution speed. Run enough copies of 'while :; do :; done &' to make all but one cpu busy and the cpus all speed up giving completely different TSC counts for short loops. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)