Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Feb 2002 22:32:16 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Julian Elischer <julian@elischer.org>, Alfred Perlstein <bright@mu.org>, Poul-Henning Kamp <phk@critter.freebsd.dk>, arch@FreeBSD.ORG, jhb@FreeBSD.ORG, peter@wemm.org, jake@locore.ca
Subject:   Re: gettimeofday() and crhold()/crfree() (was Re: gettimeofday()and  copyout(). Is copyout() MPSAFE on non-i386 archs? )
Message-ID:  <200202170632.g1H6WGt43386@apollo.backplane.com>
References:  <Pine.BSF.4.21.0202161647070.39539-200000@InterJet.elischer.org> <3C6F0A13.258882FF@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
    Well, this is really more of a side-converstaion, but in general I agree.
    Still, if we construct a global userspace-accessible page we have to
    be *very* careful about future backwards compatibility.  Consider what
    would have happened if, say, BSDI used this trick and we had to support
    it in our emulation code?  Or Linux, or NetBSD, etc...

    So, I'm all for it, as long as we do it right:  Have a system call that
    returns the address of specific elements of the shared page.  e.g.
    something like:

	time_t *t = system_pointer(SYSPTR_TIME_32);

    libc could store it in a global and should be able to handle a SYSPTR_BAD
    return (meaning that the requested entity is not supported as a shared
    memory variable, for example due to being too large for atomic access
    and to make emulation easier).  This also gives us flexibility in regards
    to where and when the page is mapped.

    Here is a quick example (assuming no user-level sysinit mechanism):

    time_t
    libc_time(time_t *t)
    {
	static time_t *tptr;
	if (tptr == NULL)
	    tptr = system_pointer(SYSPTR_TIME_32);
	else if (tptr != SYSPTR_BAD)
	    *t = *tptr;
	else
	    *t = time(NULL);
	return(*t);
    }

    Something like this would be trivial to emulate (one just makes the
    system call always return SYSPTR_BAD) in a compatible way and we wouldn't
    have to worry about structural position changes.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>

:This whole cred thing on gettimeofday is silly.
:
:I was able to ensure that the contents of a copy of the
:timecounter context struct were rotated between two
:buffers with an atomic pointer update, each time they
:were updated.
:
:I really don't understand the need for a very large
:pool of these things, and I don't really understand
:the need for locking, so long as the pointer change
:is atomic, and the clock update is always handled b y
:a single processor.
:
:By taking this single page, two structure, area, and
:setting up an additional mapping, read-only, with
:the PG_G and PG_U bits set, the pointer can be
:directly dereferenced from user space, providing an
:accurate zero system call "gettimeofday" call (the
:easy part is copying the kernel space code for the
:structure content use to user space).
:
:With the PG_U bit set on the page, the same pointer
:can be used in both user and kernel space to access
:the snapshot structure, so there's no decoherence
:from the change from kernel space copy to user space
:dereference.
:
:Pretty simple, actually.
:
:-- Terry
:
:To Unsubscribe: send mail to majordomo@FreeBSD.org
:with "unsubscribe freebsd-arch" in the body of the message
:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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