Commit Graph

32 Commits

Author SHA1 Message Date
David Xu
e2dc286c1c Caching scheduling policy and priority in userland, a critical but baddly
written application is frequently changing thread priority for SCHED_OTHER
policy.
2006-07-13 22:45:19 +00:00
David Xu
561a89f945 Use thr_setscheduler, thr_getscheduler and thr_setschedparam to implement
pthread functions.
2006-07-13 06:35:43 +00:00
David Xu
7b4f8f037f Use kernel facilities to support real-time scheduling. 2006-07-12 06:13:18 +00:00
David Xu
37a6356bbe WARNS level 4 cleanup. 2006-04-04 02:57:49 +00:00
David Xu
9ad4b64459 Remove priority mutex code because it does not work correctly,
to make it work, turnstile like mechanism to support priority
propagating and other realtime scheduling options in kernel
should be available to userland mutex, for the moment, I just
want to make libthr be simple and efficient thread library.

Discussed with: deischen, julian
2006-03-27 23:50:21 +00:00
David Xu
1775714935 Fix a bug recently introduced, the _thread_active_count should be
decreased if thread can not be created.
2006-01-08 10:13:18 +00:00
David Xu
bc414752d3 Refine thread suspension code, now thread suspension is a blockable
operation, the caller is blocked util target threads are really
suspended, also avoid suspending a thread when it is holding a
critical lock.
Fix a bug in _thr_ref_delete which tests a never set flag.
2006-01-05 13:51:22 +00:00
David Xu
df2cf82178 Update copyright. 2005-12-17 09:42:45 +00:00
David Xu
88676cbc2c The pthread_attr_set_createsuspend_np was broken, fix it by
replacing THR_FLAGS_SUSPENDED with THR_FLAGS_NEED_SUSPEND.
2005-10-10 12:15:07 +00:00
Stefan Farfeleder
7e4cbc3a50 Include needed headers that were obtained through <pthread.h>. Sort headers
while here.
2005-09-01 15:21:23 +00:00
David Xu
80c9676e8b Use thr_new syscall to create a new thread, obscure context operations
is no longer needed.
2005-04-23 02:48:59 +00:00
David Xu
d245d9e13f Add debugger event reporting support, current only TD_CREATE and TD_DEATH
events are reported.
2005-04-12 03:00:28 +00:00
David Xu
a091d823ad Import my recent 1:1 threading working. some features improved includes:
1. fast simple type mutex.
 2. __thread tls works.
 3. asynchronous cancellation works ( using signal ).
 4. thread synchronization is fully based on umtx, mainly, condition
    variable and other synchronization objects were rewritten by using
    umtx directly. those objects can be shared between processes via
    shared memory, it has to change ABI which does not happen yet.
 5. default stack size is increased to 1M on 32 bits platform, 2M for
    64 bits platform.
As the result, some mysql super-smack benchmarks show performance is
improved massivly.

Okayed by: jeff, mtm, rwatson, scottl
2005-04-02 01:20:00 +00:00
David Xu
9027ac471c Adjust code to support AMD64, on AMD64, thread needs to set fsbase by
itself before it can execute any other code, so new thread should be
created with all signals are masked until after fsbase is set.
2004-08-19 23:49:04 +00:00
Marcel Moolenaar
cc7be8dc05 Record the offset of thr_id in the thread structure. Required for
debugging.
2004-07-04 19:07:07 +00:00
Marcel Moolenaar
cd28f17da2 Change the thread ID (thr_id_t) used for 1:1 threading from being a
pointer to the corresponding struct thread to the thread ID (lwpid_t)
assigned to that thread. The primary reason for this change is that
libthr now internally uses the same ID as the debugger and the kernel
when referencing to a kernel thread. This allows us to implement the
support for debugging without additional translations and/or mappings.

To preserve the ABI, the 1:1 threading syscalls, including the umtx
locking API have not been changed to work on a lwpid_t. Instead the
1:1 threading syscalls operate on long and the umtx locking API has
not been changed except for the contested bit. Previously this was
the least significant bit. Now it's the most significant bit. Since
the contested bit should not be tested by userland, this change is
not expected to be visible. Just to be sure, UMTX_CONTESTED has been
removed from <sys/umtx.h>.

Reviewed by: mtm@
ABI preservation tested on: i386, ia64
2004-07-02 00:40:07 +00:00
Mike Makonnen
105711487e When a thread is created suspended have libthr suspend it explicitly
instead of asking the kernel to do it when we create the thread.
2004-06-30 15:57:36 +00:00
Mike Makonnen
4cd18a22d5 Make libthr async-signal-safe without costly signal masking. The guidlines I
followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate,
pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of
the rest of the pthread api is required to be async-signal-safe. This means
that only the three mentioned functions are safe to use from inside
signal handlers.
However, there are certain system/libc calls that are
cancellation points that a caller may call from within a signal handler,
and since they are cancellation points calls have to be made into libthr
to test for cancellation and exit the thread if necessary. So, the
cancellation test and thread exit code paths must be async-signal-safe
as well. A summary of the changes follows:

o Almost all of the code paths that masked signals, as well as locking the
  pthread structure now lock only the pthread structure.
o Signals are masked (and left that way) as soon as a thread enters
  pthread_exit().
o The active and dead threads locks now explicitly require that signals
  are masked.
o Access to the isdead field of the pthread structure is protected by both
  the active and dead list locks for writing. Either one is sufficient for
  reading.
o The thread state and type fields have been combined into one three-state
  switch to make it easier to read without requiring a lock. It doesn't need
  a lock for writing (and therefore for reading either) because only the
  current thread can write to it and it is an integer value.
o The thread state field of the pthread structure has been eliminated. It
  was an unnecessary field that mostly duplicated the flags field, but
  required additional locking that would make a lot more code paths require
  signal masking. Any truly unique values (such as PS_DEAD) have been
  reborn as separate members of the pthread structure.
o Since the mutex and condvar pthread functions are not async-signal-safe
  there is no need to muck about with the wait queues when handling
  a signal ...
o ... which also removes the need for wrapping signal handlers and sigaction(2).
o The condvar and mutex async-cancellation code had to be revised as a result
  of some of these changes, which resulted in semi-unrelated changes which
  would have been difficult to work on as a separate commit, so they are
  included as well.

The only part of the changes I am worried about is related to locking for
the pthread joining fields. But, I will take a closer look at them once this
mega-patch is committed.
2004-05-20 12:06:16 +00:00
Mike Makonnen
1c6f63018d Remove the garbage collector thread. All resources are freed
in-line. If the exiting thread cannot release a resource, then
the next thread to exit will release it.
2004-03-28 14:05:28 +00:00
Mike Makonnen
06e5becb69 Move the initialization of thread priority to a common function. 2004-02-18 15:05:56 +00:00
Mike Makonnen
f2c3dd08ec Preparations to make libthr work in multi-threaded fork()ing applications.
o Remove some code duplication between _thread_init(), which is run once
  to initialize libthr and the intitial thread, and pthread_create(), which
  initializes newly created threads, into a new function called from both
  places: init_td_common()
o Move initialization of certain parts of libthr into a separate
  function. These include:
	- Active threads list and it's lock
	- Dead threads list and it's lock & condition variable
	- Naming and insertion of the initial thread into the
	  active threads list.
2003-12-26 08:16:17 +00:00
Mike Makonnen
c830473999 When creating a pthread in the suspended state their were two
problems: (1) The wrong flag was being checked for in the attribute
	  (2) The pthread's state was not being set to indicate it was
	      suspended.

Noticed by: Igor Sysoev <is@rambler-co.ru>
2003-12-15 09:35:02 +00:00
Mike Makonnen
981f4968f0 It's unnecessary to lock the thread during creation. Simply extend
the scope of the active thread list lock.

Approved by:	re/jhb
2003-05-29 20:40:50 +00:00
Mike Makonnen
ca1c469cc7 Decouple the thread stack [de]allocating functions from the 'dead threads list'
lock. It's not really necessary and we don't need the added complexity
or potential for deadlocks.

Approved by:	re/blanket libthr
2003-05-26 00:37:07 +00:00
Mike Makonnen
12c407a424 Return gracefully, rather than aborting, when the maximum concurrent
threads per process has been reached. Return EAGAIN, as per spec.

Approved by:	re/blanket libthr
2003-05-25 22:40:57 +00:00
Mike Makonnen
4393f2c4ec Part of the last patch.
Modify the thread creation and thread searching routine
to lock the thread lists with the new locks instead of GIANT_LOCK.

Approved by:	re/blanket libthr
2003-05-25 08:35:37 +00:00
Mike Makonnen
7d9d7ca2ed Make WARNS2 clean. The fixes mostly included:
o removed unused variables
	o explicit inclusion of header files
	o prototypes for externally defined functions

Approved by:    re/blanket libthr
2003-05-23 09:48:20 +00:00
Mike Makonnen
5ccf23715a Re-enable the garbage collector thread in anticipation of further
locking work. I can't see anything obviously wrong with it (other than
the need to update the locking).

Approved by: markm/mentor, re/blanket libthr
2003-05-21 03:34:54 +00:00
Marcel Moolenaar
e7c9b7517b Fix build breakage (on ia64) caused by a missing file descriptor to
_thread_printf(). Use STDERR_FILENO as the file descriptor.
2003-04-20 02:56:12 +00:00
Jake Burkholder
55ad402a8f - Pass a ucontext_t to _set_curthread. If non-NULL the new thread is set
as curthread in the new context, so that it will be set automatically when
  the thread is switched to.  This fixes a race where we'd run for a little
  while with curthread unset in _thread_start.

Reviewed by:	jeff
2003-04-03 03:34:50 +00:00
Jeff Roberson
26f52e2f8b - Define curthread as _get_curthread() and remove all direct calls to
_get_curthread().  This is similar to the kernel's curthread.  Doing
   this saves stack overhead and is more convenient to the programmer.
 - Pass the pointer to the newly created thread to _thread_init().
 - Remove _get_curthread_slow().
2003-04-02 03:05:39 +00:00
Jeff Roberson
bb535300dd - Add libthr but don't hook it up to the regular build yet. This is an
adaptation of libc_r for the thr system call interface.  This is beta
   quality code.
2003-04-01 03:46:29 +00:00