Commit Graph

44 Commits

Author SHA1 Message Date
Justin T. Gibbs
5b326a32ce Prevent live-lock and access of destroyed data in taskqueue_drain_all().
Phabric:	https://reviews.freebsd.org/D1247
Reviewed by:	jhb, avg
Sponsored by:	Spectra Logic Corporation

sys/kern_subr_taskqueue.c:
	Modify taskqueue_drain_all() processing to use a temporary
	"barrier task", rather than rely on a user task that may
	be destroyed during taskqueue_drain_all()'s execution.  The
	barrier task is queued behind all previously queued tasks
	and then has its priority elevated so that future tasks
	cannot pass it in the queue.

	Use a similar barrier scheme to drain threads processing
	current tasks.  This requires taskqueue_run_locked() to
	insert and remove the taskqueue_busy object for the running
	thread for every task processed.

share/man/man9/taskqueue.9:
	Remove warning about live-lock issues with taskqueue_drain_all()
	and indicate that it does not wait for tasks queued after
	it begins processing.
2015-01-04 19:55:44 +00:00
Benjamin Kaduk
ec5d37f4f5 Document taskqueue_start_threads_pinned
Requested by:	adrian
Reviewed by:	adrian
Approved by:	hrs (mentor)
X-MFC-with:	r266629
2014-05-25 02:45:26 +00:00
Andriy Gapon
cb03508f58 update taskqueue(9) manual page
Many thanks to bjk, gjb and pluknet for improvements and suggestions.

MFC after:	5 days
Sponsored by:	HybridCluster
2014-02-14 15:03:55 +00:00
Will Andrews
fdbc71742b Extend taskqueue(9) to enable per-taskqueue callbacks.
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
2013-03-23 15:11:53 +00:00
Konstantin Belousov
c1e231bcbb Fix typo.
Submitted by:	bjk
MFC after:	3 days
2012-12-04 14:07:17 +00:00
Konstantin Belousov
471af3a8df Document the interpretation of the negative value of ticks for
taskqueue_enqueue_timeout(9).

MFC after:	3 days
2012-12-04 00:32:12 +00:00
Glen Barber
73bbeaa529 Typo and mdoc(7) style fixes.
PR:		168117
Submitted by:	Nobuyuki Koganemaru (kogane&jp!freebsd!org)
MFC after:	3 days
2012-05-20 16:43:47 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
John Baldwin
a7f5f7948b Add a TASK_INITIALIZER() macro that can be used to statically
initialize a task structure.

Reviewed by:	gj
MFC after:	2 weeks
2011-12-19 18:55:13 +00:00
Adrian Chadd
d2849f27bc Ensure that ta_pending doesn't overflow u_short by capping its value at 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
2011-09-15 08:42:06 +00:00
Konstantin Belousov
4d066e4519 Fix markup.
Approved by:	re (hrs)
2011-08-01 08:52:05 +00:00
Konstantin Belousov
c3bd10b434 Document timeout_task.
While there, fix the type of the func argument of INIT_TASK macro,
and use the modern name of the analogous facility from Linux kernel.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
2011-04-26 11:43:57 +00:00
Matthew D Fleming
f46276a9b0 Add a taskqueue_cancel(9) to cancel a pending task without waiting for
it to run as taskqueue_drain(9) does.

Requested by:	hselasky
Original code:	jeff
Reviewed by:	jhb
MFC after:	2 weeks
2010-11-08 20:56:31 +00:00
Matthew D Fleming
bf73d4d28e Use a safer mechanism for determining if a task is currently running,
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
2010-10-13 22:59:04 +00:00
Matthew D Fleming
a92f0ee866 Re-expose and briefly document taskqueue_run(9). The function is used
in at least one 3rd party driver.

Requested by:	jhb
2010-10-12 18:36:03 +00:00
Joel Dahl
9ba4735280 Spelling fixes. 2010-07-31 10:01:15 +00:00
Matthew D Fleming
242ed5d96c Fix taskqueue_drain(9) to not have false negatives. For threaded
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)
2010-07-22 16:41:09 +00:00
Pawel Jakub Dawidek
e477e4fe8e Remove unused taskqueue_find() function.
Reviewed by:	dfr
Approved by:	re (kib)
2009-08-18 13:55:48 +00:00
Pawel Jakub Dawidek
9c1a8ce494 Correct typo in the previous commit.
Noticed by:	pluknet <pluknet@gmail.com>
Approved by:	re (kib, implicit)
2009-08-17 10:20:22 +00:00
Pawel Jakub Dawidek
159ef108e1 Remove OpenSolaris taskq port (it performs very poorly in our kernel) and
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)
2009-08-17 09:01:20 +00:00
Oleksandr Tymoshenko
10a6caea1b It's Friday the 13th, not the 10th and I can't travel in time. Yet. 2008-06-13 19:45:12 +00:00
Oleksandr Tymoshenko
2eb30874af Add "fast" versions of macros and functions to taskqueue(9) API
description: TASKQUEUE_FAST_DEFINE(9), TASKQUEUE_FAST_DEFINE_THREAD(9),
  taskqueue_create_fast(9). They deal with taskqueues intended for use
  in fast interrupt handlers.

  Approved by:	cognet (mentor)
  Reviewed by:	keramida
2008-06-13 19:35:17 +00:00
Oleksandr Tymoshenko
8f668ffa98 Clean out all mentions of struct proc* for it was removed from
taskqueue(9) API more then two years ago.

  Approved by:	cognet (mentor)
2008-05-22 21:41:19 +00:00
John-Mark Gurney
f616cf330e document the call to wakeup after a task has been run...
Approved by:	re (hrs)
MFC after:	3 days
2007-07-09 06:24:10 +00:00
Hiten Pandya
571dba6ec9 Use 'manual page' instead of 'man page' for consistency.
Approved by:	re (hrs)
2005-06-28 20:15:19 +00:00
Ruslan Ermilov
4f06896130 Assorted markup fixes and minor wordsmithing.
Approved by:	re
2005-06-15 13:31:23 +00:00
Gleb Smirnoff
fff7ff711b Document taskqueue_drain(). 2005-05-19 18:31:42 +00:00
Sam Leffler
cf82599dcc update for recent api changes 2005-05-01 02:12:44 +00:00
Joseph Koshy
4c49b002e0 Document taskqueue_run_fast(). Markup 'Giant' with ".Va".
Reviewed by:	ru
2005-04-19 16:23:00 +00:00
Joseph Koshy
3bbf58f9be Add a 'SEE ALSO' section. 2005-04-15 14:46:59 +00:00
Ruslan Ermilov
c0854fb7b2 Scheduled mdoc(7) sweep. 2005-01-12 21:48:25 +00:00
Bruce M Simpson
f674e945aa Correct a misspelling, 'task_fn' -> 'task_fn_t'.
Noticed by:	sah at softcardsystems dot com
MFC after:	3 days
2004-10-26 17:14:45 +00:00
John-Mark Gurney
227559d11f rearange some code that handles the thread taskqueue so that it is more
generic.  Introduce a new define TASKQUEUE_DEFINE_THREAD that takes a
single arg, which is the name of the queue.

Document these changes.
2004-08-08 02:37:22 +00:00
Ruslan Ermilov
d37ea99837 Removed trailing whitespace. 2004-07-02 19:07:33 +00:00
Ruslan Ermilov
bf7f20c2b6 Assorted markup, spelling, and grammar fixes. 2004-06-16 08:33:57 +00:00
Scott Long
24b4e9d17f Document taskqueue_enqueue_fast() 2004-01-02 07:23:40 +00:00
Kenneth D. Merry
e0254f1068 Fix typo in the last commit.
Pointed out by:	njl
MFC after:	3 days
2003-09-03 05:35:37 +00:00
Kenneth D. Merry
cb32189e23 Move dynamic sysctl(8) variable creation for the cd(4) and da(4) drivers
out of cdregister() and daregister(), which are run from interrupt context.

The sysctl code does blocking mallocs (M_WAITOK), which causes problems
if malloc(9) actually needs to sleep.

The eventual fix for this issue will involve moving the CAM probe process
inside a kernel thread.  For now, though, I have fixed the issue by moving
dynamic sysctl variable creation for these two drivers to a task queue
running in a kernel thread.

The existing task queues (taskqueue_swi and taskqueue_swi_giant) run in
software interrupt handlers, which wouldn't fix the problem at hand.  So I
have created a new task queue, taskqueue_thread, that runs inside a kernel
thread.  (It also runs outside of Giant -- clients must explicitly acquire
and release Giant in their taskqueue functions.)

scsi_cd.c:	Remove sysctl variable creation code from cdregister(), and
		move it to a new function, cdsysctlinit().  Queue
		cdsysctlinit() to the taskqueue_thread taskqueue once we
		have fully registered the cd(4) driver instance.

scsi_da.c:	Remove sysctl variable creation code from daregister(), and
		move it to move it to a new function, dasysctlinit().
		Queue dasysctlinit() to the taskqueue_thread taskqueue once
		we have fully registered the da(4) instance.

taskqueue.h:	Declare the new taskqueue_thread taskqueue, update some
		comments.

subr_taskqueue.c:
		Create the new kernel thread taskqueue.  This taskqueue
		runs outside of Giant, so any functions queued to it would
		need to explicitly acquire/release Giant if they need it.

cd.4:		Update the cd(4) man page to talk about the minimum command
		size sysctl/loader tunable.  Also note that the changer
		variables are available as loader tunables as well.

da.4:		Update the da(4) man page to cover the retry_count,
		default_timeout and minimum_cmd_size sysctl variables/loader
		tunables.  Remove references to /dev/r???, they aren't used
		any longer.

cd.9:		Update the cd(9) man page to describe the CD_Q_10_BYTE_ONLY
		quirk.

taskqueue.9:	Update the taskqueue(9) man page to describe the new thread
		task queue, and the taskqueue_swi_giant queue.

MFC after:	3 days
2003-09-03 04:46:28 +00:00
Ruslan Ermilov
2eff01c7e0 mdoc(7) police: Kill the (now extraneous) empty line. Previously,
.Bd erroneously defaulted to -compact mode in the SYNOPSIS section.
2002-03-15 12:04:49 +00:00
Chad David
f16b3c0de4 Update function definitions and required include files to reflect
the current state of the system.

Approved by: alfred
2001-12-26 23:14:04 +00:00
Ruslan Ermilov
32eef9aeb1 mdoc(7) police: Use the new .In macro for #include statements. 2001-10-01 16:09:29 +00:00
Dima Dorfman
70d51341bf mdoc(7) police: remove extraneous .Pp before and/or after .Sh. 2001-07-09 09:54:33 +00:00
Ruslan Ermilov
b92a189eb9 mdoc(7) police: Er macro usage cleanup. 2000-11-22 16:11:48 +00:00
Doug Rabson
823234556f Add documentation for taskqueue apis. 2000-05-28 16:53:50 +00:00