Commit Graph

267 Commits

Author SHA1 Message Date
David Xu
30a2952c90 Call kse_wakeup_multi() to wakeup idle KSEs when there are threads ready
to run.
2003-04-30 01:03:58 +00:00
Daniel Eischen
6cc13fa9ad Create the thread signal lock as a KSE lock (as opposed to
a thread lock).

Better protect access to thread state while searching for
threads to handle a signal.

Better protect access to process pending signals while processing
a thread in sigwait().

Submitted by:	davidxu
2003-04-29 21:03:33 +00:00
Daniel Eischen
55613576f5 o Don't add a scope system thread's KSE to the list of available
KSEs when it's thread exits; allow the GC handler to do that.

o Make spinlock/spinlock critical regions.

The following were submitted by davidxu

  o Alow thr_switch() to take a null mailbox argument.

  o Better protect cancellation checks.

  o Don't set KSE specific data when creating new KSEs; rely on the
    first upcall of the KSE to set it.

  o Add the ability to set the maximum concurrency level and do this
    automatically.  We should have a way to enable/disable this with
    some sort of tunable because some applications may not want this
    to be the default.

  o Hold the scheduling lock across thread switch calls.

  o If scheduling of a thread fails, make sure to remove it from the list
    of active threads.

  o Better protect accesses to a joining threads when the target thread is
    exited and detached.

  o Remove some macro definitions that are now provided by <sys/kse.h>.

  o Don't leave the library in threaded mode if creation of the initial
    KSE fails.

  o Wakeup idle KSEs when there are threads ready to run.

  o Maintain the number of threads active in the priority queue.
2003-04-28 23:56:12 +00:00
Daniel Eischen
76f344139c Use the correct link entry for walking the list of threads.
While I'm here, use the TAILQ_FOREACH macro instead of a more
manual method which was inherited from libc_r (so we could
remove elements from the list which isn't needed for libpthread).

Submitted by:	Kazuaki Oda <kaakun@highway.ne.jp>
2003-04-28 21:35:06 +00:00
Daniel Eischen
f1c8192fd4 Protect thread errno from being changed while operating
on behalf of the KSE.

Add a kse_reinit function to reinitialize a reused KSE.

Submitted by:	davidxu
2003-04-23 21:46:50 +00:00
Daniel Eischen
29fde418c1 Set the quantum for scope system threads to 0 (no quantum). 2003-04-22 21:32:32 +00:00
Daniel Eischen
42a5f6248b Add a working pthread_[gs]etconcurrency. Initial null implementation
provided by Sergey A. Osokin <osa@freebsd.org.ru>.

In order to test this on a single CPU machine, you need to:

    sysctl kern.threads.debug=1
    sysctl kern.threads.virtual_cpu=2
2003-04-22 20:29:16 +00:00
Daniel Eischen
6dee371a55 Add a couple asserts to pthread_cond_foo to ensure the (low-level)
lock level is 0.  Thus far, the threads implementation doesn't use
mutexes or condition variables so the lock level should be 0.

Save the return value when trying to schedule a new thread and
use this to return an error from pthread_create().

Change the max sleep time for an idle KSE to 1 minute from 2 minutes.

Maintain a count of the number of KSEs within a KSEG.

With these changes scope system threads seem to work, but heavy
use of them crash the kernel (supposedly VM bugs).
2003-04-22 20:28:33 +00:00
Daniel Eischen
02245e6120 Add an i386-specifc hack to always set %gs. There still seems
to be instances where the kernel doesn't  properly save and/or
restore it.

Use noupcall and nocompleted flags in the KSE mailbox.  These
require kernel changes to work which will be committed sometime
later.  Things still work without the changes.

Remove the general kse entry function and use two different
functions -- one for scope system threads and one for scope
process threads.  The scope system function is not yet enabled
and we use the same function for all threads at the moment.

Keep a copy of the KSE stack for the case that a KSE runs
a scope system thread and uses the same stack as the thread
(no upcalls are generated, so a separate stack isn't needed).
This isn't enabled yet.

Use a separate field for the KSE waiting flag.  It isn't
correct to use the mailbox flags field.

The following fixes were provided by David Xu:

  o Initialize condition variable locks with thread versions
    of the low-level locking functions instead of the kse versions.

  o Enable threading before creating the first thread instead
    of after.

  o Don't enter critical regions when trying to malloc/free
    or call functions that malloc/free.

  o Take the scheduling lock when inheriting thread attributes.

  o Check the attribute's stack pointer instead of the
    attributes stack size for null when allocating a
    thread's stack.

  o Add a kseg reinit function so we don't have to destroy and
    then recreate the same lock.

  o Check the return value of kse_create() and return an
    appropriate error if it fails.

  o Don't forget to destroy a thread's locks when freeing it.

  o Examine the correct flags word for checking to see if
    a thread is in a synchronization queue.

Things should now work on an SMP kernel.
2003-04-21 04:02:56 +00:00
Daniel Eischen
078d4c1b8b Remove duplicate $FreeBSD$ id. 2003-04-18 07:45:03 +00:00
Daniel Eischen
e4c2ac1637 Sorry folks; I accidentally committed a patch from what I was working
on a couple of days ago.  This should be the most recent changes.

Noticed by:	davidxu
2003-04-18 07:09:43 +00:00
Daniel Eischen
a0240e2cb0 Revamp libpthread so that it has a chance of working in an SMP
environment.  This includes support for multiple KSEs and KSEGs.

The ability to create more than 1 KSE via pthread_setconcurrency()
is in the works as well as support for PTHREAD_SCOPE_SYSTEM threads.
Those should come shortly.

There are still some known issues which davidxu and I are working
on, but it'll make it easier for us by committing what we have.

This library now passes all of the ACE tests that libc_r passes
with the exception of one.  It also seems to work OK with KDE
including konqueror, kwrite, etc.  I haven't been able to get
mozilla to run due to lack of java plugin, so I'd be interested
to see how it works with that.

Reviewed by:	davidxu
2003-04-18 05:04:16 +00:00
Jeff Roberson
cc3521d660 - Define a _spinunlock() function so that threading implementations may do
more complicated things than just setting the lock to 0.
 - Implement stubs for this function in libc and the two threading libraries
   that are currently in the tree.
2003-03-26 04:02:24 +00:00
David Xu
5b54b0891a Backout last commit.
Requested by: jhb
2003-03-15 04:45:42 +00:00
David Xu
047a20e644 Fix a bug in rwlock. When a rwlock was locked by reader threads, a
writter thread can block reader threads to get read lock.
2003-03-14 01:02:47 +00:00
Alexey Zelkin
68d8899c03 Fix cut'n'paste error
Noticed by:	julian
2003-03-05 20:50:03 +00:00
Alexey Zelkin
09492be669 MFlibc_r: add and document pthread_attr_get_np() function. 2003-03-03 22:40:20 +00:00
David Xu
96dfe788ad Fix compiling error. 2003-02-26 08:28:28 +00:00
Jonathan Mini
3b63c6c8ea Insert threads interrupted by a signal while running onto the run queue. 2003-02-23 21:15:25 +00:00
Jonathan Mini
f88cb3c627 Add signal logic to the build. 2003-02-23 21:14:08 +00:00
Jonathan Mini
faa8342f9f Deliver signals posted via an upcall to the appropriate thread. 2003-02-17 10:05:18 +00:00
Alfred Perlstein
969e2ea158 Actually link in the attr_{set,get}stack. 2003-02-11 07:28:28 +00:00
Alfred Perlstein
4e44912c6c Add pthread_attr_getstack() and pthread_attr_setstack().
Submitted by: Craig Rodrigues <rodrigc@attbi.com>
2003-02-10 08:48:04 +00:00
Jonathan Mini
e9d0431f0b Schedule spinlocked threads by moving them through the work queue, instead
of the wait queue.

Approved by: re (blanket)
Stolen from: davidxu
2002-11-24 06:45:45 +00:00
Jonathan Mini
4df51f23bb Get the wall clock time from the KSE mailbox, rather than doing another
syscall.
2002-11-24 06:43:21 +00:00
David Xu
662c0429b9 Fix idle timeout bug, use correct current time of day. 2002-11-20 12:35:59 +00:00
Jonathan Mini
1cb53a1828 Schedule an idle context to block until timeouts expire without blocking
further upcalls.
2002-11-12 00:55:01 +00:00
Jonathan Mini
40e044cbd3 Make pthread_sigmask(3) operate on the thread signal mask, not the process
signal mask.
2002-10-30 07:13:27 +00:00
Jonathan Mini
2d9a293b4e Use KSE to schedule threads. 2002-10-30 06:07:18 +00:00
Robert Drehmel
e31d11c36a Add the 'restrict' type qualifier to the prototypes of `sigaction',
`sigprocmask', `sigaltstack', and `sigwait' as well as to the
prototypes of the apparantly unimplemented functions `sigtimedwait'
and `sigwaitinfo'.  This complies with IEEE Std 1003.1-2001.
2002-10-02 10:53:44 +00:00
Jonathan Mini
255ab70cdf Make libpthread KSE aware.
Reviewed by:	deischen, julian
Approved by:	-arch
2002-09-16 19:52:52 +00:00
Jonathan Mini
cc118d869b Make the changes needed for libpthread to compile in its new home.
The new libpthread will provide POSIX threading support using KSE.
These files were previously repo-copied from src/lib/libc_r.

Reviewed by:	deischen
Approved by:	-arch
2002-09-16 08:45:36 +00:00
Daniel Eischen
d8b5986dd6 Remove much of the dereferencing of the fd table entries to look
at file flags and replace it with functions that will avoid null
pointer checks.

MFC to be done by archie ;-)

PR:		42100
Reviewed by:	archie, robert
MFC after:	3 days
2002-08-29 23:06:07 +00:00
Archie Cobbs
afa4625307 Make the libc_r version of select() set the readable or writable
file descriptor bit if poll() returns POLLERR, POLLHUP, or POLLNVAL.
Othewise, it's possible for select() to return successfully but
with no bits set.

Reviewed by:	deischen
MFC after:	3 days
PR:		bin/42175
2002-08-29 21:39:19 +00:00
Archie Cobbs
ccde72a411 When poll(2)'ing for readability or writability of a file descriptor
on behalf of a thread, we should check the POLLERR, POLLHUP, and
POLLNVAL flags as well to wake up the thread in these cases.

Suggested by:	deischen
MFC after:	3 days
2002-08-29 00:44:11 +00:00
Philippe Charnier
7fed38d0a0 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:10:45 +00:00
Daniel Eischen
582dfa2dd4 Oops, forgot to set the suspended flag for threads that are created
initially suspended.  This was preventing such threads from getting
resumed.

Reported by:	Bill Huey <billh@gnuppy.monkey.org>
2002-07-09 13:24:52 +00:00
Daniel Eischen
88127f1a62 Make sigpending and sigsuspend account for signals that are pending on
the process as well as pending on the current thread.

Reported by:	Andrew MacIntyre <andymac@bullseye.apana.org.au>
2002-06-28 13:28:41 +00:00
Daniel Eischen
b4e1c937c7 Add a wrapper for pselect() in order to make it a cancellation point.
Prompted by: wollman
2002-06-28 13:26:02 +00:00
Robert Watson
4a85ccbe6d Missed in earlier commit -- I did cvs commit src/lib/libc. Oops. 2002-06-14 04:02:25 +00:00
Daniel Eischen
5eb8d1f0b0 Revamp suspend and resume. While I'm here add pthread_suspend_all_np()
and pthread_resume_all_np().  These suspend and resume all threads except
the current thread, respectively.  The existing functions pthread_single_np()
and pthread_multi_np(), which formerly had no effect, now exhibit the same
behaviour and pthread_suspend_all_np() and pthread_resume_all_np().  These
functions have been added mostly for the native java port.

Don't allow the uthread kernel pipe to use the same descriptors as
stdio.  Mostily submitted by Oswald Buddenhagen <ossi@kde.org>.

Correct some minor style nits.
2002-05-24 04:32:28 +00:00
Alfred Perlstein
2b75bbdb31 Undo namespace pollution by prefixing the globals pthread_guard_default and
pthread_page_size.

Fix a bunch line wrapping.

Pointed out by: deischen
2002-05-15 05:37:48 +00:00
Alfred Perlstein
efe5270b1e Don't use PAGE_SIZE in userland, instead use getpagesize(), this is to
allow running on other arches when the instructions are supported but
the page size granularity is not.

Glanced at by: peter
2002-05-13 07:58:15 +00:00
Alfred Perlstein
e5ba687a2c Use GCC's __attribute__ ((constructor)) mechanism to invoke the pthread
startup code rather than a static C++ object since c++ seems to be broken.

This doesn't seem to work for staticically linked program just yet, I'll
give that some more work when I get a chance.
2002-05-11 08:13:42 +00:00
Archie Cobbs
663fc9cc7c Make these functions cancellation points like they should be:
poll(2), readv(2), select(2), wait4(2), writev(2).

PR:		bin/37658
Reviewed by:	deischen
MFC after:	1 week
2002-05-02 19:58:43 +00:00
Archie Cobbs
ca0989d865 Make sure calls to pthread_cancel() do not take effect if the target
thread is already exiting.

PR:		bin/37614
Reviewed by:	deischen
MFC after:	1 week
2002-05-02 19:57:59 +00:00
David E. O'Brien
07a7a2eba8 The GCC developers have made good on their threats against #pragma for 3.1.
Use __weak_reference in place of the #pragma.

Submitted by:	eischen
2002-04-15 23:11:38 +00:00
Jeroen Ruigrok van der Werven
92d2baa6a2 Return correct number of total bits set in all fd_set's.
Change case of POLLNVAL as an error.
Remove POLLHUP and POLLERR from one case, their place is most likely
amongst read events.

PR:		33723
Submitted by:	Alexander Litvin <archer@whichever.org>
Reviewed by:	deischen [Provided a small change to the PR patch as well]
MFC after:	4 weeks
2002-04-09 05:41:00 +00:00
Mark Murray
4cd0119367 Do not use __progname directly (except in [gs]etprogname(3)).
Also, make an internal _getprogname() that is used only inside
libc. For libc, getprogname(3) is a weak symbol in case a
function of the same name is defined in userland.
2002-03-29 22:43:43 +00:00
Daniel Eischen
3003bdb598 Add the ability to recognize old references to keys, and return NULL
when old keys are referenced (after pthread_key_delete()) via
pthread_getspecific().
2002-03-19 22:58:56 +00:00