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 3E28145980 for ; Thu, 19 Sep 2024 00:04:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E96C240156; Thu, 19 Sep 2024 00:04:52 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 624F24003C for ; Thu, 19 Sep 2024 00:04:52 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-206aee4073cso2497605ad.1 for ; Wed, 18 Sep 2024 15:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726697091; x=1727301891; darn=dpdk.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=7zOreQzauvv1vN0h0Ose+QGKXdxav6FyaQw/0FNV0b4=; b=LLHEfPIFdPHK5V4IcA3PwJ0JSLYIpWEW79aVMrrfLqwWVqFY1phuCD4MYLE1WYAi4q zEecLYsFHeC4Iz5fVRf+DBwE+z3WB5miWKHeFaYMf3qhnOkpJDAmwTn9cZGkJvzU7K33 jGFdleio2l6nnU0nLGGe3wJsTMZECAW6Fu9iQfUk+un1UA8rxXUx1ryD96s2PwdsoTDQ Ny7GsJdms7vtVx4WsKnWa+WuR9zabuS7zdPhim2+N3vKD5mh288MHqOy7TwloNoCapDC pADlEI6bPDnB+4B4YYy6xgb2aUriV8ijUrg9TJ/BzTEi+l810H698ULmM4Hygr04Nua7 xIOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726697091; x=1727301891; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7zOreQzauvv1vN0h0Ose+QGKXdxav6FyaQw/0FNV0b4=; b=P4fq2iVTxqmlqEpqNa56MVnYPAUmdXetRpzhuI5G1+kAuA6Z6UjdN8h02g1e1Qmccw ycEhYjJ1/ks5fvpkzXz7ufLd14GGzTVJ3MSv5eOK8BveYyT/WsTt9q+LEGdS0hqNPEE9 Wz/iEFE5hb9H3oprgjdR5R78JQ/tTAHYNIj3SGCU8k87KCbuDlwnViJdqrjzlSfb0BGn QauNjqox3w8zA7xRiOt7faL6zkmRQI+iZWp4BGCAFqa7AnQHmaJ8wxoA0AyofKfVlM9c 7mlD+my3ob+OC6wO1Fx7V3mZ86r+VTZs+Q1eLjOO9zg6CHmnFfaTqXPk3BKtLt4PeAdY BPLQ== X-Gm-Message-State: AOJu0YwnXbq0ONlB7m1bymRE3d9xymY9tO5Ht7RZiKgWNd8EQwLPTg6j iuWCUtz8yPU/M0Pt9qrXEb1OW4vVza+MkrskavVUvOBtwuNMLBM9Z8oPECQC1iOSikqSpvpX02D 68RJ8rZ1SMubhUWIS/fkQVnvsWwi3jZkn X-Google-Smtp-Source: AGHT+IFk+FYmcaN2jZ9K8DanbSn4nkARPYt7+PADqc5xpjCi7kr4i6/snRi0tqdKLMceH/OvdX6BUEzUddULK5k0XZQ= X-Received: by 2002:a17:902:d48d:b0:206:a277:6152 with SMTP id d9443c01a7336-2076e3f3229mr309489595ad.38.1726697091222; Wed, 18 Sep 2024 15:04:51 -0700 (PDT) MIME-Version: 1.0 From: Isaac Boukris Date: Thu, 19 Sep 2024 01:04:40 +0300 Message-ID: Subject: Accuracy of rte_get_tsc_hz() compared to linux To: users@dpdk.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: users@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK usage discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: users-bounces@dpdk.org Hi, On Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz (see lscpu output at the end). The rte_get_tsc_hz() returns 2100000 KHz but using it causes our timestamps to lag behind real time (roughly a sec per 10 min). I noticed the kernel uses 2095082 KHz and in fact it gives much better results. dmesg: tsc: Detected 2095.082 MHz processor tsc_freq_khz (custom kmod to exposes kernel's tsc_khz): cat /sys/devices/system/cpu/cpu0/tsc_freq_khz 2095082 I changed the dpdk code to print more when it initializes eal_tsc_resolution_hz and lowered the rounding of the estimations, as follows: git diff diff --git a/lib/eal/common/eal_common_timer.c b/lib/eal/common/eal_common_timer.c index c5c4703f15..faf1efc90f 100644 --- a/lib/eal/common/eal_common_timer.c +++ b/lib/eal/common/eal_common_timer.c @@ -38,7 +38,7 @@ rte_get_tsc_hz(void) static uint64_t estimate_tsc_freq(void) { -#define CYC_PER_10MHZ 1E7 +#define CYC_PER_10MHZ 1E3 EAL_LOG(WARNING, "WARNING: TSC frequency estimated roughly" " - clock timings may be less accurate."); /* assume that the rte_delay_us_sleep() will sleep for 1 second */ @@ -71,6 +71,10 @@ set_tsc_freq(void) if (!freq) freq = estimate_tsc_freq(); + EAL_LOG(DEBUG, "TSC frequency arch ~%" PRIu64 " KHz", get_tsc_freq_arch() / 1000); + EAL_LOG(DEBUG, "TSC frequency linux ~%" PRIu64 " KHz", get_tsc_freq() / 1000); + EAL_LOG(DEBUG, "TSC frequency estimate ~%" PRIu64 " KHz", estimate_tsc_freq() / 1000); + EAL_LOG(DEBUG, "TSC frequency is ~%" PRIu64 " KHz", freq / 1000); eal_tsc_resolution_hz = freq; mcfg->tsc_hz = freq; diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1cb1e92193..9254c901b8 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -192,9 +192,9 @@ get_tsc_freq(void) { #ifdef CLOCK_MONOTONIC_RAW #define NS_PER_SEC 1E9 -#define CYC_PER_10MHZ 1E7 +#define CYC_PER_10MHZ 1E3 - struct timespec sleeptime = {.tv_nsec = NS_PER_SEC / 10 }; /* 1/10 second */ + struct timespec sleeptime = {.tv_sec = 1 }; /* 1/10 second */ struct timespec t_start, t_end; uint64_t tsc_hz; I've run the helloworld application on an isolated cpu: taskset -c 10 ./dpdk-helloworld --log-level=lib.eal:debug --no-huge The results are: EAL: TSC frequency arch ~2100000 KHz EAL: TSC frequency linux ~2095082 KHz EAL: TSC frequency estimate ~2095346 KHz The arch one is picked, which seems rather wrong, any way to override that? Should we lower the estimation rounding to 1MHz or even 1KHz in the linux one? Thoughts? Thanks! Kernel: 4.18.0-513.9.1.el8_9.x86_64 lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 64 On-line CPU(s) list: 0-63 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel BIOS Vendor ID: Intel(R) Corporation CPU family: 6 Model: 85 Model name: Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz BIOS Model name: Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz Stepping: 4 CPU MHz: 2100.000 BogoMIPS: 4200.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 1024K L3 cache: 22528K NUMA node0 CPU(s): 0-15,32-47 NUMA node1 CPU(s): 16-31,48-63 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke md_clear flush_l1d arch_capabilities