Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5888224rwd; Mon, 5 Jun 2023 09:51:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gDSsulgtIDib/KBzBCnuldZa1scH76MchtZxRmfutOM9VKYQenmQZgXd2m+jFJLvM3yBS X-Received: by 2002:a05:6a00:1952:b0:648:c1be:496 with SMTP id s18-20020a056a00195200b00648c1be0496mr225251pfk.22.1685983881810; Mon, 05 Jun 2023 09:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685983881; cv=none; d=google.com; s=arc-20160816; b=cFFhALt60A8gpYIyXMbkyNEbJ5LeSmo+FcPaF7bdcQ4d/QAAb1h/BRIoTG1pXKL2I8 EQ6COq7o64uUoqZsLKHM6pmP/mcJbBHfjnk5I72go0sN5V8pvBuZzCdfo2ZzIXmvYaA3 8MerWSR99atIwhCxKgF2f+qkaqFwY0Tt0dRzgxlN7yZTOSwqwPX/xlOh21aV1dcz2FuU K1+2WgT4aDr+UkW8CXqj0hmk86KJrXwKPHGo+wt5qZelKLv7zMRtnLJ86c3cYdJyoknI AALjlX/LaynoDimuTc+uRlz4I69eWWD+OrR+DeCDK4ie+AEjEpWVYFH4l4L0+w/bEuyc GLOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=QzKVr2LoBWHFQbC68p/jgagz+vnQECzay1Xuo/y+g/8=; b=UKj9JV+BO2J6vWe05qMV5PfPD9VWnweTcBJZ2JIYBfuL13Hd1bpxmCIPC7/ZeI3bUj yLQtGKBqtgE0Kge0DqB4Gew+EL2PxpH6U4UZVemrkyi42g8YL4N1/RapKZBDCwYIai+k t4CweM9PSoVx28EpY2Uzuf1+X4uKjAEim+Q1BKnsDULriofDBb3WcKdva9F3nl46YoGK GDmR6sClisf+vPTgKzDLmXaGAdTPvkAhFblHq29g7jS//SaN5kmW719TCZD3K/Opewfe FvfSid6IB9vM+cPem47tug50sZD/iseknkUr4lnsucFAP7bJJhMLrwlHXAiO3p8ue8mL 7kew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@zytor.com header.s=2023051001 header.b=1em2soU6; 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=zytor.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 84-20020a630057000000b0053eeed3d26asi5748488pga.688.2023.06.05.09.51.09; Mon, 05 Jun 2023 09:51:21 -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; dkim=fail header.i=@zytor.com header.s=2023051001 header.b=1em2soU6; 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=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234247AbjFEQdm (ORCPT + 99 others); Mon, 5 Jun 2023 12:33:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235065AbjFEQd3 (ORCPT ); Mon, 5 Jun 2023 12:33:29 -0400 Received: from mail.zytor.com (unknown [IPv6:2607:7c80:54:3::138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C83E5E40; Mon, 5 Jun 2023 09:33:17 -0700 (PDT) Received: from [172.27.2.41] ([73.231.166.163]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.17.1) with ESMTPSA id 355GWORK3938757 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Mon, 5 Jun 2023 09:32:26 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 355GWORK3938757 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2023051001; t=1685982748; bh=QzKVr2LoBWHFQbC68p/jgagz+vnQECzay1Xuo/y+g/8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=1em2soU6xzrZzWJ6eJ0F2W2ZLTuU2sc0HBqMtwhLc5Bq+9iEO9/Jw3TxE5uJV/nDX JGoJMStv6xkvY+yeRCzecEqFQ4rcCOm/S+v7kIw6dQrTmLPdmyQd2AGNLBl5/ez4i1 59XPlRbiI5YNLiYjT+4UPgzqOeC9P9t65u3I5KLTENI0ZXtkrOzpWu8Vx6h/gHdSe6 teuwQwPiAACcffhxljJEOPjRWMOHDm1bhpguq/NXQgVUEaSvq46eRH6DoPl9xRumQ2 fjh5+9VjC/hK32y6y18Z2ftg+ofFCrhl5Nf6JRZA9UH6SqRvsPik1gm6DTc5AsHKgs 8yGU5xFfYz3DA== Message-ID: <4ea6e82c-4761-e0c9-3e75-8ec39eecb30a@zytor.com> Date: Mon, 5 Jun 2023 09:32:24 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Direct rdtsc call side-effect Content-Language: en-US To: David Laight , "'Thomas Gleixner'" , Muhammad Usama Anjum , Jonathan Corbet , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "open list:DOCUMENTATION" , open list , "Guilherme G. Piccoli" Cc: Steven Noonan , "kernel@collabora.com" References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> <353732783fde46919fdcf698c326b7ed@AcuMS.aculab.com> <87jzwi55qo.ffs@tglx> From: "H. Peter Anvin" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On 6/5/23 08:54, David Laight wrote: > 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. > The TSC is certainly not perfect; partly because, ironically enough, it was introduced just *before* out of order and power management entered the x86 world. It is no secret that it has been slow to catch up. It was easy to put a counter in; it is a *lot* harder to make it work in all the possible scenarios in the power-managed, out-of-order world. It is one of my personal pet projects in the architecture work to push to get that last distance; we are not yet there. > > 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. > That is the reason for architecturally fixed performance counters. -hpa