summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thr.c
Commit message (Collapse)AuthorAgeFilesLines
* If threads limit is exceeded, increase the totoal numberdavidxu2008-10-291-1/+4
| | | | of failures.
* Actually, for signal and thread suspension, extra process spin lock isdavidxu2008-10-231-2/+1
| | | | | | unnecessary, the normal process lock and thread lock are enough. The spin lock is still needed for process and thread exiting to mimic single sched_lock.
* Check the result of copyin and in a case of errorrdivacky2008-10-131-0/+2
| | | | | | | return one. This prevents setting wrong priority or (more likely) returning EINVAL. Approved by: kib (mentor)
* Fix compiling problem.davidxu2008-04-291-1/+1
|
* Remove commented out code, thread suspension is done in thread library.davidxu2008-03-231-2/+1
|
* - Add a new td flag TDF_NEEDSUSPCHK that is set whenever a thread needsjeff2008-03-211-0/+2
| | | | | | | | | | | | | to enter thread_suspend_check(). - Set TDF_ASTPENDING along with TDF_NEEDSUSPCHK so we can move the thread_suspend_check() to ast() rather than userret(). - Check TDF_NEEDSUSPCHK in the sleepq_catch_signals() optimization so that we don't miss a suspend request. If this is set use the expensive signal path. - Set NEEDSUSPCHK when creating a new thread in thr in case the creating thread is due to be suspended as well but has not yet. Reviewed by: davidxu (Authored original patch)
* - Relax requirements for p_numthreads, p_threads, p_swtick, and p_nice fromjeff2008-03-191-2/+0
| | | | | | | requiring the per-process spinlock to only requiring the process lock. - Reflect these changes in the proc.h documentation and consumers throughout the kernel. This is a substantial reduction in locking cost for these fields and was made possible by recent changes to threading support.
* This time REALLY copy the name from the proc to the thread as a default.julian2007-11-151-0/+1
|
* Fix for the panic("vm_thread_new: kstack allocation failed") andkib2007-11-051-0/+2
| | | | | | | | | | | | | | | | | | | | silent NULL pointer dereference in the i386 and sparc64 pmap_pinit() when the kmem_alloc_nofault() failed to allocate address space. Both functions now return error instead of panicing or dereferencing NULL. As consequence, vmspace_exec() and vmspace_unshare() returns the errno int. struct vmspace arg was added to vm_forkproc() to avoid dealing with failed allocation when most of the fork1() job is already done. The kernel stack for the thread is now set up in the thread_alloc(), that itself may return NULL. Also, allocation of the first process thread is performed in the fork1() to properly deal with stack allocation failure. proc_linkup() is separated into proc_linkup() called from fork1(), and proc_linkup0(), that is used to set up the kernel process (was known as swapper). In collaboration with: Peter Holm Reviewed by: jhb
* Add thr_kill2 syscall which sends a signal to a thread in another process.davidxu2007-08-161-0/+55
| | | | | Submitted by: Tijl Coosemans tijl at ulyssis dot org Approved by: re (kensmith)
* - Remove unused variable from create_thread().jhb2007-06-071-2/+1
| | | | | - Move kern_thr_*() prototype to <sys/syscallsubr.h> where all the other kern_*() prototypes live.
* Commit 14/14 of sched_lock decomposition.jeff2007-06-051-10/+13
| | | | | | | | | | | - Use thread_lock() rather than sched_lock for per-thread scheduling sychronization. - Use the per-process spinlock rather than the sched_lock for per-process scheduling synchronization. Tested by: kris, current@ Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc. Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
* - Remove setrunqueue and replace it with direct calls to sched_add().jeff2007-01-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | setrunqueue() was mostly empty. The few asserts and thread state setting were moved to the individual schedulers. sched_add() was chosen to displace it for naming consistency reasons. - Remove adjustrunqueue, it was 4 lines of code that was ifdef'd to be different on all three schedulers where it was only called in one place each. - Remove the long ifdef'd out remrunqueue code. - Remove the now redundant ts_state. Inspect the thread state directly. - Don't set TSF_* flags from kern_switch.c, we were only doing this to support a feature in one scheduler. - Change sched_choose() to return a thread rather than a td_sched. Also, rely on the schedulers to return the idlethread. This simplifies the logic in choosethread(). Aside from the run queue links kern_switch.c mostly does not care about the contents of td_sched. Discussed with: julian - Move the idle thread loop into the per scheduler area. ULE wants to do something different from the other schedulers. Suggested by: jhb Tested on: x86/amd64 sched_{4BSD, ULE, CORE}.
* Threading cleanup.. part 2 of several.julian2006-12-061-35/+1
| | | | | | | | | | | | | | | | | | | | | | Make part of John Birrell's KSE patch permanent.. Specifically, remove: Any reference of the ksegrp structure. This feature was never fully utilised and made things overly complicated. All code in the scheduler that tried to make threaded programs fair to unthreaded programs. Libpthread processes will already do this to some extent and libthr processes already disable it. Also: Since this makes such a big change to the scheduler(s), take the opportunity to rename some structures and elements that had to be moved anyhow. This makes the code a lot more readable. The ULE scheduler compiles again but I have no idea if it works. The 4bsd scheduler still reqires a little cleaning and some functions that now do ALMOST nothing will go away, but I thought I'd do that as a separate commit. Tested by David Xu, and Dan Eischen using libthr and libpthread.
* if a thread blocked on userland condition variable isdavidxu2006-12-041-0/+11
| | | | | | | | | | pthread_cancel()ed, it is expected that the thread will not consume a pthread_cond_signal(), therefor, we use thr_wake() to mark a flag, the flag tells a thread calling do_cv_wait() in umtx code to not block on a condition variable. Thread library is expected that once a thread detected itself is in pthread_cond_wait, it will call the thr_wake() for itself in its SIGCANCEL handler.
* Update includes for sys/posix4 move.trhodes2006-11-111-2/+1
| | | | Approved by: silence on -arch and -standards
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-1/+2
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Make KSE a kernel option, turned on by default in all GENERICjb2006-10-261-0/+24
| | | | | | | kernel configs except sun4v (which doesn't process signals properly with KSE). Reviewed by: davidxu@
* Add compatible code to let 32bit libthr work on 64bit kernel.davidxu2006-09-221-25/+64
|
* Replace system call thr_getscheduler, thr_setscheduler, thr_setschedparamdavidxu2006-09-211-198/+21
| | | | | with rtprio_thread, while rtprio system call is for process only, the new system call rtprio_thread is responsible for LWP.
* Same as previous change, the user provided priority should be reverseddavidxu2006-08-251-2/+2
| | | | too.
* POSIX requires that higher numerical values for the priority representdavidxu2006-08-231-39/+39
| | | | higher priorities, so we should reverse the passed value here.
* Add syscalls thr_setscheduler, thr_getscheduler, and thr_setschedparam,davidxu2006-07-131-2/+158
| | | | | | | | these syscalls are designed to set thread's scheduling parameters and policy, because each syscall contains a size parameter, it is possible to support future scheduling option, e.g SCHED_SPORADIC, this option needs other fields in structure sched_param, current they are not avaiblable.
* Use newkg to check if SCHED_OTHER is already inherited.davidxu2006-07-121-2/+1
|
* Don't forget to check invalid policy!davidxu2006-07-111-7/+9
|
* For SCHED_OTHER, we always inherit current thread's interactive prioritydavidxu2006-07-111-6/+10
| | | | | | unless current thread is realtime thread, in such case, we set a new zero priority for it, notice we don't have per-thread nice, the priority passed by userland is ignored here.
* Add POSIX scheduler parameters support to thr_new syscall, this permitsdavidxu2006-07-111-4/+57
| | | | privileged process to create realtime thread.
* Create thread in separated ksegrp, so they always get correct user leveldavidxu2006-07-101-75/+11
| | | | priority.
* Change msleep() and tsleep() to not alter the calling thread's priorityjhb2006-04-171-2/+2
| | | | | | | | | | | | if the specified priority is zero. This avoids a race where the calling thread could read a snapshot of it's current priority, then a different thread could change the first thread's priority, then the original thread would call sched_prio() inside msleep() undoing the change made by the second thread. I used a priority of zero as no thread that calls msleep() or tsleep() should be specifying a priority of zero anyway. The various places that passed 'curthread->td_priority' or some variant as the priority now pass 0.
* Call thread_stopped in thr_exit to notify parent that the child processdavidxu2006-02-101-0/+1
| | | | is now fully stopped, this was already in kse_exit().
* Implement thr_set_name to set a name for thread.davidxu2006-02-051-0/+29
| | | | Reviewed by: julian
* Add a new feature to thr_kill, if thread ID argument is -1, senddavidxu2006-01-071-12/+27
| | | | signals to all threads except current sender.
* Cleanup some signal interfaces. Now the tdsignal function acceptsdavidxu2005-11-031-1/+1
| | | | | | | | | both proc pointer and thread pointer, if thread pointer is NULL, tdsignal automatically finds a thread, otherwise it sends signal to given thread. Add utility function psignal_event to send a realtime sigevent to a process according to the delivery requirement specified in struct sigevent.
* Oops, don't change tdsignal call.davidxu2005-11-031-1/+1
|
* Add thread_find() function to search a thread by lwpid.davidxu2005-11-031-12/+8
|
* do umtx_wake at userland thread exit address, so that others userlanddavidxu2005-10-261-1/+5
| | | | | | | | | | threads can wait for a thread to exit, and safely assume that the thread has left userland and is no longer using its userland stack, this is necessary for pthread_join when a thread is waiting for another thread to exit which has user customized stack, after pthread_join returns, the userland stack can be reused for other purposes, without this change, the joiner thread has to spin at the address to ensure the thread is really exited.
* 1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, mostdavidxu2005-10-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | changes in MD code are trivial, before this change, trapsignal and sendsig use discrete parameters, now they uses member fields of ksiginfo_t structure. For sendsig, this change allows us to pass POSIX realtime signal value to user code. 2. Remove cpu_thread_siginfo, it is no longer needed because we now always generate ksiginfo_t data and feed it to libpthread. 3. Add p_sigqueue to proc structure to hold shared signals which were blocked by all threads in the proc. 4. Add td_sigqueue to thread structure to hold all signals delivered to thread. 5. i386 and amd64 now return POSIX standard si_code, other arches will be fixed. 6. In this sigqueue implementation, pending signal set is kept as before, an extra siginfo list holds additional siginfo_t data for signals. kernel code uses psignal() still behavior as before, it won't be failed even under memory pressure, only exception is when deleting a signal, we should call sigqueue_delete to remove signal from sigqueue but not SIGDELSET. Current there is no kernel code will deliver a signal with additional data, so kernel should be as stable as before, a ksiginfo can carry more information, for example, allow signal to be delivered but throw away siginfo data if memory is not enough. SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can not be caught or masked. The sigqueue() syscall allows user code to queue a signal to target process, if resource is unavailable, EAGAIN will be returned as specification said. Just before thread exits, signal queue memory will be freed by sigqueue_flush. Current, all signals are allowed to be queued, not only realtime signals. Earlier patch reviewed by: jhb, deischen Tested on: i386, amd64
* Validate if the value written into {FS,GS}.base is a canonicaldavidxu2005-07-101-1/+6
| | | | | | | | | address, writting non-canonical address can cause kernel a panic, by restricting base values to 0..VM_MAXUSER_ADDRESS, ensuring only canonical values get written to the registers. Reviewed by: peter, Josepha Koshy < joseph.koshy at gmail dot com > Approved by: re (scottl)
* Add new syscall thr_new to create thread in atomic, it willdavidxu2005-04-231-53/+136
| | | | | | | inherit signal mask from parent thread, setup TLS and stack, and user entry address. Also support POSIX thread's PTHREAD_SCOPE_PROCESS and PTHREAD_SCOPE_SYSTEM, sysctl is also provided to control the scheduler scope.
* /* -> /*- for copyright notices, minor format tweaks as necessaryimp2005-01-061-1/+1
|
* If a thread is resumed by thr_wake, it should return 0, especially itdavidxu2004-12-011-5/+15
| | | | | | should not return ERESTART after it caught a signal, otherwise thr_wake() call will be lost, also a timeout wait should not be restarted. Final, using wakeup not wakeup_one to be safeness.
* Remove local definitions of RANGEOF() and use __rangeof() instead.das2004-11-201-10/+4
| | | | Also remove a few bogus casts.
* Close a race between a thread exiting and the freeing of it's stack.mtm2004-10-061-1/+5
| | | | | | | | | After some discussion the best option seems to be to signal the thread's death from within the kernel. This requires that thr_exit() take an argument. Discussed with: davidxu, deischen, marcel MFC after: 3 days
* Close a race between thr_create and sysctl -w, the thr_scope_sys coulddavidxu2004-10-061-7/+10
| | | | be changed when thr_create is running, and we tested it for several times.
* fix typojulian2004-09-071-1/+1
| | | | MFC after: 2 days
* Give libthr a choice (per system) of scope_system or scope_threadjulian2004-09-071-10/+37
| | | | | | scheduling. MFC after: 4 days
* Refactor a bunch of scheduler code to give basically the same behaviourjulian2004-09-051-102/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | but with slightly cleaned up interfaces. The KSE structure has become the same as the "per thread scheduler private data" structure. In order to not make the diffs too great one is #defined as the other at this time. The KSE (or td_sched) structure is now allocated per thread and has no allocation code of its own. Concurrency for a KSEGRP is now kept track of via a simple pair of counters rather than using KSE structures as tokens. Since the KSE structure is different in each scheduler, kern_switch.c is now included at the end of each scheduler. Nothing outside the scheduler knows the contents of the KSE (aka td_sched) structure. The fields in the ksegrp structure that are to do with the scheduler's queueing mechanisms are now moved to the kg_sched structure. (per ksegrp scheduler private data structure). In other words how the scheduler queues and keeps track of threads is no-one's business except the scheduler's. This should allow people to write experimental schedulers with completely different internal structuring. A scheduler call sched_set_concurrency(kg, N) has been added that notifies teh scheduler that no more than N threads from that ksegrp should be allowed to be on concurrently scheduled. This is also used to enforce 'fainess' at this time so that a ksegrp with 10000 threads can not swamp a the run queue and force out a process with 1 thread, since the current code will not set the concurrency above NCPU, and both schedulers will not allow more than that many onto the system run queue at a time. Each scheduler should eventualy develop their own methods to do this now that they are effectively separated. Rejig libthr's kernel interface to follow the same code paths as linkse for scope system threads. This has slightly hurt libthr's performance but I will work to recover as much of it as I can. Thread exit code has been cleaned up greatly. exit and exec code now transitions a process back to 'standard non-threaded mode' before taking the next step. Reviewed by: scottl, peter MFC after: 1 week
* Give setrunqueue() and sched_add() more of a clue as tojulian2004-09-011-1/+1
| | | | | | where they are coming from and what is expected from them. MFC after: 2 days
* When calling scheduler entrypoints for creating new threads and processes,julian2004-07-181-2/+2
| | | | | | | | | | | specify "us" as the thread not the process/ksegrp/kse. You can always find the others from the thread but the converse is not true. Theorotically this would lead to runtime being allocated to the wrong entity in some cases though it is not clear how often this actually happenned. (would only affect threaded processes and would probably be pretty benign, but it WAS a bug..) Reviewed by: peter
* writers must hold both sched_lock and the process lock; therefore, readersmtm2004-07-121-5/+2
| | | | need only obtain the process lock.
OpenPOWER on IntegriCloud