From owner-freebsd-arch@FreeBSD.ORG Thu Jun 7 17:28:51 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 635ED106566B; Thu, 7 Jun 2012 17:28:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id F0CF88FC0C; Thu, 7 Jun 2012 17:28:50 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q57HSeLB054444; Thu, 7 Jun 2012 20:28:40 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q57HSd0v030478; Thu, 7 Jun 2012 20:28:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q57HSd4F030477; Thu, 7 Jun 2012 20:28:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 7 Jun 2012 20:28:39 +0300 From: Konstantin Belousov To: John Baldwin Message-ID: <20120607172839.GZ85127@deviant.kiev.zoral.com.ua> References: <20120606165115.GQ85127@deviant.kiev.zoral.com.ua> <201206061423.53179.jhb@freebsd.org> <20120606205938.GS85127@deviant.kiev.zoral.com.ua> <201206070850.55751.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YBGzgpgHAney5ErF" Content-Disposition: inline In-Reply-To: <201206070850.55751.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-arch@freebsd.org Subject: Re: Fast gettimeofday(2) and clock_gettime(2) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2012 17:28:51 -0000 --YBGzgpgHAney5ErF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 07, 2012 at 08:50:55AM -0400, John Baldwin wrote: > On Wednesday, June 06, 2012 4:59:38 pm Konstantin Belousov wrote: > > On Wed, Jun 06, 2012 at 02:23:53PM -0400, John Baldwin wrote: > > > On Wednesday, June 06, 2012 12:51:15 pm Konstantin Belousov wrote: > > > > A positive result from the recent flame-bait on arch@ is the working > > > > implementation of the fast gettimeofday(2) and clock_gettime(2). The > > > > speedup I see is around 6-7x on the 2600K. I think the speedup could > > > > be even bigger on the previous generation of CPUs, where lock > > > > operations and syscall entry are costlier. A sample test runs of > > > > tools/tools/syscall_timing are presented at the end of message. > > >=20 > > > In general this looks good but I see a few nits / races: > > >=20 > > > 1) You don't follow the model of clearing tk_current to 0 while you > > > are updating the structure that the in-kernel timecounter code > > > uses. This also means you have to avoid using a tk_current of 0 > > > and that userland has to keep spinning as long as tk_current is 0. > > > Without this I believe userland can read a partially updated > > > structure. > > I changed the code to be much more similar to the kern_tc.c. I (re)added > > the generation field, which is set to 0 upon kernel touching timehands. >=20 > Thank you. BTW, I think we should use atomic_load_acq_int() on both acce= sses=20 > to th_gen (and the in-kernel binuptime should do the same). I realize th= is > requires using rmb before the while condition in userland since we can't > use atomic_load_acq_int() here. I think it should also use=20 > atomic_store_rel_int() for both stores to th_gen during the tc_windup() > callback. This is done. On the other hand, I removed a store_rel from updating tk_current, since it is after enabling store to th_gen, and the order there does not matter. I also did some restructuring of the userspace, removing layers that Bruce did not liked. Now top-level functions directly call binuptime(). I also shortened the preliminary operations by caching timekeep pointer. Its double-initialization is safe. Latest version is at http://people.freebsd.org/~kib/misc/moronix.4.patch I probably move all shared page helpers to separate file from kern_exec.c, but this will happen after moronix is committed. --YBGzgpgHAney5ErF Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk/Q5McACgkQC3+MBN1Mb4goxQCg1CEB9/qDJ7WNNVdNleSpqiUS kZwAniRrYMNQOjHycMeeoCOu4ixtChdl =j52Z -----END PGP SIGNATURE----- --YBGzgpgHAney5ErF--