Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Jun 2012 16:38:40 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: Fwd: [RFC] Kernel shared variables
Message-ID:  <20120605133840.GK85127@deviant.kiev.zoral.com.ua>
In-Reply-To: <201206041722.07269.jhb@freebsd.org>
References:  <CACfq090r1tWhuDkxdSZ24fwafbVKU0yduu1yV2%2BoYo%2BwwT4ipA@mail.gmail.com> <201206041101.57486.jhb@freebsd.org> <20120604181917.GD85127@deviant.kiev.zoral.com.ua> <201206041722.07269.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--PEfPc/DjvCj+JzNg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jun 04, 2012 at 05:22:07PM -0400, John Baldwin wrote:
> On Monday, June 04, 2012 2:19:17 pm Konstantin Belousov wrote:
> > On Mon, Jun 04, 2012 at 11:01:57AM -0400, John Baldwin wrote:
> > > On Sunday, June 03, 2012 6:49:27 am Bruce Evans wrote:
> > > > On Sun, 3 Jun 2012, Konstantin Belousov wrote:
> > > >=20
> > > > > On Sun, Jun 03, 2012 at 07:28:09AM +1000, Bruce Evans wrote:
> > > > >> On Sat, 2 Jun 2012, Konstantin Belousov wrote:
> > > > >>> ...
> > > > >>> In fact, I think that if the whole goal is only fast clocks, th=
en we
> > > > >>> do not need any additional system mechanisms, since we can easi=
ly export
> > > > >>> coefficients for rdtsc formula already. E.g. we can put it into=
 elf auxv,
> > > > >>> which is ugly but bearable.
> > > > >>
> > > > >> How do you get the timehands offsets?  These only need to be upd=
ated
> > > > >> every second or so, or when used, but how can the application kn=
ow
> > > > >> when they need to be updated if this is not done automatically i=
n the
> > > > >> kernel by writing to a shared page?  I can only think of the
> > > > >> application arranging an alarm signal every second or so and upd=
ating
> > > > >> then.  No good for libraries.
> > > > > What is timehands offsets ? Do you mean things like leap seconds ?
> > > >=20
> > > > Yes.  binuptime() is:
> > > >=20
> > > > % void
> > > > % binuptime(struct bintime *bt)
> > > > % {
> > > > % 	struct timehands *th;
> > > > % 	u_int gen;
> > > > %=20
> > > > % 	do {
> > > > % 		th =3D timehands;
> > > > % 		gen =3D th->th_generation;
> > > > % 		*bt =3D th->th_offset;
> > > > % 		bintime_addx(bt, th->th_scale * tc_delta(th));
> > > > % 	} while (gen =3D=3D 0 || gen !=3D th->th_generation);
> > > > % }
> > > >=20
> > > > Without the kernel providing th->th_offset, you have to do lots of =
ntp
> > > > handling for yourself (compatibly with the kernel) just to get an
> > > > accuracy of 1 second.  Leap seconds don't affect CLOCK_MONOTONIC, b=
ut
> > > > they do affect CLOCK_REALTIME which is the clock id used by
> > > > gettimeofday().  For the former, you only have to advance the offset
> > > > for yourself occasionally (compatibly with the kernel) and manage
> > > > (compatibly with the kernel, especially in the long term) ntp slewi=
ng
> > > > and other syscall/sysctl kernel activity that micro-adjusts th->th_=
scale.
> > >=20
> > > I think duplicating this logic in userland would just be wasteful.  I=
 have
> > > a private fast gettimeofday() at my current job and it works by expor=
ting
> > > the current timehands structure (well, the equivalent) to userland.  =
The
> > > userland bits then fetch a copy of the details and do the same as bin=
time().
> > > (I move the math (bintime_addx() and the multiply)) out of the loop h=
owever.
> > I started yesterday an implementation which uses shared page to export
> > some variant of timehands, and uses auxv to provide the libc with a poi=
nter
> > to timehands when rdtsc is reasonable.
> >=20
> > I almost finished both 32bit and 64bit userspace, but there is
> > kernel-side work left. Is your implementation ready or close to be ready
> > for commit ? In other words, should I drop the efforts, or continue ?
>=20
> No, mine is not general purpose.  I'll see if I can make a public patch o=
f what
> it looks like.

My first version that seems to work on amd64 is at
http://people.freebsd.org/~kib/misc/moronix.1.patch

The plugs do allow for the new gettimeofday code to be replaced by
vdso version in future.

This is definitely WIP, in particular, the memory barriers handling in
the __vdso_gettimeofday and in the tc_windup updater is missing.
Also, clock_gettime() support would require ABI change.

I only compiled amd64 kernel, i386 is probably broken, other architectures
are definitely broken.

--PEfPc/DjvCj+JzNg
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk/OC+AACgkQC3+MBN1Mb4gFvgCg7kdxK3EZJGiLz8SDf3/xTkEg
XA8An0Mb5+KWdwgLW+SjCaI7UFY3ufJS
=Ev9z
-----END PGP SIGNATURE-----

--PEfPc/DjvCj+JzNg--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605133840.GK85127>