usr/src/lib/libzpool/common/taskq.c
author Garrett D'Amore <garrett@nexenta.com>
Wed, 27 Jul 2011 07:13:44 -0700
changeset 13414 b42c1f0432b6
parent 11854 5351ddd19d45
child 13597 3eac1e8e0f4c
permissions -rw-r--r--
734 taskq_dispatch_prealloc() desired 943 zio_interrupt ends up calling taskq_dispatch with TQ_SLEEP Reviewed by: Albert Lee <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Alexey Zaytsev <[email protected]> Reviewed by: Jason Brian King <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Adam Leventhal <[email protected]> Approved by: Gordon Ross <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    22
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    25
/*
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    26
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    27
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
int taskq_now;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
    32
taskq_t *system_taskq;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#define	TASKQ_ACTIVE	0x00010000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
struct taskq {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
	kmutex_t	tq_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
	krwlock_t	tq_threadlock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
	kcondvar_t	tq_dispatch_cv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
	kcondvar_t	tq_wait_cv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
	thread_t	*tq_threadlist;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
	int		tq_flags;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
	int		tq_active;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
	int		tq_nthreads;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
	int		tq_nalloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	int		tq_minalloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	int		tq_maxalloc;
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    48
	kcondvar_t	tq_maxalloc_cv;
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    49
	int		tq_maxalloc_wait;
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    50
	taskq_ent_t	*tq_freelist;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    51
	taskq_ent_t	tq_task;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    54
static taskq_ent_t *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
task_alloc(taskq_t *tq, int tqflags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
{
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    57
	taskq_ent_t *t;
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    58
	int rv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    60
again:	if ((t = tq->tq_freelist) != NULL && tq->tq_nalloc >= tq->tq_minalloc) {
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    61
		tq->tq_freelist = t->tqent_next;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
		if (tq->tq_nalloc >= tq->tq_maxalloc) {
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    64
			if (!(tqflags & KM_SLEEP))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
				return (NULL);
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    66
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
			 * We don't want to exceed tq_maxalloc, but we can't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
			 * wait for other tasks to complete (and thus free up
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
			 * task structures) without risking deadlock with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
			 * the caller.  So, we just delay for one second
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    72
			 * to throttle the allocation rate. If we have tasks
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    73
			 * complete before one second timeout expires then
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    74
			 * taskq_ent_free will signal us and we will
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    75
			 * immediately retry the allocation.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
			 */
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    77
			tq->tq_maxalloc_wait++;
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    78
			rv = cv_timedwait(&tq->tq_maxalloc_cv,
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    79
			    &tq->tq_lock, ddi_get_lbolt() + hz);
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    80
			tq->tq_maxalloc_wait--;
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    81
			if (rv > 0)
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    82
				goto again;		/* signaled */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
		}
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    84
		mutex_exit(&tq->tq_lock);
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    85
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    86
		t = kmem_alloc(sizeof (taskq_ent_t), tqflags);
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
    87
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
		mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
		if (t != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
			tq->tq_nalloc++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	return (t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
static void
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    96
task_free(taskq_t *tq, taskq_ent_t *t)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	if (tq->tq_nalloc <= tq->tq_minalloc) {
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
    99
		t->tqent_next = tq->tq_freelist;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
		tq->tq_freelist = t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
		tq->tq_nalloc--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
		mutex_exit(&tq->tq_lock);
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   104
		kmem_free(t, sizeof (taskq_ent_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
		mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	}
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
   107
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
   108
	if (tq->tq_maxalloc_wait)
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
   109
		cv_signal(&tq->tq_maxalloc_cv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
taskqid_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t tqflags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
{
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   115
	taskq_ent_t *t;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	if (taskq_now) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
		func(arg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	ASSERT(tq->tq_flags & TASKQ_ACTIVE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	if ((t = task_alloc(tq, tqflags)) == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
		mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	}
11173
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10612
diff changeset
   128
	if (tqflags & TQ_FRONT) {
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   129
		t->tqent_next = tq->tq_task.tqent_next;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   130
		t->tqent_prev = &tq->tq_task;
11173
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10612
diff changeset
   131
	} else {
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   132
		t->tqent_next = &tq->tq_task;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   133
		t->tqent_prev = tq->tq_task.tqent_prev;
11173
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10612
diff changeset
   134
	}
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   135
	t->tqent_next->tqent_prev = t;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   136
	t->tqent_prev->tqent_next = t;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   137
	t->tqent_func = func;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   138
	t->tqent_arg = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	cv_signal(&tq->tq_dispatch_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
	mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
void
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   145
taskq_dispatch_ent(taskq_t *tq, task_func_t func, void *arg, uint_t flags,
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   146
    taskq_ent_t *t)
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   147
{
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   148
	ASSERT(func != NULL);
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   149
	ASSERT(!(tq->tq_flags & TASKQ_DYNAMIC));
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   150
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   151
	/*
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   152
	 * Mark it as a prealloc'd task.  This is important
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   153
	 * to ensure that we don't free it later.
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   154
	 */
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   155
	t->tqent_flags |= TQENT_FLAG_PREALLOC;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   156
	/*
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   157
	 * Enqueue the task to the underlying queue.
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   158
	 */
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   159
	mutex_enter(&tq->tq_lock);
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   160
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   161
	if (flags & TQ_FRONT) {
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   162
		t->tqent_next = tq->tq_task.tqent_next;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   163
		t->tqent_prev = &tq->tq_task;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   164
	} else {
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   165
		t->tqent_next = &tq->tq_task;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   166
		t->tqent_prev = tq->tq_task.tqent_prev;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   167
	}
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   168
	t->tqent_next->tqent_prev = t;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   169
	t->tqent_prev->tqent_next = t;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   170
	t->tqent_func = func;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   171
	t->tqent_arg = arg;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   172
	cv_signal(&tq->tq_dispatch_cv);
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   173
	mutex_exit(&tq->tq_lock);
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   174
}
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   175
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   176
void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
taskq_wait(taskq_t *tq)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	mutex_enter(&tq->tq_lock);
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   180
	while (tq->tq_task.tqent_next != &tq->tq_task || tq->tq_active != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
		cv_wait(&tq->tq_wait_cv, &tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
	mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
static void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
taskq_thread(void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	taskq_t *tq = arg;
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   189
	taskq_ent_t *t;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   190
	boolean_t prealloc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	while (tq->tq_flags & TASKQ_ACTIVE) {
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   194
		if ((t = tq->tq_task.tqent_next) == &tq->tq_task) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
			if (--tq->tq_active == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
				cv_broadcast(&tq->tq_wait_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
			cv_wait(&tq->tq_dispatch_cv, &tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
			tq->tq_active++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
		}
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   201
		t->tqent_prev->tqent_next = t->tqent_next;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   202
		t->tqent_next->tqent_prev = t->tqent_prev;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   203
		t->tqent_next = NULL;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   204
		t->tqent_prev = NULL;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   205
		prealloc = t->tqent_flags & TQENT_FLAG_PREALLOC;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
		mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
		rw_enter(&tq->tq_threadlock, RW_READER);
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   209
		t->tqent_func(t->tqent_arg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
		rw_exit(&tq->tq_threadlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
		mutex_enter(&tq->tq_lock);
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   213
		if (!prealloc)
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   214
			task_free(tq, t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	tq->tq_nthreads--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
	cv_broadcast(&tq->tq_wait_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
	mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
taskq_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
taskq_create(const char *name, int nthreads, pri_t pri,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	int minalloc, int maxalloc, uint_t flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	int t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
9515
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   230
	if (flags & TASKQ_THREADS_CPU_PCT) {
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   231
		int pct;
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   232
		ASSERT3S(nthreads, >=, 0);
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   233
		ASSERT3S(nthreads, <=, 100);
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   234
		pct = MIN(nthreads, 100);
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   235
		pct = MAX(pct, 0);
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   236
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   237
		nthreads = (sysconf(_SC_NPROCESSORS_ONLN) * pct) / 100;
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   238
		nthreads = MAX(nthreads, 1);	/* need at least 1 thread */
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   239
	} else {
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   240
		ASSERT3S(nthreads, >=, 1);
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   241
	}
d3b739d9d043 6586537 async zio taskqs can block out userland commands
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 7837
diff changeset
   242
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
	rw_init(&tq->tq_threadlock, NULL, RW_DEFAULT, NULL);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   244
	mutex_init(&tq->tq_lock, NULL, MUTEX_DEFAULT, NULL);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   245
	cv_init(&tq->tq_dispatch_cv, NULL, CV_DEFAULT, NULL);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   246
	cv_init(&tq->tq_wait_cv, NULL, CV_DEFAULT, NULL);
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
   247
	cv_init(&tq->tq_maxalloc_cv, NULL, CV_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	tq->tq_flags = flags | TASKQ_ACTIVE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	tq->tq_active = nthreads;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	tq->tq_nthreads = nthreads;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
	tq->tq_minalloc = minalloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	tq->tq_maxalloc = maxalloc;
13414
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   253
	tq->tq_task.tqent_next = &tq->tq_task;
b42c1f0432b6 734 taskq_dispatch_prealloc() desired
Garrett D'Amore <garrett@nexenta.com>
parents: 11854
diff changeset
   254
	tq->tq_task.tqent_prev = &tq->tq_task;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	tq->tq_threadlist = kmem_alloc(nthreads * sizeof (thread_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
	if (flags & TASKQ_PREPOPULATE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
		mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
		while (minalloc-- > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
			task_free(tq, task_alloc(tq, KM_SLEEP));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
		mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
	for (t = 0; t < nthreads; t++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
		(void) thr_create(0, 0, taskq_thread,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
		    tq, THR_BOUND, &tq->tq_threadlist[t]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	return (tq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
taskq_destroy(taskq_t *tq)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	int t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	int nthreads = tq->tq_nthreads;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	taskq_wait(tq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	mutex_enter(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	tq->tq_flags &= ~TASKQ_ACTIVE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	cv_broadcast(&tq->tq_dispatch_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	while (tq->tq_nthreads != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
		cv_wait(&tq->tq_wait_cv, &tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	tq->tq_minalloc = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	while (tq->tq_nalloc != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
		ASSERT(tq->tq_freelist != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		task_free(tq, task_alloc(tq, KM_SLEEP));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	mutex_exit(&tq->tq_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	for (t = 0; t < nthreads; t++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
		(void) thr_join(tq->tq_threadlist[t], NULL, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	kmem_free(tq->tq_threadlist, nthreads * sizeof (thread_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	rw_destroy(&tq->tq_threadlock);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   301
	mutex_destroy(&tq->tq_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   302
	cv_destroy(&tq->tq_dispatch_cv);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 789
diff changeset
   303
	cv_destroy(&tq->tq_wait_cv);
11854
5351ddd19d45 6900839 taskq_ent_alloc: TQ_SLEEP performance cliff when tq_nalloc > tq_maxalloc
Chris Horne <Chris.Horne@Sun.COM>
parents: 11173
diff changeset
   304
	cv_destroy(&tq->tq_maxalloc_cv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
	kmem_free(tq, sizeof (taskq_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
taskq_member(taskq_t *tq, void *t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	if (taskq_now)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	for (i = 0; i < tq->tq_nthreads; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
		if (tq->tq_threadlist[i] == (thread_t)(uintptr_t)t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
			return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
}
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   323
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   324
void
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   325
system_taskq_init(void)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   326
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   327
	system_taskq = taskq_create("system_taskq", 64, minclsyspri, 4, 512,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   328
	    TASKQ_DYNAMIC | TASKQ_PREPOPULATE);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 4831
diff changeset
   329
}
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   330
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   331
void
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   332
system_taskq_fini(void)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   333
{
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   334
	taskq_destroy(system_taskq);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   335
	system_taskq = NULL; /* defensive */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9515
diff changeset
   336
}