From owner-freebsd-current Fri Apr 7 0:28:23 2000 Delivered-To: freebsd-current@freebsd.org Received: from finch-post-11.mail.demon.net (finch-post-11.mail.demon.net [194.217.242.39]) by hub.freebsd.org (Postfix) with ESMTP id C6B9837C1FB for ; Fri, 7 Apr 2000 00:28:17 -0700 (PDT) (envelope-from dfr@nlsystems.com) Received: from nlsys.demon.co.uk ([158.152.125.33] helo=herring.nlsystems.com) by finch-post-11.mail.demon.net with esmtp (Exim 2.12 #1) id 12dTBf-0009zw-0B; Fri, 7 Apr 2000 07:28:16 +0000 Received: from salmon.nlsystems.com (salmon.nlsystems.com [10.0.0.3]) by herring.nlsystems.com (8.9.3/8.8.8) with ESMTP id IAA49853; Fri, 7 Apr 2000 08:33:46 +0100 (BST) (envelope-from dfr@nlsystems.com) Date: Fri, 7 Apr 2000 08:34:31 +0100 (BST) From: Doug Rabson To: Matthew Dillon Cc: Alfred Perlstein , Greg Lehey , current@freebsd.org Subject: Re: cvs commit: src/sys/i386/i386 support.s src/sys/kern init_sysent.c kern_prot.c kern_sig.c In-Reply-To: <200004061757.KAA89372@apollo.backplane.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 6 Apr 2000, Matthew Dillon wrote: > > :The version of Linux kernel source that I have uses the first: > : > :asmlinkage long sys_getppid(void) > :{ > : int pid; > : struct task_struct * me = current; > : struct task_struct * parent; > : > : parent = me->p_opptr; > : for (;;) { > : pid = parent->pid; > :#if __SMP__ > :{ > : struct task_struct *old = parent; > : mb(); > : parent = me->p_opptr; > : if (old != parent) > : continue; > :} > :#endif > : break; > : } > : return pid; > :} > : > :I like it. mb() is most certainly a "memory barrier" inline to > :force ordering constraints. interesting how they don't use > :volatile for the pointer though: > > mb() just prevents the compiler from optimizing access to the > structural fields (otherwise it might move the accesses outside > the for() loop and you would get an infinite loop. From the > compiler's point of view, mb() is a subroutine call (I assume > in the headers it's a volatile __asm). > > We can either use an mb() type of thing, or we can declare the structural > field volatile, or we can cast the access to be volatile. It also forces the cpu to drain writes and prevents reads from being re-ordered before the mb(). This is mainly a hint for alpha processors but I think it is relavent to other architectures. -- Doug Rabson Mail: dfr@nlsystems.com Nonlinear Systems Ltd. Phone: +44 181 442 9037 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message