cvs commit: src/lib/libthr/arch/alpha/alpha _curthread.c

John Baldwin jhb at FreeBSD.org
Thu Jul 24 14:00:02 PDT 2003


On 24-Jul-2003 Marcel Moolenaar wrote:
> On Thu, Jul 24, 2003 at 03:08:32PM -0400, John Baldwin wrote:
>> 
>> On 24-Jul-2003 Marcel Moolenaar wrote:
>> > marcel      2003/07/24 00:51:49 PDT
>> > 
>> >   FreeBSD src repository
>> > 
>> >   Modified files:
>> >     lib/libthr/arch/alpha/alpha _curthread.c 
>> >   Log:
>> >   Implement _get_curthread and _set_curthread. We use GCCs builtin
>> >   function this, which expands to PAL calls (rduniq and wruniq).
>> >   This needs adjustment when TLS is implemented.
>> 
>> This trashes SMP since we use the per-CPU unique value already
>> to maintain the per-cpu data pointer.
> 
> Writing to the per-CPU unique value is an unprivileged operation.
> You cannot possibly use that for in-kernel use without saving and
> restoring it on kernel exit/entry. Which is what needs to be done.

There is a chicken and egg problem.  We use the unique value to
initialize the per-cpu pointer on kernel entry.  We only have one
such beast, and in the kernel we cache it in a register that userland
gets to clobber (and frequently does).  If you can think of a better
way to store the per-cpu pointer such that kernel entry can load it
into the register go for it.

Read some code:

syscall(...)
{
        ...
        /*
         * Find our per-cpu globals.
         */
#ifdef SMP
        s = intr_disable();
#endif
        pcpup = (struct pcpu *) alpha_pal_rdval();
        td = curthread;
#ifdef SMP
        td->td_md.md_kernnest++;
        intr_restore(s);
#endif
        ...
}

-- 

John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/


More information about the cvs-src mailing list