Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp260802iob; Thu, 28 Apr 2022 01:34:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF84N6lMb4bAoKRYuYVOnzi2nGu/i6PTU8F8PLPtMiiJOTGeCzqMTHyWwtFTxyrBTeDBXV X-Received: by 2002:a63:82c2:0:b0:3ab:5747:8837 with SMTP id w185-20020a6382c2000000b003ab57478837mr15293083pgd.297.1651134846174; Thu, 28 Apr 2022 01:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651134846; cv=none; d=google.com; s=arc-20160816; b=xymL3yJ1SIj4mW+tx+18I1vN8ydkFdLktA5lrLVfo1OJJLVjpFdzg2ve7ooJc+jjqY mdKtwZwS4/MswWhJtThANgQxLnZpcSegp0bqPGETgbFuJeaBQyoqbdUb7t0p3h4xYvE5 Jo/HnfM71ySilZzFpdVIIfpxa3bjAs7t0wpSgzuvwzzKJTKe1ReyT2mzYOdEIzdjmu5N URhBMoqVJKjraEvNxu61dilqYzH5Rv8sZP1P+fxm955LtldvzugAR0yX2aF0UeyC/bjP DqwhQoJcBwvDL4YK1eXwshD3/t0IASmYRZI2VuYPSdn/gnqmaLu/XwIxlY3WvYM1A9Re zulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=e0JjrDY5ZRqnFRcUlqMMWqxBQcbO4A/xkDxTwlnqWFk=; b=XhJezvUtfHntpIQ+/0loqqOzmQBYkMXAKzrqeKCv11oaxvVQxNbWJ3nr7vcUjlkUVK 8ql6IVR8ssx+yamKZIg6TmXDzhp9/dewKUoK5Csi8G4cFKWUA/nsbPS0K2CC5U8DGtC5 7tgyYcriOx4AY0cqGIKCDdlaXIpczvjcuDMsDcZ27/6rSJ0YasLHdXPsIWhCTmEyq1K/ 8f3Oh35nXoJkMMm37zYfGH+xh0OjS5pUpJGF1MOgnfPqmjgVzCdmJyMg8VZDNpt8onPn mfQyPff0NbXRqdR7mTWeXRHfmiz0DL6rBJtheGf7ysiygNq6BVXame3TtJfcxmqitJmG RwVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jszYZzKU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9QL4MT7c; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q64-20020a632a43000000b003c14ba00ed9si3635152pgq.331.2022.04.28.01.33.51; Thu, 28 Apr 2022 01:34:06 -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=pass header.i=@linutronix.de header.s=2020 header.b=jszYZzKU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9QL4MT7c; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232271AbiD0Wle (ORCPT + 99 others); Wed, 27 Apr 2022 18:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232858AbiD0Wl2 (ORCPT ); Wed, 27 Apr 2022 18:41:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6265D6D4D6 for ; Wed, 27 Apr 2022 15:38:15 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1651099093; 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:references:references; bh=e0JjrDY5ZRqnFRcUlqMMWqxBQcbO4A/xkDxTwlnqWFk=; b=jszYZzKU9Rvaj4vO0mmsqXhjqNc3Kmos0bvnYLYr6I7iPz7aPlPApzuUorjIW6x9Qa6Fhv 7eEzpPQJXNOgkJDEnf6hHcR2/mKwP1te6TBEpd2EcgVFsoM4icSOSKh6sqnxbyUgxc25MP 72WvwH7+rV4Usb/6q6IYHcPvunTHhTjA5GyhMKUcERoS111LzApS9xNqBKbq6dadp+v5To om9izSodKsy5lpx39yETJ4Nnm04vMarlcgfJLbIFNfB4N763+ea3MosaTe7/4fn6f8Eu5C 36yAOsG0CHLJqLk41Xz/f7lG0wh4BfZtXQZjVhZ2bx8GDuStReSKBkKxON5qag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1651099093; 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:references:references; bh=e0JjrDY5ZRqnFRcUlqMMWqxBQcbO4A/xkDxTwlnqWFk=; b=9QL4MT7cR7VrfiWOSQecv39bRXF/RRERSU7EgX/+pd70Xr6NKGiSWYYBYCJZ8lz0vnY93a DnOyykn5zxBLWrAg== To: Waiman Long , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: x86@kernel.org, linux-kernel@vger.kernel.org, "H. Peter Anvin" , Feng Tang , Bill Gray , Jirka Hladky Subject: Re: [PATCH 2/2] x86/tsc_sync: Add synchronization overhead to tsc adjustment In-Reply-To: <68837b1a-f85b-e842-f8c0-1cad162856f4@redhat.com> References: <20220314194630.1726542-1-longman@redhat.com> <20220314194630.1726542-3-longman@redhat.com> <87czhymql2.ffs@tglx> <87levx8kou.ffs@tglx> <4f02fe46-b253-2809-0af7-f2e9da091fe9@redhat.com> <87czh50xwf.ffs@tglx> <68837b1a-f85b-e842-f8c0-1cad162856f4@redhat.com> Date: Thu, 28 Apr 2022 00:38:12 +0200 Message-ID: <87h76ew3sb.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 On Tue, Apr 26 2022 at 11:36, Waiman Long wrote: > On 4/25/22 15:24, Thomas Gleixner wrote: >> Yes. It's clear that the initial sync overhead is due to the cache line >> being remote, but I rather underestimate the compensation. Aside of that >> it's not guaranteed that the cache line is actually remote on the first >> access. It's by chance, but not by design. > > In check_tsc_warp(), the (unlikely(prev > now) check may only be > triggered to record the possible wrap if last_tsc was previously written > to by another cpu. That requires the transfer of lock cacheline from the > remote cpu to local cpu as well. So sync overhead with remote cacheline > is what really matters here. I had actually thought about just measuring > local cacheline sync overhead so as to underestimate it and I am fine > about doing it. Fair enough, but what I meant is that when estimating the actual sync overhead then there is no guarantee that the cache line is remote. The CPU which does that estimation might have been the last to lock, there is no guarantee that the reference CPU locked last or wrote to the cache line last. >> IOW, TSC runs with a constant frequency independent of the actual CPU >> frequency, ergo the CPU frequency dependent execution time has an >> influence on the resulting compensation value, no? >> >> On the machine I tested on, it's a factor of 3 between the minimal and >> the maximal CPU frequency, which makes quite a difference, right? > > Yes, I understand that. The measurement of sync_overhead is for > estimating the delay (in TSC cycles) that the locking overhead > introduces. With 1000MHz frequency, the delay in TSC cycle will be > double that of a cpu running at 2000MHz. So you need more compensation > in this case. That is why I said that as long as clock frequency doesn't > change in the check_tsc_wrap() loop and the sync_overhead measurement > part of the code, the actual cpu frequency does not matter here. I grant you that it does not matter for the loop under the assumption that the loop runs at constant frequency, but is that a guarantee that it does not matter later on? If you overcompensate by a factor of 3 because the upcoming CPU ran at the lowest frequency, then it might become visible later when everything runs at full speed. > However about we half the measure sync_overhead as compensation to avoid > over-estimation, but probably increase the chance that we need a second > adjustment of TSC wrap. Half of what? > With this patch applied, the measured overhead on the same CooperLake > system on different reboot runs varies from 104 to 326. Half of something which jumps around? Not convinced. :) Btw: >> Yes, I will try that experiment and report back the results. Could you please do that? I really like to see the data points. It's so sad that we have still to deal with this nonsense just because HW people don't give a damn. Thanks, tglx