summaryrefslogtreecommitdiff
path: root/sys/kern/kern_synch.c
AgeCommit message (Collapse)Author
2015-09-11introduce a wrapper around reference counts called refcnt.David Gwynne
its basically atomic inc/dec, but it includes magical sleep code in refcnt_finalise that is better written once than many times. refcnt_finalise sleeps until all references are released and does so with sleep_setup and sleep_finalize, which is fairly subtle. putting this in now so i we can get on with work in the stack, a proper discussion about visibility and how available intrinsics should be in the kernel can happen after next week. with help from guenther@ ok guenther@ deraadt@ mpi@
2015-09-07Delete ktracing of context switches: it's unused, and not particularly useful,Philip Guenther
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too complicated, making it harder to move forward on MP changes. ok deraadt@ kettenis@
2015-05-12Drop and reacquire the kernel lock in the vfs_shutdown and "cold"Mike Belopuhov
portions of msleep and tsleep to give interrupts a chance to run on other CPUs. Tweak and OK kettenis
2015-05-07msleep(9) must prevent kernel from attempting a context switchMike Belopuhov
during autoconf and after panics. Tweak and OK guenther, OK miod
2015-03-14Remove some includes include-what-you-use claims don'tJonathan Gray
have any direct symbols used. Tested for indirect use by compiling amd64/i386/sparc64 kernels. ok tedu@ deraadt@
2015-02-10assert that we hold the scheduler lock in unsleep()Bret Lambert
ok guenther@
2015-02-09we want to defer work traditionally (in openbsd) handled in anDavid Gwynne
interrupt context to a taskq running in a thread. however, there is a concern that if we do that then we allow accidental use of sleeping APIs in this work, which will make it harder to move the work back to interrupts in the future. guenther and kettenis came up with the idea of marking a proc with CANTSLEEP which the sleep paths can check and panic on. this builds on that so you create taskqs that run with CANTSLEEP set except when they need to sleep for more tasks to run. the taskq_create api is changed to take a flags argument so users can specify CANTSLEEP. MPSAFE is also passed via this flags field now. this means archs that defined IPL_MPSAFE to 0 can now create mpsafe taskqs too. lots of discussion at s2k15 ok guenther@ miod@ mpi@ tedu@ pelikan@
2014-07-08decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.hTheo de Raadt
don't need to be married. ok guenther miod beck jsing kettenis
2014-03-22Move p_sigacts from struct proc to struct process.Philip Guenther
testing help mpi@
2014-01-23msleep() with a NULL mtx argument is a programming error.Philip Guenther
ok matthew@ phessler@ dlg@
2014-01-23Waiting on a condition without a lock is an error: you need *some* lockPhilip Guenther
to guarantee there isn't a window in which you can lose a wakeup. The exception for tsleep() is when it's just being used to sleep for a period of time, so permit that too. ok jsing@ deraadt@
2013-12-24get rid of if (timeout_pending()) timeout_del(). this is racy. anyDavid Gwynne
conditionals you did on timeout_pending can now be done on timeout_del now that it returns what it did. ok and a very good fix from kettenis@
2013-11-25rename magicnumber to globalsleepaddrTed Unangst
2013-11-18hack in a global rendezvous for interprocess semaphores to useTed Unangst
2013-11-09Add KASSERT()s to tsleep() and msleep() to verify that bogus flagsPhilip Guenther
aren't being passed to them. Fix UVM_WAIT() to not pass PNORELOCK to tsleep(), as that flag only does something with msleep(). ok beck@ dlg@
2013-09-14Snapshots for all archs have been built, so remove the T32 codePhilip Guenther
2013-08-13Switch time_t, ino_t, clock_t, and struct kevent's ident and dataPhilip Guenther
members to 64bit types. Assign new syscall numbers for (almost all) the syscalls that involve the affected types, including anything with time_t, timeval, itimerval, timespec, rusage, dirent, stat, or kevent arguments. Add a d_off member to struct dirent and replace getdirentries() with getdents(), thus immensely simplifying and accelerating telldir/seekdir. Build perl with -DBIG_TIME. Bump the major on every single base library: the compat bits included here are only good enough to make the transition; the T32 compat option will be burned as soon as we've reached the new world are are happy with the snapshots for all architectures. DANGER: ABI incompatibility. Updating to this kernel requires extra work or you won't be able to login: install a snapshot instead. Much assistance in fixing userland issues from deraadt@ and tedu@ and build assistance from todd@ and otto@
2013-06-01cleanup and consolidate the spinlock_lock (what a name!) code.Ted Unangst
it's now atomic_lock to better reflect its usage, and librthread now features a new spinlock that's really a ticket lock. thrlseep can handle both types of lock via a flag in the clock arg. (temp back compat hack) remove some old stuff that's accumulated along the way and no longer used. some feedback from dlg, who is concerned with all things ticket lock. (you need to boot a new kernel before installing librthread)
2013-04-06rthreads are always enabled. remove the sysctl.Ted Unangst
ok deraadt guenther kettenis matthew
2012-08-21Stop "inlining" setrunnable() we already had two bugs because of it.Christiano F. Haesbaert
This also makes sure we call cpu_unidle() on the correct cpu, since the inlining order was wrong and could call it on the old cpu. ok kettenis@
2012-07-10We should only call need_resched() if the priority is lower than theChristiano F. Haesbaert
priority of the current running process. In amd64 a call to need_resched() sends an IPI to the other cpu. This fixes aja@ problem where he would move the mouse and see 60000 IPIs being sent. Thanks to mikeb@ for bringing that subject up tuesday. Actually found this after inquiring guenther@ about some changes in mi_switch(). ok guenther@ aja@
2012-04-10When converting the timeout to ticks, both round up and add one to accountPhilip Guenthe
for the tick that we're already in the middle of. noted and tested by aja; ok kurt@
2012-03-23Make rusage totals, itimers, and profile settings per-process insteadPhilip Guenthe
of per-rthread. Handling of per-thread tick and runtime counters inspired by how FreeBSD does it. ok kettenis@
2012-03-19Add tracing and dumping of "pointer to struct" syscall arguments forPhilip Guenthe
structs timespec, timeval, sigaction, and rlimit. ok otto@ jsing@
2012-01-17Reimplement mutexes, condvars, and rwlocks to eliminate bugs,Philip Guenthe
particularly the "consume the signal you just sent" hang, and putting the wait queues in userspace. Do cancellation handling in pthread_cond_*wait(), pthread_join(), and sem_wait(). Add __ prefix to thr{sleep,wakeup,exit,sigdivert}() syscalls; add 'abort" argument to thrsleep to close cancellation race; make thr{sleep,wakeup} return errno values via *retval to avoid touching userspace errno.
2011-12-11Suspend other rthreads before dumping core or execing; make them exitPhilip Guenthe
when exec succeeds. ok jsing@
2011-07-07Functions used in files other than where they are defined should bePhilip Guenthe
declared in .h files, not in each .c. Apply that rule to endtsleep(), scheduler_start(), updatepri(), and realitexpire() ok deraadt@ tedu@
2011-01-25Don't ignore copyout() return value in sys_thrsleep().Stefan Sperling
Spotted by miod some time ago. ok miod guenther
2010-06-29Eliminate RTHREADS kernel option in favor of a sysctl. The actual statusTed Unangst
(not done) hasn't changed, but now it's less work to test things. ok art deraadt
2010-06-10Declare safepri at the MD level on each platform, so that the kern_synch.cTheo de Raadt
does not have to deal with it as a common. Some platforms may be missed by this commit... if you spot one, fix it the same way. ok miod
2009-12-27Correct previous commit: match the errno return by thrsleep() inPhilip Guenthe
the already-timed-out case to be the same (EWOULDBLOCK) as when it times out after sleeping
2009-11-27Convert thrsleep() to an absolute timeout with clockid to eliminate aPhilip Guenthe
race condition and prep for later support of pthread_condattr_setclock() "get it in" deraadt@, tedu@, cheers by others
2009-06-04unfuck msleep - fixed by art and ariane after much horror and teeth gnashingBob Beck
over why the processes were being woken up at splvm after the page daemon ran - and probably also had the page daemon running at splvm after the first pass through the loop. ok art@ weingart@ oga@ ariane@
2009-06-02Change the wait-channel type to 'const volatile void *', eliminatingPhilip Guenthe
the need for casts when calling tsleep(), msleep(), and wakeup(). "I guess so" oga@ "it's masturbation" art@
2009-04-14Some tweaks to the cpu affinity code.Artur Grabowski
- Split up choosing of cpu between fork and "normal" cases. Fork is very different and should be treated as such. - Instead of implicitly choosing a cpu in setrunqueue, do it outside where it actually makes sense. - Just because a cpu is marked as idle doesn't mean it will be soon. There could be a thundering herd effect if we call wakeup from an interrupt handler, so subtract cpus with queued processes when deciding which cpu is actually idle. - some simplifications allowed by the above. kettenis@ ok (except one bugfix that was not in the intial diff)
2009-03-23Processor affinity for processes.Artur Grabowski
- Split up run queues so that every cpu has one. - Make setrunqueue choose the cpu where we want to make this process runnable (this should be refined and less brutal in the future). - When choosing the cpu where we want to run, make some kind of educated guess where it will be best to run (very naive right now). Other: - Set operations for sets of cpus. - load average calculations per cpu. - sched_is_idle() -> curcpu_is_idle() tested, debugged and prodded by many@
2008-09-10There's no need to fully traverse the wakeup queue when waking a specificBret Lambert
process sleeping on a unique address (wakeup -> wakeup_one) ok guenther@, tedu@, art@
2008-09-05Back out previous. Art realised a problem with it.Owain Ainsworth
2008-09-05Don't overwrite the old ipl in msleep if PNORELOCK was set.Artur Grabowski
2008-09-05When munging the WANTIPL of the mutex to prevent undoing the sched_lock,Owain Ainsworth
use the constant for IPL_SCHED, and not splsched(), which doesn't do what we want. ok art@. Tested by Paul de Weerd.
2007-11-30Fix msleep.Owain Ainsworth
Since mutexes mess around with spl levels, and the sched-lock isn't a mutex, we need to make sure to fix the IPL when msleep does the locking. ok art.
2007-11-28Add msleep. This is identical to tsleep but it takes a mutex as aOwain Ainsworth
parameter. The mutex is unlocked just before sleep and relocked after unless P_NORELOCK is in flags, in which case it is left unlocked. ok art@.
2007-10-10Make context switching much more MI:Artur Grabowski
- Move the functionality of choosing a process from cpu_switch into a much simpler function: cpu_switchto. Instead of having the locore code walk the run queues, let the MI code choose the process we want to run and only implement the context switching itself in MD code. - Let MD context switching run without worrying about spls or locks. - Instead of having the idle loop implemented with special contexts in MD code, implement one idle proc for each cpu. make the idle loop MI with MD hooks. - Change the proc lists from the old style vax queues to TAILQs. - Change the sleep queue from vax queues to TAILQs. This makes wakeup() go from O(n^2) to O(n) there will be some MD fallout, but it will be fixed shortly. There's also a few cleanups to be done after this. deraadt@, kettenis@ ok
2007-05-16The world of __HAVEs and __HAVE_NOTs is reducing. All architecturesArtur Grabowski
have cpu_info now, so kill the option. eyeballed by jsg@ and grange@
2007-04-03Start moving state that is shared among threads in a process intoArtur Grabowski
a new struct. Instead of doing a huge rename and deal with the fallout for weeks, like other projects that need no mention, we will slowly and carefully move things out of struct proc into a new struct process. - Create struct process and the infrastructure to create and remove them. - Move threads in a process into struct process. deraadt@, tedu@ ok
2007-03-21Split tsleep into pieces. Instead of doing everything in a large "shoveArtur Grabowski
everything into it" function, there are now 6 stages of tsleep with an on-stack (remember that kernel stacks are not swappable now?) structure that keeps track of the state. This way we first setup the sleep, setup the events that might break the sleep, finish the sleep (actually sleeping) and then take care of the events that could wake us up. In the future this will make it easier to implement functionality like: setup sleep, release lock or check some condition, finish sleep, in a race-free way and without duplicating or complicating the tsleep function too much. miod@, millert@ ok.
2007-03-18Don't restart thrsleep after a signal. After a signal happened and weArtur Grabowski
weren't on the sleep queues, the condition we were sleeping on might have changed, so we need to go back to userland and recheck that condition. This fixes the majority of lockups and and hanging threads in rthreads since it fixes a race in the semaphore code. ok tedu@
2007-03-15Since p_flag is often manipulated in interrupts and without biglockArtur Grabowski
it's a good idea to use atomic.h operations on it. This mechanic change updates all bit operations on p_flag to atomic_{set,clear}bits_int. Only exception is that P_OWEUPC is set by MI code before calling need_proftick and it's automatically cleared by ADDUPC. There's no reason for MD handling of that flag since everyone handles it the same way. kettenis@ ok
2006-11-29Kernel stack can be swapped. This means that stuff that's on the stackMiod Vallat
should never be referenced outside the context of the process to which this stack belongs unless we do the PHOLD/PRELE dance. Loads of code doesn't follow the rules here. Instead of trying to track down all offenders and fix this hairy situation, it makes much more sense to not swap kernel stacks. From art@, tested by many some time ago.
2006-10-21tbert sent me a diff to change some 0 to NULLTed Unangst
i got carried away and deleted a whole bunch of useless casts this is C, not C++. ok md5