From owner-freebsd-arch Wed Oct 4 18:40:58 2000 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 5E82537B502; Wed, 4 Oct 2000 18:40:53 -0700 (PDT) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.8.7/8.8.7) with ESMTP id MAA07356; Thu, 5 Oct 2000 12:40:20 +1100 Date: Thu, 5 Oct 2000 12:40:16 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Matt Dillon Cc: Peter Wemm , Chuck Paterson , Alfred Perlstein , John Baldwin , arch@FreeBSD.ORG, John Polstra , Daniel Eischen , Greg Lehey Subject: Re: Mutexes and semaphores In-Reply-To: <200010041639.e94GdVR24384@earth.backplane.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, 4 Oct 2000, Matt Dillon wrote: [Writing reordered to reply after quoted material] [Peter Wemm wrote] > :int > :getppid(p, uap) > : struct proc *p; > : struct getppid_args *uap; > :{ > : struct proc *parent; > : pid_t pid; > : > : parent = p->p_pptr; > : pid = parent->p_pid; > :#ifdef SMP > : for (;;) { > : __asm __volatile (": : : memory"); /* mb(); on x86 */ > : if (parent == p->p_pptr) > : break; > : /* lost a race, our parent died and we reparented - redo */ > : parent = p->p_pptr; > : pid = parent->p_pid; > : } > :#endif > : p->p_retval[0] = (register_t)pid; > : return 0; > :} > This is one of the few things I really hate in the linux source base. This seems to be only to win getppid() benchmarks. Complications like it might be justified in inner loops of syscalls that are called somewhat more than once at most in normal programs. It's too hard to do things this in the thousands of places that would be necessary to get a uniform speedup. > Besides, it isn't guarenteed to work. What happens if the process > double-reparent's and the space pointed to by the original pptr is > reallocated and reused in the second reparenting? That is, this > Now, granted, the chance of the above occuring is probably close to nil. > From an algorithmic point of view, though, the below code (and the > linux code) cannot actually guarentee correct operation without also > make assumptions on side effects (for example, in regards to who is > or is not actually allowed to become the new parent and whether the > situation can occur with those restrictions in place). I think we know that only init can become the new parent provided we can assume that the pointer access to determine to parent is atomic. > I would prefer not to see this sort of code in FreeBSD, even if it means > slowing things down a little. I agree. Locking for file accesses slows things down much more, but not significantly except for too-small i/o sizes. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message