From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 3 21:19:51 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F2942E7F for ; Wed, 3 Jun 2015 21:19:50 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 670021DD9 for ; Wed, 3 Jun 2015 21:19:50 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id A11C92A1962; Wed, 3 Jun 2015 23:19:51 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id kFzVZ2y9VEOV; Wed, 3 Jun 2015 23:19:49 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 412212A1989; Wed, 3 Jun 2015 23:19:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id VGFvs_SJzERH; Wed, 3 Jun 2015 23:19:49 +0200 (CEST) Received: from zimbra.eb.localhost (zimbra.eb.localhost [192.168.96.204]) by mail.embedded-brains.de (Postfix) with ESMTP id 26E142A1962; Wed, 3 Jun 2015 23:19:49 +0200 (CEST) Date: Wed, 3 Jun 2015 23:19:49 +0200 (CEST) From: Sebastian Huber To: Konstantin Belousov Cc: freebsd-hackers@freebsd.org, phk@phk.freebsd.dk Message-ID: <2127254638.13127.1433366389045.JavaMail.zimbra@embedded-brains.de> In-Reply-To: <20150603145606.GW2499@kib.kiev.ua> References: <1433331966-27548-1-git-send-email-sebastian.huber@embedded-brains.de> <1433332368-27645-1-git-send-email-sebastian.huber@embedded-brains.de> <20150603145606.GW2499@kib.kiev.ua> Subject: Re: [PATCH v2] timecounters: Fix timehand generation read/write MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.102.3] X-Mailer: Zimbra 8.6.0_GA_1153 (zclient/8.6.0_GA_1153) Thread-Topic: timecounters: Fix timehand generation read/write Thread-Index: d0P9aXUEWAbTrW5w2dcl2/Lw6RzpjQ== X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jun 2015 21:19:51 -0000 ----- Konstantin Belousov schrieb: > On Wed, Jun 03, 2015 at 01:52:48PM +0200, Sebastian Huber wrote: > > The compiler is free to re-order load/store instructions to non-volatil= e > > variables around a load/store of a volatile variable. So the volatile > > generation counter is insufficent. In addition tests on a Freescale > > T4240 platform with 24 PowerPC processors showed that real memory > > barriers are required. Compiler memory barriers are not enough. > >=20 > > For the test the timehand count was reduced to one with 10000 > > tc_windup() calls per second. The timehand memory location was adjuste= d > > so that the th_generation field was on its own cache line. > > --- > >=20 > > v2: Don't use tc_getgen() in tc_windup() since in the only writer there= is no > > need for a read memory barrier. > >=20 > > sys/kern/kern_tc.c | 100 +++++++++++++++++++++++++++++++--------------= -------- > > 1 file changed, 59 insertions(+), 41 deletions(-) > >=20 > > diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c > > index 9dca0e8..bb9614a 100644 > > --- a/sys/kern/kern_tc.c > > +++ b/sys/kern/kern_tc.c > > @@ -71,7 +71,7 @@ struct timehands { > > =09struct timeval=09=09th_microtime; > > =09struct timespec=09=09th_nanotime; > > =09/* Fields not to be copied in tc_windup start with th_generation. *= / > > -=09volatile u_int=09=09th_generation; > > +=09u_int=09=09=09th_generation; > > =09struct timehands=09*th_next; > > }; > > =20 > > @@ -189,6 +189,24 @@ tc_delta(struct timehands *th) > > =09 tc->tc_counter_mask); > > } > > =20 > > +static u_int > > +tc_getgen(struct timehands *th) > > +{ > > +=09u_int gen; > > + > > +=09gen =3D th->th_generation; > > +=09rmb(); > > +=09return (gen); > Why not > =09return (atomic_load_acq_int(&th->th_generation); > ? >=20 > > +} > > + > > +static void > > +tc_setgen(struct timehands *th, u_int newgen) > > +{ > > + > > +=09wmb(); > > +=09th->th_generation =3D newgen; > And there, > =09atomic_store_rel_int(&th->th_generation, newgen); > ? Ok, I will send a second version of the patch next Tuesday. --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber at embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG.