Port-macppc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

macppc ksem problem



Some time ago I ran into a problem with semaphores on macppc.  Few
days ago I stumbled into a workaround that is rather weird, but might
help narrow down the search space, so I thought I might post about the
issue.

Unfortunately, the reproducer is not small :).

Few years ago I fixed NetBSD support in Inferno OS (hosted).  The code
in question is on the "devel" branch of

  https://bitbucket.org/nbuwe/inferno-os

Old code used clone(2) for inferno processes, but there's now a
pthreads implementation, so I wanted to switch NetBSD port to use it.
It worked on both i386 (6.x and 7.x) and ppc (I used 6.x at the time).
But then I tried it on macppc 7.x and it was just hanging.

  $ ./NetBSD/power/bin/emu.bad 
  ; echo hello world
  hello world
  <... hangs ...>

The difference is that we switched libpthread semaphores from userland
implementation in 6.x to _ksem(2) kernel based semaphores in 7.x.  emu
is blocked in _ksem_wait() and _ksem_post() never comes.

The pthreads code (emu/port/kproc-pthreads.c) is quite old at this
point, and MI, and works just fine on Linux and on NetBSD/i386 (and on
macppc 6.x), so it's unlikely that the problem is in that code.

A few days ago I wanted to give it another try.  Since ktrace doesn't
show the semaphore id in _ksem_init() I added getvalue call right
after init, just for completeness sake.  The code in question runs at
kproc creation time.

    sem_init(&os->sem, 0, 0);
    {
        int val;
      	sem_getvalue(&os->sem, &val);
    }

To my utter surprise that getvalue call made the problem go away:

  $ ./NetBSD/power/bin/emu 
  ; echo hello world
  hello world
  ; 

This is on sufficiently current current and the tests in
/usr/tests/lib/semaphore/pthread/t_sem_pth all pass.

Any ideas or hunches are appreciated.

If someone is interested to try to debug this themselves (or if you
are curious where Go comes from :), you can grab the sources from that
repo (use "devel" branch) and follow the simple steps in INSTALL.
It's built and run in situ, so no actual "installation" is required.

The workaround mentioned above is in emu/port/kproc-pthreads.c under
an #ifdef.

Thanks in advance.

-uwe


Home | Main Index | Thread Index | Old Index