Date: Fri, 7 Apr 2000 08:34:31 +0100 (BST) From: Doug Rabson <dfr@nlsystems.com> To: Matthew Dillon <dillon@apollo.backplane.com> Cc: Alfred Perlstein <bright@wintelcom.net>, Greg Lehey <grog@lemis.com>, 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 Message-ID: <Pine.BSF.4.21.0004070833040.250-100000@salmon.nlsystems.com> In-Reply-To: <200004061757.KAA89372@apollo.backplane.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0004070833040.250-100000>
