aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_taskqueue.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r258713,262062: add taskqueue_drain_allAndriy Gapon2014-02-171-0/+30
| | | | Notes: svn path=/stable/10/; revision=262065
* MFC r258354: taskqueue_cancel: garbage collect a write-only variableAndriy Gapon2014-01-161-2/+0
| | | | Notes: svn path=/stable/10/; revision=260723
* MFprojects/camlock r254460:Alexander Motin2013-08-241-2/+0
| | | | | | | | | Remove locking from taskqueue_member(). The list of threads is static during the taskqueue life cycle, so there is no need to protect it, taking quite congested lock several more times for each ZFS I/O. Notes: svn path=/head/; revision=254787
* Extend taskqueue(9) to enable per-taskqueue callbacks.Will Andrews2013-03-231-3/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The scope of these callbacks is primarily to support actions that affect the taskqueue's thread environments. They are entirely optional, and consequently are introduced as a new API: taskqueue_set_callback(). This interface allows the caller to specify that a taskqueue requires a callback and optional context pointer for a given callback type. The callback types included in this commit can be used to register a constructor and destructor for thread-local storage using osd(9). This allows a particular taskqueue to define that its threads require a specific type of TLS, without the need for a specially-orchestrated task-based mechanism for startup and shutdown in order to accomplish it. Two callback types are supported at this point: - TASKQUEUE_CALLBACK_TYPE_INIT, called by every thread when it starts, prior to processing any tasks. - TASKQUEUE_CALLBACK_TYPE_SHUTDOWN, called by every thread when it exits, after it has processed its last task but before the taskqueue is reclaimed. While I'm here: - Add two new macros, TQ_ASSERT_LOCKED and TQ_ASSERT_UNLOCKED, and use them in appropriate locations. - Fix taskqueue.9 to mention taskqueue_start_threads(), which is a required interface for all consumers of taskqueue(9). Reviewed by: kib (all), eadler (taskqueue.9), brd (taskqueue.9) Approved by: ken (mentor) Sponsored by: Spectra Logic MFC after: 1 month Notes: svn path=/head/; revision=248649
* Add a special meaning to the negative ticks argument forKonstantin Belousov2012-11-201-2/+6
| | | | | | | | | | | | | | | | | | | taskqueue_enqueue_timeout(). Do not rearm the callout if it is already armed and the ticks is negative. Otherwise rearm it to fire in abs(ticks) ticks in the future. The intended use is to call taskqueue_enqueue_timeout() for the given timeout_task with the same negative ticks argument. As result, the task is scheduled to execute not further than abs(ticks) ticks in future, and the consequent enqueues are coalesced until the already scheduled task is finished. Reviewed by: rwatson Tested by: Markus Gebert <markus.gebert@hostpoint.ch> MFC after: 2 weeks Notes: svn path=/head/; revision=243341
* Shorten the name of the fast SWI taskqueue to "fast taskq" so thatJohn Baldwin2012-08-281-1/+1
| | | | | | | | | | it fits. Reported by: lev MFC after: 1 week Notes: svn path=/head/; revision=239779
* Ensure that ta_pending doesn't overflow u_short by capping its value at ↵Adrian Chadd2011-09-151-1/+3
| | | | | | | | | | | | | | | | USHRT_MAX. If it overflows before the taskqueue can run, the task will be re-added to the taskqueue and cause a loop in the task list. Reported by: Arnaud Lacombe <lacombar@gmail.com> Submitted by: Ryan Stone <rysto32@gmail.com> Reviewed by: jhb Approved by: re (kib) MFC after: 1 day Notes: svn path=/head/; revision=225570
* Implement the delayed task execution extension to the taskqueueKonstantin Belousov2011-04-261-13/+115
| | | | | | | | | | | | mechanism. The caller may specify a timeout in ticks after which the task will be scheduled. Sponsored by: The FreeBSD Foundation Reviewed by: jeff, jhb MFC after: 1 month Notes: svn path=/head/; revision=221059
* taskqueue: drop unused tq_name fieldAndriy Gapon2010-11-231-3/+1
| | | | | | | | | | | | | | | tq_name was used write-only and besides it was just a pointer, so it could point to some garbage in a temporary buffer that's gone. This change shouldn't change KPI/KBI as struct taskqueue is private to subr_taskqueue.c. If we find a need for tq_name it can be resurrected at any moment. taskqueue_create() interface is preserved for this purpose. Suggested by: jhb MFC after: 10 days Notes: svn path=/head/; revision=215750
* Use macros rather than inline functions to lock and unlock mutexes, so thatJuli Mallett2010-11-081-16/+14
| | | | | | | | | line number information is preserved in witness. Reviewed by: jhb Notes: svn path=/head/; revision=215021
* Add a taskqueue_cancel(9) to cancel a pending task without waiting forMatthew D Fleming2010-11-081-0/+18
| | | | | | | | | | | | it to run as taskqueue_drain(9) does. Requested by: hselasky Original code: jeff Reviewed by: jhb MFC after: 2 weeks Notes: svn path=/head/; revision=215011
* Use a safer mechanism for determining if a task is currently running,Matthew D Fleming2010-10-131-30/+45
| | | | | | | | | | | that does not rely on the lifetime of pointers being the same. This also restores the task KBI. Suggested by: jhb MFC after: 1 month Notes: svn path=/head/; revision=213813
* Re-expose and briefly document taskqueue_run(9). The function is usedMatthew D Fleming2010-10-121-3/+1
| | | | | | | | | in at least one 3rd party driver. Requested by: jhb Notes: svn path=/head/; revision=213739
* Run all tasks from a proper context, with proper priority, etc.Pawel Jakub Dawidek2010-08-281-1/+1
| | | | | | | | Reviewed by: jhb MFC after: 1 month Notes: svn path=/head/; revision=211928
* Simplify taskqueue_drain() by using proved macros.Pawel Jakub Dawidek2010-08-131-14/+7
| | | | Notes: svn path=/head/; revision=211284
* Remove unused variable that snuck in during development.Matthew D Fleming2010-07-221-2/+1
| | | | | | | Approved by: zml (mentor) Notes: svn path=/head/; revision=210380
* Fix taskqueue_drain(9) to not have false negatives. For threadedMatthew D Fleming2010-07-221-23/+38
| | | | | | | | | | | | | | | | | taskqueues, more than one task can be running simultaneously. Also make taskqueue_run(9) static to the file, since there are no consumers in the base kernel and the function signature needs to change with this fix. Remove mention of taskqueue_run(9) and taskqueue_run_fast(9) from the taskqueue(9) man page. Reviewed by: jhb Approved by: zml (mentor) Notes: svn path=/head/; revision=210377
* fix a few cases where a string is passed via format argument instead ofAndriy Gapon2010-06-111-1/+1
| | | | | | | | | | | | | via %s Most of the cases looked harmless, but this is done for the sake of correctness. In one case it even allowed to drop an intermediate buffer. Found by: clang MFC after: 2 week Notes: svn path=/head/; revision=209062
* Revert taskqueue(9) related commits until mdf@ is approved and canZachary Loafman2010-06-011-14/+6
| | | | | | | | | resolve issues. This reverts commits r207439, r208623, r208624 Notes: svn path=/head/; revision=208715
* Avoid a wakeup(9) if we can be sure no one is waiting on the task.Zachary Loafman2010-05-281-3/+11
| | | | | | | | Submitted by: Matthew Fleming <matthew.fleming@isilon.com> Reviewed by: zml, jhb Notes: svn path=/head/; revision=208624
* Revert r207439 and solve the problem differently. The task handlerZachary Loafman2010-05-281-6/+5
| | | | | | | | | | | | ta_func may free the task structure, so no references to its members are valid after the handler has been called. Using a per-queue member and having waits longer than strictly necessary was suggested by jhb. Submitted by: Matthew Fleming <matthew.fleming@isilon.com> Reviewed by: zml, jhb Notes: svn path=/head/; revision=208623
* Handle taskqueue_drain(9) correctly on a threaded taskqueue:Zachary Loafman2010-04-301-5/+6
| | | | | | | | | | | | | | | taskqueue_drain(9) will not correctly detect whether a task is currently running. The check is against a field in the taskqueue struct, but for a threaded queue with more than one thread, multiple threads can simultaneously be running a task, thus stomping over the tq_running field. Submitted by: Matthew Fleming <matthew.fleming@isilon.com> Reviewed by: jhb Approved by: dfr (mentor) Notes: svn path=/head/; revision=207439
* - Fix several off-by-one errors when using MAXCOMLEN. The p_comm[] andJohn Baldwin2009-10-231-2/+2
| | | | | | | | | | | | | | | | td_name[] arrays are actually MAXCOMLEN + 1 in size and a few places that created shadow copies of these arrays were just using MAXCOMLEN. - Prefer using sizeof() of an array type to explicit constants for the array length in a few places. - Ensure that all of p_comm[] and td_name[] is always zero'd during execve() to guard against any possible information leaks. Previously trailing garbage in p_comm[] could be leaked to userland in ktrace record headers via td_name[]. Reviewed by: bde Notes: svn path=/head/; revision=198411
* Remove unused taskqueue_find() function.Pawel Jakub Dawidek2009-08-181-43/+0
| | | | | | | | Reviewed by: dfr Approved by: re (kib) Notes: svn path=/head/; revision=196358
* Remove OpenSolaris taskq port (it performs very poorly in our kernel) andPawel Jakub Dawidek2009-08-171-0/+20
| | | | | | | | | | | replace it with wrappers around our taskqueue(9). To make it possible implement taskqueue_member() function which returns 1 if the given thread was created by the given taskqueue. Approved by: re (kib) Notes: svn path=/head/; revision=196295
* Because taskqueue_run() can drop tq_mutex, we need to check if thePawel Jakub Dawidek2009-08-171-0/+7
| | | | | | | | | | TQ_FLAGS_ACTIVE flag wasn't removed in the meantime, which means we missed a wakeup. Approved by: re (kib) Notes: svn path=/head/; revision=196293
* Remove semicolon left in the last commitAndrew Thompson2009-02-131-1/+1
| | | | | | | Spotted by: csjp Notes: svn path=/head/; revision=188592
* Check the exit flag at the start of the taskqueue loop rather than the end. ItAndrew Thompson2009-02-131-2/+2
| | | | | | | | | | | is possible to tear down the taskqueue before the thread has run and the taskqueue loop would sleep forever. Reviewed by: sam MFC after: 1 week Notes: svn path=/head/; revision=188548
* Use NULL in preference to 0 for pointers.Warner Losh2009-02-031-5/+5
| | | | Notes: svn path=/head/; revision=188058
* revert local changeKip Macy2008-07-181-175/+26
| | | | Notes: svn path=/head/; revision=180588
* import vendor fixes to cxgbKip Macy2008-07-181-26/+175
| | | | Notes: svn path=/head/; revision=180583
* Use kthread_exit() to terminate a taskqueue thread rather than kproc_exit()John Baldwin2008-04-111-1/+1
| | | | | | | | | now that the taskqueue threads are kthreads rather than kprocs. Reported by: kris Notes: svn path=/head/; revision=178123
* change taskqueue_start_threads to create threads instead of proc'sSam Leffler2008-04-081-22/+24
| | | | | | | Reviewed by: jhb Notes: svn path=/head/; revision=178015
* Implement taskqueue_block() and taskqueue_unblock(). These functions allowScott Long2008-03-251-1/+28
| | | | | | | | | | | | | the owner of a queue to block and unblock execution of the tasks in the queue while allowing tasks to continue to be added queue. Combining this with taskqueue_drain() allows a queue to be safely disabled. The unblock function may run (or schedule to run) the queue when it is called, just as calling taskqueue_enqueue() would. Reviewed by: jhb, sam Notes: svn path=/head/; revision=177621
* Rename the kthread_xxx (e.g. kthread_create()) callsJulian Elischer2007-10-201-4/+4
| | | | | | | | | | | | | | to kproc_xxx as they actually make whole processes. Thos makes way for us to add REAL kthread_create() and friends that actually make theads. it turns out that most of these calls actually end up being moved back to the thread version when it's added. but we need to make this cosmetic change first. I'd LOVE to do this rename in 7.0 so that we can eventually MFC the new kthread_xxx() calls. Notes: svn path=/head/; revision=172836
* Commit 14/14 of sched_lock decomposition.Jeff Roberson2007-06-051-2/+2
| | | | | | | | | | | | | | - 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) Notes: svn path=/head/; revision=170307
* - Remove setrunqueue and replace it with direct calls to sched_add().Jeff Roberson2007-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}. Notes: svn path=/head/; revision=166188
* When starting up threads in taskqueue_start_threads create themSam Leffler2006-05-241-9/+16
| | | | | | | | | | | | | | | stopped before adjusting their priority and setting them on the run q so they cannot race for resources (pointed out by njl). While here add a console printf on thread create fails; otherwise noone may notice (e.g. return value is always 0 and caller has no way to verify). Reviewed by: jhb, scottl MFC after: 2 weeks Notes: svn path=/head/; revision=158904
* Change msleep() and tsleep() to not alter the calling thread's priorityJohn Baldwin2006-04-171-1/+1
| | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=157815
* fixup error handling in taskqueue_start_threads: check for kthread_createSam Leffler2006-03-301-11/+20
| | | | | | | | | | | failing, print a message when we fail for some reason as most callers do not check the return value (e.g. 'cuz they're called from SYSINIT) Reviewed by: scottl MFC after: 1 week Notes: svn path=/head/; revision=157314
* Add the following to the taskqueue api:Scott Long2006-01-141-16/+56
| | | | | | | | | | | | | | | | | | | | taskqueue_start_threads(struct taskqueue **, int count, int pri, const char *name, ...); This allows the creation of 1 or more threads that will service a single taskqueue. Also rework the taskqueue_create() API to remove the API change that was introduced a while back. Creating a taskqueue doesn't rely on the presence of a process structure, and the proc mechanics are much better encapsulated in taskqueue_start_threads(). Also clean up the taskqueue_terminate() and taskqueue_free() functions to safely drain pending tasks and remove all associated threads. The TASKQUEUE_DEFINE and TASKQUEUE_DEFINE_THREAD macros have been changed to use the new API, but drivers compiled against the old definitions will still work. Thus, recompiling drivers is not a strict requirement. Notes: svn path=/head/; revision=154333
* The interlock in taskqueue_terminate() is completely wrong for taskqueuesScott Long2006-01-111-5/+1
| | | | | | | that use spinlocks. Remove it for now. Notes: svn path=/head/; revision=154205
* Add functions and macros and refactor code to make it easier to manageScott Long2006-01-101-116/+86
| | | | | | | | | | | | | | | | | | | | | | | | fast taskqueues. The following have been added: TASKQUEUE_FAST_DEFINE() - create a global task queue. an arbitrary execution context. TASKQUEUE_FAST_DEFINE_THREAD() - create a global taskqueue that uses a dedicated kthread. taskqueue_create_fast() - create a local/private taskqueue. These are all complimentary of the standard taskqueue functions. They are primarily useful for fast interrupt handlers that can only use spinlock for synchronization. I personally think that the taskqueue API is starting to get too narrow and hairy, but fixing it will require a major redesign on the API. Such a redesign would be good but would break compatibility with FreeBSD 6.x, so it really isn't desirable at this time. Submitted by: sam Notes: svn path=/head/; revision=154167
* Create the taskqueue_fast handler with INTR_MPSAFE so that it doesn't runScott Long2005-12-231-1/+1
| | | | | | | | | with Giant. MFC After: 3 days Notes: svn path=/head/; revision=153676
* Use shorter names for the Giant and fast taskqueues so that their namesJohn Baldwin2005-10-251-2/+2
| | | | | | | actually fit. Notes: svn path=/head/; revision=151656
* Revert previous change to this file. I accidentally committed whileJohn Baldwin2005-10-241-19/+0
| | | | | | | fixing spelling in a comment. Notes: svn path=/head/; revision=151624
* Spell hierarchy correctly in comments.John Baldwin2005-10-241-0/+19
| | | | | | | Submitted by: Wojciech A. Koszek dunstan at freebsd dot czest dot pl Notes: svn path=/head/; revision=151623
* o enable shutdown of taskqueue threads; the thread servicing the queue checksSam Leffler2005-05-011-10/+38
| | | | | | | | | | | | | | | a new entry in the taskqueue struct each time it wakes up to see if it should terminate o adjust TASKQUEUE_DEFINE_THREAD & co. to record the thread/proc identity for the shutdown rendezvous o replace wakeup after adding a task to a queue with wakeup_one; this helps queues where multiple threads are used to service tasks (e.g. acpi) o remove NULL check of tq_enqueue method; it should never be NULL Reviewed by: dfr, njl Notes: svn path=/head/; revision=145729
* o eliminate modification of task structures after their run to avoidSam Leffler2005-04-241-3/+4
| | | | | | | | | | | | modify-after-free races when the task structure is malloc'd o shrink task structure by removing ta_flags (no longer needed with avoid fix) and combining ta_pending and ta_priority Reviewed by: dwhite, dfr MFC after: 4 days Notes: svn path=/head/; revision=145473
* Add taskqueue_drain. This waits for the specified task to finish, ifWarner Losh2004-10-051-0/+14
| | | | | | | | | | running, or returns. The calling program is responsible for making sure that nothing new is enqueued. # man page coming soon. Notes: svn path=/head/; revision=136131