From owner-freebsd-arch Sat Feb 16 22:32:28 2002 Delivered-To: freebsd-arch@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id 21D7C37B405; Sat, 16 Feb 2002 22:32:24 -0800 (PST) Received: (from dillon@localhost) by apollo.backplane.com (8.11.6/8.9.1) id g1H6WGt43386; Sat, 16 Feb 2002 22:32:16 -0800 (PST) (envelope-from dillon) Date: Sat, 16 Feb 2002 22:32:16 -0800 (PST) From: Matthew Dillon Message-Id: <200202170632.g1H6WGt43386@apollo.backplane.com> To: Terry Lambert Cc: Julian Elischer , Alfred Perlstein , Poul-Henning Kamp , 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? ) References: <3C6F0A13.258882FF@mindspring.com> Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 :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