From nobody Mon Feb 9 16:47:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1612875339; cv=none; d=zohomail.com; s=zohoarc; b=BzEUFBYeuEpUTpFRbSGvTkAYPvGlCtqdl5CUztCkeabW6aOfupCIWUO1kXELWw8B7I9KUL4B3BoluI/JnmB63vI1sT/seRkmCZYgBoFRDq0oofSHsIdbZObzdNvMOHv4Oggnstk8rfVdJxIBcnO4heDlKXtRvPT/aPfzENjlh1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612875339; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Wj3LF6N3hDpyMxGowUzNE8QQ+tNIwy9wVm4fwaEKDOE=; b=M06BzpnfNu2A3JqjiG7l6SRsDAoaNAtVWfSB03QsxC0nrmBIv3HNoNxk2ohnGfo2Iscu9kze8Up0E60618OJ4fVl0KwOfSNs3+3w8zs0nCJuCgLZzEhQcEs228PD4fy3PuGCsR2BmksmQQgwAddsXJ+85DKzvUZ0ewXEyVXAzMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612875338649584.6290434060986; Tue, 9 Feb 2021 04:55:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83221.154316 (Exim 4.92) (envelope-from ) id 1l9SY8-0007kv-07; Tue, 09 Feb 2021 12:55:24 +0000 Received: by outflank-mailman (output) from mailman id 83221.154316; Tue, 09 Feb 2021 12:55:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l9SY7-0007ko-TC; Tue, 09 Feb 2021 12:55:23 +0000 Received: by outflank-mailman (input) for mailman id 83221; Tue, 09 Feb 2021 12:55:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l9SY6-0007kd-39 for xen-devel@lists.xenproject.org; Tue, 09 Feb 2021 12:55:22 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e30d3eeb-2174-45f1-8bad-e6cc0e4db328; Tue, 09 Feb 2021 12:55:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 36B88AF7B; Tue, 9 Feb 2021 12:55:20 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e30d3eeb-2174-45f1-8bad-e6cc0e4db328 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612875320; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wj3LF6N3hDpyMxGowUzNE8QQ+tNIwy9wVm4fwaEKDOE=; b=vHpsQ5Aw3nml/+0jP8BUWaK7WUZklTEIBFXQy//AlIp4Tz0krwYW650znhIxTqU3UVo/6G vat7dW0J0gMTpYXSp4cMmVREXTQxSzOzmQ5NZGABwINBmH8cTtLi4CJMoOyOfRT2RCxi7s Z32QdGSq6yNxYkGGg/X45DkRyfA9uVU= Subject: [PATCH v3 2/4] x86/time: adjust time recording in time_calibration_tsc_rendezvous() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Claudemir Todo Bom , Ian Jackson References: Message-ID: <834b2d29-2589-f2b7-b496-7f1b35d35cff@suse.com> Date: Tue, 9 Feb 2021 13:55:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) The (stime,tsc) tuple is the basis for extrapolation by get_s_time(). Therefore the two better get taken as close to one another as possible. This means two things: First, reading platform time is too early when done on the first iteration. The closest we can get is on the last iteration, immediately before telling other CPUs to write their TSCs (and then also writing CPU0's). While at the first glance it may seem not overly relevant when exactly platform time is read (when assuming that only stime is ever relevant anywhere, and hence the association with the precise TSC values is of lower interest), both CPU frequency changes and the effects of SMT make it unpredictable (between individual rendezvous instances) how long the loop iterations will take. This will in turn lead to higher an error than neccesary in how close to linear stime movement we can get. Second, re-reading the TSC for local recording is increasing the overall error as well, when we already know a more precise value - the one just written. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- v2: New. --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1662,11 +1662,12 @@ struct calibration_rendezvous { }; =20 static void -time_calibration_rendezvous_tail(const struct calibration_rendezvous *r) +time_calibration_rendezvous_tail(const struct calibration_rendezvous *r, + uint64_t tsc) { struct cpu_time_stamp *c =3D &this_cpu(cpu_calibration); =20 - c->local_tsc =3D rdtsc_ordered(); + c->local_tsc =3D tsc; c->local_stime =3D get_s_time_fixed(c->local_tsc); c->master_stime =3D r->master_stime; =20 @@ -1691,11 +1692,11 @@ static void time_calibration_tsc_rendezv while ( atomic_read(&r->semaphore) !=3D (total_cpus - 1) ) cpu_relax(); =20 - if ( r->master_stime =3D=3D 0 ) - { - r->master_stime =3D read_platform_stime(NULL); + if ( r->master_tsc_stamp =3D=3D 0 ) r->master_tsc_stamp =3D rdtsc_ordered(); - } + else if ( i =3D=3D 0 ) + r->master_stime =3D read_platform_stime(NULL); + atomic_inc(&r->semaphore); =20 if ( i =3D=3D 0 ) @@ -1720,7 +1721,7 @@ static void time_calibration_tsc_rendezv } } =20 - time_calibration_rendezvous_tail(r); + time_calibration_rendezvous_tail(r, r->master_tsc_stamp); } =20 /* Ordinary rendezvous function which does not modify TSC values. */ @@ -1745,7 +1746,7 @@ static void time_calibration_std_rendezv smp_rmb(); /* receive signal /then/ read r->master_stime */ } =20 - time_calibration_rendezvous_tail(r); + time_calibration_rendezvous_tail(r, rdtsc_ordered()); } =20 /*