summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
Commit message (Collapse)AuthorAgeFilesLines
* More work on the interaction between suspending and sleeping threads.julian2002-10-251-7/+10
| | | | | | Also clean up some code used with 'single-threading'. Reviewed by: davidxu
* - Create a new scheduler api that is defined in sys/sched.hjeff2002-10-121-415/+21
| | | | | | | | | | - Begin moving scheduler specific functionality into sched_4bsd.c - Replace direct manipulation of scheduler data with hooks provided by the new api. - Remove KSE specific state modifications and single runq assumptions from kern_switch.c Reviewed by: -arch
* - Move p_cpulimit to struct proc from struct plimit and protect it withjhb2002-10-091-8/+2
| | | | | | | | | | | | | | | sched_lock. This means that we no longer access p_limit in mi_switch() and the p_limit pointer can be protected by the proc lock. - Remove PRS_ZOMBIE check from CPU limit test in mi_switch(). PRS_ZOMBIE processes don't call mi_switch(), and even if they did there is no longer the danger of p_limit being NULL (which is what the original zombie check was added for). - When we bump the current processes soft CPU limit in ast(), just bump the private p_cpulimit instead of the shared rlimit. This fixes an XXX for some value of fix. There is still a (probably benign) bug in that this code doesn't check that the new soft limit exceeds the hard limit. Inspired by: bde (2)
* Round out the facilty for a 'bound' thread to loan out its KSEjulian2002-10-091-21/+11
| | | | | | | | | | | | | | | | | | | | | | | | in specific situations. The owner thread must be blocked, and the borrower can not proceed back to user space with the borrowed KSE. The borrower will return the KSE on the next context switch where teh owner wants it back. This removes a lot of possible race conditions and deadlocks. It is consceivable that the borrower should inherit the priority of the owner too. that's another discussion and would be simple to do. Also, as part of this, the "preallocatd spare thread" is attached to the thread doing a syscall rather than the KSE. This removes the need to lock the scheduler when we want to access it, as it's now "at hand". DDB now shows a lot mor info for threaded proceses though it may need some optimisation to squeeze it all back into 80 chars again. (possible JKH project) Upcalls are now "bound" threads, but "KSE Lending" now means that other completing syscalls can be completed using that KSE before the upcall finally makes it back to the UTS. (getting threads OUT OF THE KERNEL is one of the highest priorities in the KSE system.) The upcall when it happens will present all the completed syscalls to the KSE for selection.
* XXX Add a check for p->p_limit being NULL before dereferencing it. This isjmallett2002-10-031-1/+6
| | | | | | | | totally bogus but will hide the occurances of access of 0xbc(NULL) which people have run into lately. This is not a proper fix, just a bandaid, until the cause of this happening is tracked down and fixed. Reviewed by: rwatson
* Rename the mutex thread and process states to use a more generic 'LOCK'jhb2002-10-021-1/+1
| | | | | | | | | name instead. (e.g., SLOCK instead of SMTX, TD_ON_LOCK() instead of TD_ON_MUTEX()) Eventually a turnstile abstraction will be added that will be shared with mutexes and other types of locks. SLOCK/TDI_LOCK will be used internally by the turnstile code and will not be specific to mutexes. Making the change now ensures that turnstiles can be dropped in at a later date without affecting the ABI of userland applications.
* - Adjust comment noting that handling of CPU limit exhaustion is done injhb2002-10-011-2/+5
| | | | | | | | | | ast(). - Actually set KEF_ASTPENDING so ast() is called. I think this is buggy for a process with multiple KSE's in that PS_XCPU is not a KSE event, it's a process-wide event. IMO there really should probably be two ASTPENDING flags, one for per-process, and one for per-KSE. Submitted by: bde
* - Add a new per-process flag PS_XCPU to indicate that at least one threadjhb2002-09-301-28/+2
| | | | | | | | has exceeded its CPU time limit. - In mi_switch(), set PS_XCPU when the CPU time limit is exceeded. - Perform actual CPU time limit exceeded work in ast() when PS_XCPU is set. Requested by: many
* Implement basic KSE loaning. This stops a hread that is blocked in BOUND modejulian2002-09-291-0/+5
| | | | | | | | | from stopping another thread from completing a syscall, and this allows it to release its resources etc. Probably more related commits to follow (at least one I know of) Initial concept by: julian, dillon Submitted by: davidxu
* Completely redo thread states.julian2002-09-111-125/+63
| | | | Reviewed by: davidxu@freebsd.org
* Rejig the code to figure out estcpu and work out how long a KSEGRP has beenjulian2002-08-301-17/+27
| | | | | | | | | idle. What was there before was surprisingly ALMOST correct. Peter and I fried our brains on this for a couple of hours figuring out what this actually means in the context of multiple threads. Reviewed by: peter@freebsd.org
* updatepri() works on a ksegrp (where the scheduling parameters are), sopeter2002-08-281-17/+18
| | | | | | | directly give it the ksegrp instead of the thread. The only thing it used to use in the thread was the ksegrp. Reviewed by: julian
* Slight cleanup of some comments/whitespace.julian2002-08-011-10/+21
| | | | | | | | | | | | Make idle process state more consistant. Add an assert on thread state. Clean up idleproc/mi_switch() interaction. Use a local instead of referencing curthread 7 times in a row (I've been told curthread can be expensive on some architectures) Remove some commented out code. Add a little commented out code (completion coming soon) Reviewed by: jhb@freebsd.org
* In endtsleep() and cv_timedwait_end(), a thread marked TDF_TIMEOUT maytanimura2002-07-301-2/+11
| | | | | | | | | be swapped out. Do not put such the thread directly back to the run queue. Spotted by: David Xu <davidx@viasoft.com.cn> While I am here, s/PS_TIMEOUT/TDF_TIMEOUT/.
* - Optimize wakeup() and its friends; if a thread waken up is beingtanimura2002-07-301-6/+12
| | | | | | | | | | | | | | swapped in, we do not have to ask for the scheduler thread to do that. - Assert that a process is not swapped out in runq functions and swapout(). - Introduce thread_safetoswapout() for readability. - In swapout_procs(), perform a test that may block (check of a thread working on its vm map) first. This lets us call swapout() with the sched_lock held, providing a better atomicity.
* Create a new thread state to describe threads that would be ready to runjulian2002-07-291-3/+4
| | | | | | | | | | | except for the fact tha they are presently swapped out. Also add a process flag to indicate that the process has started the struggle to swap back in. This will be needed for the case where multiple threads start the swapin action top a collision. Also add code to stop a process fropm being swapped out if one of the threads in this process is actually off running on another CPU.. that might hurt... Submitted by: Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>
* slight stylisations to take into account recent code changes.julian2002-07-241-7/+3
|
* Fix a reversed test.julian2002-07-171-7/+15
| | | | | | | | Fix some style nits. Fix a KASSERT message. Add/fix some comments. Submitted by: bde@freebsd.org
* Add a KASSERT() to assert that td_critnest is == 1 when mi_switch() isjhb2002-07-171-0/+2
| | | | called.
* Allow alphas to do crashdumps: Refuse to run anything in choosethread()gallatin2002-07-171-4/+4
| | | | | | | | | | after a panic which is not an interrupt thread, or the thread which caused the panic. Also, remove panicstr checks from msleep() and from cv_wait() in order to allow threads to go to sleep and yeild the cpu to the panicing thread, or to an interrupt thread which might be doing the crashdump. Reviewed by: jhb (and it was mostly his idea too)
* Thinking about it I came to the conclusion that the KSE states were incorrectlyjulian2002-07-141-13/+4
| | | | | | | | | | | | | | formulated. The correct states should be: IDLE: On the idle KSE list for that KSEG RUNQ: Linked onto the system run queue. THREAD: Attached to a thread and slaved to whatever state the thread is in. This means that most places where we were adjusting kse state can go away as it is just moving around because the thread is.. The only places we need to adjust the KSE state is in transition to and from the idle and run queues. Reviewed by: jhb@freebsd.org
* oops, state cannot be two different values at once..julian2002-07-141-1/+1
| | | | use || instead of &&
* Re-enable the idle page-zeroing code. Remove all IPIs from the idledillon2002-07-121-0/+7
| | | | | | | | | | | | | | | | | page-zeroing code as well as from the general page-zeroing code and use a lazy tlb page invalidation scheme based on a callback made at the end of mi_switch. A number of people came up with this idea at the same time so credit belongs to Peter, John, and Jake as well. Two-way SMP buildworld -j 5 tests (second run, after stabilization) 2282.76 real 2515.17 user 704.22 sys before peter's IPI commit 2266.69 real 2467.50 user 633.77 sys after peter's commit 2232.80 real 2468.99 user 615.89 sys after this commit Reviewed by: peter, jhb Approved by: peter
* make this repect ps_sigintr if there is a pre-existing signaljulian2002-07-061-1/+0
| | | | | | or suspension request. Submitted by: David Xu
* Fix at least one of the things wrong with signalsjulian2002-07-061-6/+9
| | | | | | ^Z should work a lot better now. Submitted by: peter@freebsd.org
* Try clean up some of the mess that resulted from layers and layersjulian2002-07-031-2/+1
| | | | | | of p4 merges from -current as things started getting different. Corroborated by: Similar patches just mailed by BDE.
* When going back to SLEEP state, make sure ourjulian2002-07-021-0/+1
| | | | State is correctly marked so.
* Part 1 of KSE-IIIjulian2002-06-291-80/+195
| | | | | | | | | | | | | The ability to schedule multiple threads per process (one one cpu) by making ALL system calls optionally asynchronous. to come: ia64 and power-pc patches, patches for gdb, test program (in tools) Reviewed by: Almost everyone who counts (at various times, peter, jhb, matt, alfred, mini, bernd, and a cast of thousands) NOTE: this is still Beta code, and contains lots of debugging stuff. expect slight instability in signals..
* more caddr_t removal.alfred2002-06-291-4/+4
|
* I Noticed a defect in the way wakeup() scans the tailq. Tor noticed andillon2002-06-241-3/+8
| | | | | | | even worse defect in wakeup_one(). This patch cleans up both. Submitted by: tegge MFC after: 3 days
* - Catch up to new ktrace API.jhb2002-06-071-7/+5
| | | | - ktrace trace points in msleep() and cv_wait() no longer need Giant.
* CURSIG() is not a macro so rename it cursig().julian2002-05-291-6/+6
| | | | Obtained from: KSE tree
* Minor nit: get p pointer in msleep() from td->td_proc (wherejhb2002-05-231-1/+1
| | | | td == curthread) rather than from curproc.
* Remove __P.alfred2002-03-191-5/+5
|
* Fix a gcc-3.1+ warning.peter2002-03-191-0/+1
| | | | | | | | | | | warning: deprecated use of label at end of compound statement ie: you cannot do this anymore: switch(foo) { .... default: }
* Convert p->p_runtime and PCPU(switchtime) to bintime format.phk2002-02-221-17/+6
|
* In a threaded world, differnt priorirites become properties ofjulian2002-02-111-22/+26
| | | | | | different entities. Make it so. Reviewed by: jhb@freebsd.org (john baldwin)
* Change the preemption code for software interrupt thread schedules andjhb2002-01-051-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mutex releases to not require flags for the cases when preemption is not allowed: The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent switching to a higher priority thread on mutex releease and swi schedule, respectively when that switch is not safe. Now that the critical section API maintains a per-thread nesting count, the kernel can easily check whether or not it should switch without relying on flags from the programmer. This fixes a few bugs in that all current callers of swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from fast interrupt handlers and the swi_sched of softclock needed this flag. Note that to ensure that swi_sched()'s in clock and fast interrupt handlers do not switch, these handlers have to be explicitly wrapped in critical_enter/exit pairs. Presently, just wrapping the handlers is sufficient, but in the future with the fully preemptive kernel, the interrupt must be EOI'd before critical_exit() is called. (critical_exit() can switch due to a deferred preemption in a fully preemptive kernel.) I've tested the changes to the interrupt code on i386 and alpha. I have not tested ia64, but the interrupt code is almost identical to the alpha code, so I expect it will work fine. PowerPC and ARM do not yet have interrupt code in the tree so they shouldn't be broken. Sparc64 is broken, but that's been ok'd by jake and tmm who will be fixing the interrupt code for sparc64 shortly. Reviewed by: peter Tested on: i386, alpha
* Modify the critical section API as follows:jhb2001-12-181-3/+0
| | | | | | | | | | | | | | | | | | | - The MD functions critical_enter/exit are renamed to start with a cpu_ prefix. - MI wrapper functions critical_enter/exit maintain a per-thread nesting count and a per-thread critical section saved state set when entering a critical section while at nesting level 0 and restored when exiting to nesting level 0. This moves the saved state out of spin mutexes so that interlocking spin mutexes works properly. - Most low-level MD code that used critical_enter/exit now use cpu_critical_enter/exit. MI code such as device drivers and spin mutexes use the MI wrappers. Note that since the MI wrappers store the state in the current thread, they do not have any return values or arguments. - mtx_intr_enable() is replaced with a constant CRITICAL_FORK which is assigned to curthread->td_savecrit during fork_exit(). Tested on: i386, alpha
* Add/correct description for some sysctl variables where it was missing.luigi2001-12-161-1/+2
| | | | | | | | The description field is unused in -stable, so the MFC there is equivalent to a comment. It can be done at any time, i am just setting a reminder in 45 days when hopefully we are past 4.5-release. MFC after: 45 days
* Assert that Giant is not held in mi_switch() unless the process statejhb2001-10-231-0/+4
| | | | is SMTX or SRUN.
* Introduce some jitter to the timing of the samples that determineiedowse2001-10-201-4/+15
| | | | | | | | | | | | the system load average. Previously, the load average measurement was susceptible to synchronisation with processes that run at regular intervals such as the system bufdaemon process. Each interval is now chosen at random within the range of 4 to 6 seconds. This large variation is chosen so that over the shorter 5-minute load average timescale there is a good dispersion of samples across the 5-second sample period (the time to perform 60 5-second samples now has a standard deviation of approx 4.5 seconds).
* Move the code that computes the system load average from vm_meter.ciedowse2001-10-201-3/+49
| | | | | | | | | | | | to kern_synch.c in preparation for adding some jitter to the inter-sample time. Note that the "vm.loadavg" sysctl still lives in vm_meter.c which isn't the right place, but it is appropriate for the current (bad) name of that sysctl. Suggested by: jhb (some time ago) Reviewed by: bde
* GC some #if 0'd code.jhb2001-09-211-8/+2
|
* Whitespace and spelling fixes.jhb2001-09-211-2/+2
|
* KSE Milestone 2julian2001-09-121-167/+220
| | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha
* Make yield() MPSAFE.dillon2001-09-011-1/+6
| | | | | | Synchronize syscalls.master with all MPSAFE changes to date. Synchronize new syscall generation follows because yield() will panic if it is out of sync with syscalls.master.
* Release the sched_lock before bombing out in mi_switch() via db_error().jhb2001-08-211-1/+3
| | | | | This makes things slightly easier if you call a function that calls mi_switch() as it keeps the locking before and after closer.
* Add a hook to mi_switch() to abort via db_error() if we attempt tojhb2001-08-211-0/+12
| | | | | | perform a context switch from DDB. Consulting from: bde
* - Fix a bug in the previous workaround for the tsleep/endtsleep race.jhb2001-08-211-2/+5
| | | | | | | | | | | | | | | | callout_stop() would fail in two cases: 1) The timeout was currently executing, and 2) The timeout had already executed. We only needed to work around the race for 1). We caught some instances of 2) via the PS_TIMEOUT flag, however, if endtsleep() fired after the process had been woken up but before it had resumed execution, PS_TIMEOUT would not be set, but callout_stop() would fail, so we would block the process until endtsleep() resumed it. Except that endtsleep() had already run and couldn't resume it. This adds a new flag PS_TIMOFAIL to indicate the case of 2) when PS_TIMEOUT isn't set. - Implement this race fix for condition variables as well. Tested by: sos
OpenPOWER on IntegriCloud