summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_taskqueue.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r306441 and r306634:hselasky2016-10-101-1/+22
| | | | | | | | | | | | | | | | | | | | | | | While draining a timeout task prevent the taskqueue_enqueue_timeout() function from restarting the timer. Commonly taskqueue_enqueue_timeout() is called from within the task function itself without any checks for teardown. Then it can happen the timer stays active after the return of taskqueue_drain_timeout(), because the timeout and task is drained separately. This patch factors out the teardown flag into the timeout task itself, allowing existing code to stay as-is instead of applying a teardown flag to each and every of the timeout task consumers. Add assert to taskqueue_drain_timeout() which prevents parallel execution on the same timeout task. Update manual page documenting the return value of taskqueue_enqueue_timeout(). Differential Revision: https://reviews.freebsd.org/D8012 Reviewed by: kib, trasz
* While the thread is sleeping in taskqueue_drain_all() it isjulian2016-10-101-3/+20
| | | | | | | | | | posible that the queue entry it is looking at is removed from the queue, but we make no effort to account for this. when we wake up we need to check it's still there. PR: 209580 Sponsored by: Panzura inc Differential Revision: D8160
* MFC r256613, r256862: MFprojects/camlock r254763:mav2016-03-201-4/+21
| | | | | | Move tq_enqueue() call out of the queue lock for known handlers (actually I have found no others in the base system). This reduces queue lock hold time and congestion spinning under active multithreaded enqueuing.
* MFC r256612: MFprojects/camlock r254685:mav2016-03-201-6/+1
| | | | Remove TQ_FLAGS_PENDING flag, softly duplicating queue emptiness status.
* MFC r258713,262062: add taskqueue_drain_allavg2014-02-171-0/+30
|
* MFC r258354: taskqueue_cancel: garbage collect a write-only variableavg2014-01-161-2/+0
|
* MFprojects/camlock r254460:mav2013-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.
* Extend taskqueue(9) to enable per-taskqueue callbacks.will2013-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
* Add a special meaning to the negative ticks argument forkib2012-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
* Shorten the name of the fast SWI taskqueue to "fast taskq" so thatjhb2012-08-281-1/+1
| | | | | | | it fits. Reported by: lev MFC after: 1 week
* Ensure that ta_pending doesn't overflow u_short by capping its value at ↵adrian2011-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
* Implement the delayed task execution extension to the taskqueuekib2011-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
* taskqueue: drop unused tq_name fieldavg2010-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
* Use macros rather than inline functions to lock and unlock mutexes, so thatjmallett2010-11-081-17/+15
| | | | | | line number information is preserved in witness. Reviewed by: jhb
* Add a taskqueue_cancel(9) to cancel a pending task without waiting formdf2010-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
* Use a safer mechanism for determining if a task is currently running,mdf2010-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
* Re-expose and briefly document taskqueue_run(9). The function is usedmdf2010-10-121-3/+1
| | | | | | in at least one 3rd party driver. Requested by: jhb
* Run all tasks from a proper context, with proper priority, etc.pjd2010-08-281-1/+1
| | | | | Reviewed by: jhb MFC after: 1 month
* Simplify taskqueue_drain() by using proved macros.pjd2010-08-131-14/+7
|
* Remove unused variable that snuck in during development.mdf2010-07-221-2/+1
| | | | Approved by: zml (mentor)
* Fix taskqueue_drain(9) to not have false negatives. For threadedmdf2010-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)
* fix a few cases where a string is passed via format argument instead ofavg2010-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
* Revert taskqueue(9) related commits until mdf@ is approved and canzml2010-06-011-14/+6
| | | | | | resolve issues. This reverts commits r207439, r208623, r208624
* Avoid a wakeup(9) if we can be sure no one is waiting on the task.zml2010-05-281-3/+11
| | | | | Submitted by: Matthew Fleming <matthew.fleming@isilon.com> Reviewed by: zml, jhb
* Revert r207439 and solve the problem differently. The task handlerzml2010-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
* Handle taskqueue_drain(9) correctly on a threaded taskqueue:zml2010-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)
* - Fix several off-by-one errors when using MAXCOMLEN. The p_comm[] andjhb2009-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
* Remove unused taskqueue_find() function.pjd2009-08-181-43/+0
| | | | | Reviewed by: dfr Approved by: re (kib)
* Remove OpenSolaris taskq port (it performs very poorly in our kernel) andpjd2009-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)
* Because taskqueue_run() can drop tq_mutex, we need to check if thepjd2009-08-171-0/+7
| | | | | | | TQ_FLAGS_ACTIVE flag wasn't removed in the meantime, which means we missed a wakeup. Approved by: re (kib)
* Remove semicolon left in the last committhompsa2009-02-131-1/+1
| | | | Spotted by: csjp
* Check the exit flag at the start of the taskqueue loop rather than the end. Itthompsa2009-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
* Use NULL in preference to 0 for pointers.imp2009-02-031-5/+5
|
* revert local changekmacy2008-07-181-176/+27
|
* import vendor fixes to cxgbkmacy2008-07-181-27/+176
|
* Use kthread_exit() to terminate a taskqueue thread rather than kproc_exit()jhb2008-04-111-1/+1
| | | | | | now that the taskqueue threads are kthreads rather than kprocs. Reported by: kris
* change taskqueue_start_threads to create threads instead of proc'ssam2008-04-081-22/+24
| | | | Reviewed by: jhb
* Implement taskqueue_block() and taskqueue_unblock(). These functions allowscottl2008-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
* Rename the kthread_xxx (e.g. kthread_create()) callsjulian2007-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.
* Commit 14/14 of sched_lock decomposition.jeff2007-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)
* - 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}.
* When starting up threads in taskqueue_start_threads create themsam2006-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
* Change msleep() and tsleep() to not alter the calling thread's priorityjhb2006-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.
* fixup error handling in taskqueue_start_threads: check for kthread_createsam2006-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
* Add the following to the taskqueue api:scottl2006-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.
* The interlock in taskqueue_terminate() is completely wrong for taskqueuesscottl2006-01-111-5/+1
| | | | that use spinlocks. Remove it for now.
* Add functions and macros and refactor code to make it easier to managescottl2006-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
* Create the taskqueue_fast handler with INTR_MPSAFE so that it doesn't runscottl2005-12-231-1/+1
| | | | | | with Giant. MFC After: 3 days
* Use shorter names for the Giant and fast taskqueues so that their namesjhb2005-10-251-2/+2
| | | | actually fit.
* Revert previous change to this file. I accidentally committed whilejhb2005-10-241-19/+0
| | | | fixing spelling in a comment.
OpenPOWER on IntegriCloud