From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo6.mail-out.ovh.net (1.mo6.mail-out.ovh.net [46.105.56.136]) by dpdk.org (Postfix) with ESMTP id 5E5FC5320 for ; Fri, 24 Jan 2014 12:44:23 +0100 (CET) Received: from mail625.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo6.mail-out.ovh.net (Postfix) with SMTP id 1948FFF8F2E for ; Fri, 24 Jan 2014 12:50:17 +0100 (CET) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 24 Jan 2014 13:44:55 +0200 Received: from lneuilly-152-23-9-75.w193-252.abo.wanadoo.fr (HELO pcdeff) (ff@ozog.com@193.252.40.75) by ns0.ovh.net with SMTP; 24 Jan 2014 13:44:54 +0200 From: =?iso-8859-1?Q?Fran=E7ois-Fr=E9d=E9ric_Ozog?= To: "'Didier Pallard'" , References: <1390562277-24769-1-git-send-email-didier.pallard@6wind.com> In-Reply-To: <1390562277-24769-1-git-send-email-didier.pallard@6wind.com> Date: Fri, 24 Jan 2014 12:42:47 +0100 Message-ID: <00d201cf18f9$67cdaf10$37690d30$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac8Y9faUhZo8lv5sQE2EhJsA/kDo/AAASJOg Content-Language: fr X-Ovh-Tracer-Id: 5923922361463986393 X-Ovh-Remote: 193.252.40.75 (lneuilly-152-23-9-75.w193-252.abo.wanadoo.fr) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -100 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejtddrheegucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejtddrheegucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Subject: Re: [dpdk-dev] [PATCH] timer: add lfence before TSC read 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: Fri, 24 Jan 2014 11:44:23 -0000 Hi, Most of the time rdtsc is used for timestamping and a few cycles = incorrect are most of the time not an issue (a precision of 0.1us for session = start is usually enough). Sometimes you need to serialize because the time you want to measure is = very short, in the order of few nanoseconds. If the code is running in a VM, which usually virtualize rdtsc = instruction, then it even make no sense to have more "precision". IMHO, adding the lfence for all cases is introducing an un-necessary performance penalty. What about adding rte_rdtsc_sync() or rte_rdtsc_serial() with the = comment about the rdtsc instruction behavior so that developers can choose which form they want? Fran=E7ois-Fr=E9d=E9ric > -----Message d'origine----- > De=A0: dev [mailto:dev-bounces@dpdk.org] De la part de Didier Pallard > Envoy=E9=A0: vendredi 24 janvier 2014 12:18 > =C0=A0: dev@dpdk.org > Objet=A0: [dpdk-dev] [PATCH] timer: add lfence before TSC read >=20 > According to Intel Developer's Manual: >=20 > "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." >=20 > So add a lfence instruction before rdtsc to synchronize read = operations and > ensure that the read is done at the expected instant. >=20 > Signed-off-by: Didier Pallard > --- > lib/librte_eal/common/include/rte_cycles.h | 3 +++ > 1 file changed, 3 insertions(+) >=20 > diff --git a/lib/librte_eal/common/include/rte_cycles.h > b/lib/librte_eal/common/include/rte_cycles.h > index cc6fe71..487dba6 100644 > --- a/lib/librte_eal/common/include/rte_cycles.h > +++ b/lib/librte_eal/common/include/rte_cycles.h > @@ -110,6 +110,9 @@ rte_rdtsc(void) > }; > } tsc; >=20 > + /* serialize previous load instructions in pipe */ > + asm volatile("lfence"); > + > #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT > if (unlikely(rte_cycles_vmware_tsc_map)) { > /* ecx =3D 0x10000 corresponds to the physical TSC for VMware */ > -- > 1.7.10.4