Sat Apr 11 16:32:07 2015 UTC ()
Fix ASSERT(x == y | z).  Interpret nthreads as pct when requested.

Reduces the number of threads created by zfs to a slightly less
insane value.

XXX This whole taskq business is questionable, and we really really
should not have copies of external code outside dist/ and without
vendor branches to record provenance and local changes.


(riastradh)
diff -r1.4 -r1.5 src/external/cddl/osnet/sys/kern/taskq.c

cvs diff -r1.4 -r1.5 src/external/cddl/osnet/sys/kern/taskq.c (expand / switch to unified diff)

--- src/external/cddl/osnet/sys/kern/taskq.c 2015/04/11 00:13:04 1.4
+++ src/external/cddl/osnet/sys/kern/taskq.c 2015/04/11 16:32:07 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: taskq.c,v 1.4 2015/04/11 00:13:04 riastradh Exp $ */ 1/* $NetBSD: taskq.c,v 1.5 2015/04/11 16:32:07 riastradh Exp $ */
2 2
3/* 3/*
4 * CDDL HEADER START 4 * CDDL HEADER START
5 * 5 *
6 * The contents of this file are subject to the terms of the 6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License, Version 1.0 only 7 * Common Development and Distribution License, Version 1.0 only
8 * (the "License"). You may not use this file except in compliance 8 * (the "License"). You may not use this file except in compliance
9 * with the License. 9 * with the License.
10 * 10 *
11 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12 * or http://www.opensolaris.org/os/licensing. 12 * or http://www.opensolaris.org/os/licensing.
13 * See the License for the specific language governing permissions 13 * See the License for the specific language governing permissions
14 * and limitations under the License. 14 * and limitations under the License.
@@ -895,41 +895,45 @@ taskq_create(const char *name, int nthre @@ -895,41 +895,45 @@ taskq_create(const char *name, int nthre
895 return taskq_create_common(name, 0, nthreads, pri, minalloc, 895 return taskq_create_common(name, 0, nthreads, pri, minalloc,
896 maxalloc, flags | TASKQ_NOINSTANCE); 896 maxalloc, flags | TASKQ_NOINSTANCE);
897} 897}
898 898
899static taskq_t * 899static taskq_t *
900taskq_create_common(const char *name, int instance, int nthreads, pri_t pri, 900taskq_create_common(const char *name, int instance, int nthreads, pri_t pri,
901 int minalloc, int maxalloc, uint_t flags) 901 int minalloc, int maxalloc, uint_t flags)
902{ 902{
903 taskq_t *tq = kmem_cache_alloc(taskq_cache, KM_NOSLEEP); 903 taskq_t *tq = kmem_cache_alloc(taskq_cache, KM_NOSLEEP);
904 uint_t ncpus = ((boot_max_ncpus == -1) ? max_ncpus : boot_max_ncpus); 904 uint_t ncpus = ((boot_max_ncpus == -1) ? max_ncpus : boot_max_ncpus);
905 uint_t bsize; /* # of buckets - always power of 2 */ 905 uint_t bsize; /* # of buckets - always power of 2 */
906 906
907 ASSERT(instance == 0); 907 ASSERT(instance == 0);
908 ASSERT(flags == TASKQ_PREPOPULATE | TASKQ_NOINSTANCE); 908 ASSERT(!ISSET(flags, TASKQ_CPR_SAFE));
 909 ASSERT(!ISSET(flags, TASKQ_DYNAMIC));
909 910
910 /* 911 /*
911 * TASKQ_CPR_SAFE and TASKQ_DYNAMIC flags are mutually exclusive. 912 * TASKQ_CPR_SAFE and TASKQ_DYNAMIC flags are mutually exclusive.
912 */ 913 */
913 ASSERT((flags & (TASKQ_DYNAMIC | TASKQ_CPR_SAFE)) != 914 ASSERT((flags & (TASKQ_DYNAMIC | TASKQ_CPR_SAFE)) !=
914 ((TASKQ_DYNAMIC | TASKQ_CPR_SAFE))); 915 ((TASKQ_DYNAMIC | TASKQ_CPR_SAFE)));
915 916
916 ASSERT(tq->tq_buckets == NULL); 917 ASSERT(tq->tq_buckets == NULL);
917 918
918 bsize = 1 << (highbit(ncpus) - 1); 919 bsize = 1 << (highbit(ncpus) - 1);
919 ASSERT(bsize >= 1); 920 ASSERT(bsize >= 1);
920 bsize = MIN(bsize, taskq_maxbuckets); 921 bsize = MIN(bsize, taskq_maxbuckets);
921 922
922 tq->tq_maxsize = nthreads; 923 ASSERT(!(flags & TASKQ_DYNAMIC));
 924 if (flags & TASKQ_THREADS_CPU_PCT)
 925 /* nthreads is % of CPUs we want to use. */
 926 nthreads = (ncpus*nthreads)/100;
923 927
924 (void) strncpy(tq->tq_name, name, TASKQ_NAMELEN + 1); 928 (void) strncpy(tq->tq_name, name, TASKQ_NAMELEN + 1);
925 tq->tq_name[TASKQ_NAMELEN] = '\0'; 929 tq->tq_name[TASKQ_NAMELEN] = '\0';
926 /* Make sure the name conforms to the rules for C indentifiers */ 930 /* Make sure the name conforms to the rules for C indentifiers */
927 strident_canon(tq->tq_name, TASKQ_NAMELEN); 931 strident_canon(tq->tq_name, TASKQ_NAMELEN);
928 932
929 tq->tq_flags = flags | TASKQ_ACTIVE; 933 tq->tq_flags = flags | TASKQ_ACTIVE;
930 tq->tq_active = nthreads; 934 tq->tq_active = nthreads;
931 tq->tq_nthreads = nthreads; 935 tq->tq_nthreads = nthreads;
932 tq->tq_minalloc = minalloc; 936 tq->tq_minalloc = minalloc;
933 tq->tq_maxalloc = maxalloc; 937 tq->tq_maxalloc = maxalloc;
934 tq->tq_nbuckets = bsize; 938 tq->tq_nbuckets = bsize;
935 tq->tq_pri = pri; 939 tq->tq_pri = pri;