From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 15F8845A9E; Wed, 2 Oct 2024 19:12:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 001184060B; Wed, 2 Oct 2024 19:11:59 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by mails.dpdk.org (Postfix) with ESMTP id 6047C402E9 for ; Wed, 2 Oct 2024 19:11:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727889119; x=1759425119; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=sFl/SJqqv1vZFPQCxibezk63B2A45/6KuhRPr5VHZhM=; b=WU2zWrKY2IHWodCm/9ghYBRvVT7gIiTUyhz73DxvG6QkMuZedmB3Btld 7bCNG/1tV/UuKjCFaPx9/xlmWk68TXX0NXKw+0D/8tMWhbSUhf5eTBb7x nJlkiuB76DGRtcBGpUxPMncRh9K3GfzQnvJYui+q+KKBkE7hPF/WyJy2s BMVPuV2jUccalJxQbTzqUMSZeysuu79W4sRWxZCUKubua7Vapvx5gxMY1 4nz7hJijU89ouDbBPucGWDB7j5HcMHMvO2ehSk6Lob//EAwWYBvYQBW3D Bc+5IBXBNyOf0kA8qOTSb2xX4hpB4SBEbi3D5xsi/MesZlREqS2S0yZsY w==; X-CSE-ConnectionGUID: uLuke5R+QDOPG+Fe6bM1OQ== X-CSE-MsgGUID: k+uHP04BQ86QqZhSwStM8A== X-IronPort-AV: E=McAfee;i="6700,10204,11213"; a="27217900" X-IronPort-AV: E=Sophos;i="6.11,172,1725346800"; d="scan'208";a="27217900" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2024 10:11:57 -0700 X-CSE-ConnectionGUID: VJ218ppxRpSVRdhokmvlBA== X-CSE-MsgGUID: 1XicSH4bTqmTdcvxe15u8Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,172,1725346800"; d="scan'208";a="104876021" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 02 Oct 2024 10:11:57 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 2 Oct 2024 10:11:56 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 2 Oct 2024 10:11:56 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 2 Oct 2024 10:11:56 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Wed, 2 Oct 2024 10:11:56 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.49) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 2 Oct 2024 10:11:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AUwBx96FZyh49sYB8700SrP966FpnS+nmf1ygRUX8YOM9o2OguCW6cdcup6HYvpUTMbx+/NmsyFokJkJUUXyeWLqFTYgDju97dpyjHpJqn3PEFnQl3oREgMFg/2MxjSh951YqKepVxoZa7wGsFgA0nedaD4XSZRLQ93ZZDx48KeE7pKkHdGxRFEyaejtsMbrNY1CQ8vQxuoezznZYIOrofwpuamebcQe6e9tINKUm8lz9aVNv2jcbYA9CGemnlAwj1iLdvYe3M39A/VKwatOKbmHYOsn0SdUmCmpmzSSjKywTQWK7M9hnKFJlJoHK4fjj3CyrH21zWwyhQYGfLfPJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lugeQkQeg1yCuKiHTSHcil2uOvVDehJFLJ/sRa4aRfc=; b=Y5pxQBdvj0z+uHfXmlIKDYA6LqrgqePYI9OEc+Q8zzVvzsDCQ1hjKlunTgsrkIjZ+eHMr+bjvNhoprWugK47kODAWl5H8Nvk5KekWKDXBVUm/4N5+HqqYen3w0yDxXqqJukY6qVNklM/wb1/RU9R92fFGQsckHoFkLgG4EVyqc6zI9meUUo0idALZChVrVRb9dlKopX5+FEj6POogzlpUsRJrM/UWEevcmUPpjHxrlWiYYxz1mxer6D39bjWrGSsfNLQN5X0oTbCj+XJ0bI0zmkygasmwwL73ifK9HBo7UyOlWwt6nokH82khZTxcYXmhWQhiik23QEtw5oSghMKyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by SN7PR11MB7465.namprd11.prod.outlook.com (2603:10b6:806:34e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.29; Wed, 2 Oct 2024 17:11:53 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::f120:cc1f:d78d:ae9b]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::f120:cc1f:d78d:ae9b%4]) with mapi id 15.20.8026.014; Wed, 2 Oct 2024 17:11:53 +0000 Date: Wed, 2 Oct 2024 18:11:47 +0100 From: Bruce Richardson To: Isaac Boukris CC: , , , , Subject: Re: [PATCH v4 2/2] timer: allow platform to override cpu TSC frequency Message-ID: References: <20240921140022.107239-1-iboukris@gmail.com> <20241002165840.341116-1-iboukris@gmail.com> <20241002165840.341116-3-iboukris@gmail.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20241002165840.341116-3-iboukris@gmail.com> X-ClientProxiedBy: DU7P190CA0008.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:550::26) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|SN7PR11MB7465:EE_ X-MS-Office365-Filtering-Correlation-Id: 66dbf494-3ce8-461d-3d73-08dce3054f8f X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?NAspspeov5+ql+4Vl/oXaq00F33u+51xebQliOJPIOUnitXJTSnzcCKOAEjs?= =?us-ascii?Q?1ENqZAgcSZ0ZKqY0+xd12BCvk/TrBRqOfZQ9sjRLObVm4IlT2wC0tBqycsP/?=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m2hlrOKoC/rI+jcT8FWK?= =?us-ascii?Q?GsZYRLHlUPGScfXMSb8Fs0cJzbotDePUBWhogQhKikMDf7JzhB6ovgkWHal0?= =?us-ascii?Q?hgqZbUJNUHXynUi1l1ZGFrqv7I/JU6vg7cccZVm0tZJhWRhVFqmsDUpiIJX7?= =?us-ascii?Q?TWkGeoa4zWeXys7LrJ6apZOztV+z72RzOmu0TI+1sY/IERXQE4G4qAbijrvZ?= =?us-ascii?Q?KG5I5DrTkV4w4wI1mXcoCgJbsvYtZ/FYSVlTlVg6Su/b1gbKsIumK0nTGLQ8?= =?us-ascii?Q?JSjb9hBAtqal/1c+k+8L4i8wZMwCbBJIQAOzp81JHQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gV0pMfjbJ3EL9hs4Onyl45Zo0/gyFzILvoGwoHHOC9/66Aw8LSrYKNN2ZGb9?= =?us-ascii?Q?snkRPJIYtSzCPM7aJ6p9fGLYaEG/VW9u6+ugnavto2/4/GEVXW8h83QgLJRJ?= =?us-ascii?Q?g+6cDCOeOTB2OyL9GzWT954NfbRXFMwsyhpGTUHn/SP7jgb03Nufg1c4qjOh?= =?us-ascii?Q?WwehgIcdK+iSjAEBKwDTW62iE9gfEyFugwCgrxLJwrIB+fLA9KHADL7JJZz3?= =?us-ascii?Q?X3X6L/CGoUWpuRVYcSjqxw9PbvtbOSxI/bHIgRIvqeebiBsQRWNIP0S+X2RE?= =?us-ascii?Q?oVHKbUXSq9OuoQxFaeZnCDaP037buvExDSQ/C3FU/0DgB7nF14cfNUbf8EI+?= =?us-ascii?Q?7d20Bu+laHT0jWplm9MzEYECC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?Q?n43BPTNlAC2jSKHwmdYNGuTUVR23EJ0ljkVeXSKmrWH9DdpF/FKk2KbFVrNe?= =?us-ascii?Q?CrNNzXYcVCizryrdnq5Z+O+Q8A12GTaJ9V0K1neBj7WFUy3Foh8hIaaRQi5+?= =?us-ascii?Q?a7iYrdoPsS0fcMJ58/9fiqoXmXldywpcroRU05cScDcUQ+Ltqjo9Rmk4pxtD?= =?us-ascii?Q?PtS5mAmF+TABw5Z0Zb2f1A9HA0VI8idghCH/1nWv2EIs7s6AaFWi76LPs3Pq?= =?us-ascii?Q?bUHcTV5KZzG1sDRlJWt0Yz0kql3vOhBAi8eSoYa1V5IxKvGEaqpsRNnXASwF?= =?us-ascii?Q?FpoBBHVQBhN11+YmUfOT2OxM0Rqy+TJIwvJcil6y2pceKjc9OPNhNTd26dRJ?= =?us-ascii?Q?ag=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 66dbf494-3ce8-461d-3d73-08dce3054f8f X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 17:11:53.0329 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RHiH022pfJoyxuJWP7uQfJhcHcO4HEnHcvu0jaPeRz3noUBZ3qoVgFIS4NKe6ZeiWrles5WpMLbGmA+PpAS4NwrBdAl/wIlzKQQJuqDZ5Pc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB7465 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Oct 02, 2024 at 07:56:36PM +0300, Isaac Boukris wrote: > The CPU value is often not accurate, allow overriding it based > on info from the host OS. > > On Linux X86, if the tsc_known_freq cpu flag is missing, it means > the kernel doesn't trust it and calculates its own. We should do > the same to avoid drift. > > On freebsd we have access to the kernel tsc_hz value, just use it. > > Signed-off-by: Isaac Boukris > --- Looks good to me. Hope to test it out soon on my systems to see how it goes. One comment inline below. /Bruce > lib/eal/common/eal_common_timer.c | 3 +- > lib/eal/common/eal_private.h | 2 +- > lib/eal/freebsd/eal_timer.c | 8 +++-- > lib/eal/linux/eal_timer.c | 53 +++++++++++++++++++++++++++++-- > lib/eal/windows/eal_timer.c | 5 ++- > 5 files changed, 62 insertions(+), 9 deletions(-) > > diff --git a/lib/eal/common/eal_common_timer.c b/lib/eal/common/eal_common_timer.c > index c5c4703f15..e00be0a5c8 100644 > --- a/lib/eal/common/eal_common_timer.c > +++ b/lib/eal/common/eal_common_timer.c > @@ -66,8 +66,7 @@ set_tsc_freq(void) > } > > freq = get_tsc_freq_arch(); > - if (!freq) > - freq = get_tsc_freq(); > + freq = get_tsc_freq(freq); > if (!freq) > freq = estimate_tsc_freq(); > > diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h > index af09620426..bb315dab04 100644 > --- a/lib/eal/common/eal_private.h > +++ b/lib/eal/common/eal_private.h > @@ -374,7 +374,7 @@ void set_tsc_freq(void); > * > * This function is private to the EAL. > */ > -uint64_t get_tsc_freq(void); > +uint64_t get_tsc_freq(uint64_t arch_hz); > > /** > * Get TSC frequency if the architecture supports. > diff --git a/lib/eal/freebsd/eal_timer.c b/lib/eal/freebsd/eal_timer.c > index 3dd70e24ba..19fc9a7228 100644 > --- a/lib/eal/freebsd/eal_timer.c > +++ b/lib/eal/freebsd/eal_timer.c > @@ -26,7 +26,7 @@ > enum timer_source eal_timer_source = EAL_TIMER_TSC; > > uint64_t > -get_tsc_freq(void) > +get_tsc_freq(uint64_t arch_hz) > { > size_t sz; > int tmp; > @@ -50,9 +50,13 @@ get_tsc_freq(void) > sz = sizeof(tsc_hz); > if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) { > EAL_LOG(WARNING, "%s", strerror(errno)); > - return 0; > + return arch_hz; > } > > + if (arch_hz && arch_hz - tsc_hz > arch_hz / 100) Do we not need an "abs()" call on the "arch_hz - tsc_hz" in case tsc_hz is the bigger value?