Home | History | Annotate | Line # | Download | only in libpthread
TODO revision 1.8
      1 $NetBSD: TODO,v 1.8 2007/03/02 18:53:51 ad Exp $
      2 
      3 Bugs to fix:
      4 
      5 - Add locking to ld.elf_so so that multiple threads doing lazy binding
      6   doesn't trash things. XXX Still the case?
      7 - Verify the cancel stub symbol trickery.
      8 
      9 Interfaces/features to implement:
     10 
     11 - priority scheduling
     12 - libc integration: 
     13    - foo_r interfaces
     14 - system integration
     15    - some macros and prototypes belong in headers other than pthread.h
     16 
     17 Features that need more/better regression tests:
     18 
     19  - pthread_cond_broadcast()
     20  - pthread_once()
     21  - pthread_get/setspecific()
     22  - signals
     23 
     24 Ideas to play with:
     25 
     26 - Explore the trapcontext vs. usercontext distinction in ucontext_t.
     27 
     28 - Get rid of thread structures when too many accumulate (is this
     29   actually a good idea?)
     30 
     31 - Currently, each thread uses two real pages of memory: one at the top
     32   of the stack for actual stack data, and one at the bottom for the
     33   pthread_st. If we can get suitable space above the initial stack for
     34   main(), we can cut this to one page per thread. Perhaps crt0 should
     35   do something different (give us more space) if libpthread is linked
     36   in?
     37 
     38 - Figure out whether/how to expose the inline version of
     39   pthread_self().
     40 
     41 - Along the same lines, figure out whether/how to use registers reserved
     42   in the ABI for thread-specific-data to implement pthread_self().
     43 
     44 - Figure out what to do with changing stack sizes.
     45 
     46 - Stress testing, particularly with multiple CPUs.
     47 
     48 - A race between pthread_exit() and pthread_create() for detached LWPs,
     49   where the stack (and pthread structure) could be reclaimed before the
     50   thread has a chance to call _lwp_exit(), is currently prevented by
     51   checking the return of _lwp_kill(target, 0).  It could be done more
     52   efficiently.  (See shared page item.)
     53 
     54 - Adaptive mutexes and spinlocks (see shared page item). These need
     55   to implement exponential backoff to reduce bus contention. On x86 we
     56   need to issue the 'pause' instruction while spinning, perhaps on other
     57   SMT processors too.
     58 
     59 - Have a shared page that:
     60 
     61   o Allows an LWP to request it not be preempted by the kernel. This would
     62     be used over critical sections like pthread_cond_wait(), where we can
     63     acquire a bunch of spin locks: being preempted while holding them would
     64     suck. _lwp_park() would reset the flag once in kernel mode, and there
     65     would need to be an equivalent way to do this from user mode. The user
     66     path would probably need to notice deferred preemption and call
     67     sched_yield() on exit from the critical section.
     68 
     69   o Perhaps has some kind of hint mechanism that gives us a clue about
     70     whether an LWP is currently running on another CPU. This could be used
     71     for adaptive locks, but would need to be cheap to do in-kernel.
     72 
     73   o Perhaps has a flag value that's reset when a detached LWP is into the
     74     kernel and lwp_exit1(), meaning that its stack can be reclaimed. Again,
     75     may or may not be worth it.
     76 
     77 - Keep a pool of dead LWPs so that we do not have take the full hit of
     78   _lwp_create() every time pthread_create() is called. If nothing else
     79   this is important for benchmarks.. There are a few different ways this
     80   could be implemented, but it needs to be clear if the advantages are
     81   real. Lots of thought and benchmarking required.
     82 
     83 - LWPs that are parked or that have called nanosleep() (common) burn up
     84   kernel resources. "struct lwp" itself isn't a big deal, but the VA space
     85   and swap used by kernel stacks is. _lwp_park() takes a ucontext_t pointer
     86   in expectation that at some point we may be able to recycle the kernel
     87   stack and re-start the LWP at the correct point, using pageable user
     88   memory to hold state. It might also be useful to have a nanosleep call
     89   that does something similar. Again, lots of thought and benchmarking
     90   required. (Original idea from matt@)
     91 
     92 - Need to give consideration to the order in which threads enter and exit
     93   synchronisation objects, both in the pthread library and in the kernel.
     94   Commonly locks are acquired/released in order (a, b, c -> c, b, a).
     95 
     96 - The kernel scheduler needs improving to handle LWPs and processor affinity
     97   better, and user space tools like top(1) and ps(1) need to be changed to
     98   report correctly.  Tied into that is the need for a mechanism to impose
     99   limits on various aspects of LWPs.
    100 
    101 - Streamlining of the park/unpark path.
    102 
    103 - Priority inheritance and similar nasties.
    104