From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by dpdk.org (Postfix) with ESMTP id 001AE68DD for ; Wed, 19 Feb 2014 17:44:56 +0100 (CET) Received: by mail-wi0-f176.google.com with SMTP id hi5so4906533wib.15 for ; Wed, 19 Feb 2014 08:46:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=eEe2U2LJPHVZGYJkFiNbkyneLAk0yc5K1w8Ww4Byrys=; b=V4yvMeF74oZmWOjJQsIQSnPz5VFAcs8rQW7D4tHzTZ/ODQ9/6C2IXkYjsSyGDq1jxR Gi7yqm9K0y1Gnk93d0laEQBotWbXZ8TbQxKZry9fnlQcaRjexfXG9X2IX2CN03miyJgE VS9e21VK+uYIRgHCn1QyI2WfCB2l7tiI5o+o9a9UN9mhs9b7D+vTvCAVRMWTMnsFD5/n +K79bEGl9qySGZL5QtoF/TI/O1Ea1fE6APhCniRHH4WIGy6d5CqzmxOtpWo0v9l5cXca ulh6aen0lpldOq4y3Spg09E7tajfkQzwVQAaaf3LmLcKx/diTN6yUVeB9FrlEANIY5bL kpog== X-Gm-Message-State: ALoCoQlf+DCFbEJpBsHJHxYbCaAwT62YLPAr8BqyPd5gItpDca7VcsjTYUYj4W3hDKmjcKYlUwmx X-Received: by 10.180.149.206 with SMTP id uc14mr2593596wib.10.1392828381447; Wed, 19 Feb 2014 08:46:21 -0800 (PST) Received: from pala.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id xt1sm1787931wjb.17.2014.02.19.08.46.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Feb 2014 08:46:20 -0800 (PST) From: Didier Pallard To: dev@dpdk.org Date: Wed, 19 Feb 2014 17:46:08 +0100 Message-Id: <1392828368-8563-1-git-send-email-didier.pallard@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1392809945-28025-1-git-send-email-didier.pallard@6wind.com> References: <1392809945-28025-1-git-send-email-didier.pallard@6wind.com> Subject: [dpdk-dev] [PATCH v3] timer: add new rte_rdtsc_precise function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Feb 2014 16:44:57 -0000 According to Intel Developer's Manual: "The RDTSC instruction is not a serializing instruction. It does not necessarily wait until all previous instructions have been executed before reading the counter. Simi- larly, subsequent instructions may begin execution before the read operation is performed. If software requires RDTSC to be executed only after all previous instruc- tions have completed locally, it can either use RDTSCP (if the processor supports that instruction) or execute the sequence LFENCE;RDTSC." So add a rte_rdtsc_precise function that do a memory barrier before rdtsc to synchronize operations and ensure that the TSC read is done at the expected place. Signed-off-by: Didier Pallard --- Call rte_mb() and rte_rdtsc() rather than duplicating rte_rdtsc function. Use r/w memory barrier instead of lfence to serialize both load and stores. lib/librte_eal/common/include/rte_cycles.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/librte_eal/common/include/rte_cycles.h b/lib/librte_eal/common/include/rte_cycles.h index cc6fe71..e91edf8 100644 --- a/lib/librte_eal/common/include/rte_cycles.h +++ b/lib/librte_eal/common/include/rte_cycles.h @@ -76,6 +76,7 @@ extern "C" { #include #include +#include #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT /** Global switch to use VMWARE mapping of TSC instead of RDTSC */ @@ -128,6 +129,19 @@ rte_rdtsc(void) } /** + * Read the TSC register precisely where function is called. + * + * @return + * The TSC for this lcore. + */ +static inline uint64_t +rte_rdtsc_precise(void) +{ + rte_mb(); + return(rte_rdtsc()); +} + +/** * Get the measured frequency of the RDTSC counter * * @return -- 1.7.10.4