Print this page
8115 parallel zfs mount


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
  27  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.

  28  */
  29 
  30 #include <sys/taskq_impl.h>
  31 
  32 #include <sys/class.h>
  33 #include <sys/debug.h>
  34 #include <sys/ksynch.h>
  35 #include <sys/kmem.h>
  36 #include <sys/time.h>
  37 #include <sys/systm.h>
  38 #include <sys/sysmacros.h>
  39 #include <sys/unistd.h>
  40 



  41 /* avoid <unistd.h> */
  42 extern long sysconf(int);
  43 
  44 /* avoiding <thread.h> */
  45 typedef unsigned int thread_t;
  46 typedef unsigned int thread_key_t;
  47 
  48 extern int thr_create(void *, size_t, void *(*)(void *), void *, long,
  49                         thread_t *);
  50 extern int thr_join(thread_t, thread_t *, void **);
  51 
  52 /*
  53  * POSIX.1c Note:
  54  * THR_BOUND is defined same as PTHREAD_SCOPE_SYSTEM in <pthread.h>
  55  * THR_DETACHED is defined same as PTHREAD_CREATE_DETACHED in <pthread.h>
  56  * Any changes in these definitions should be reflected in <pthread.h>
  57  */
  58 #define THR_BOUND               0x00000001      /* = PTHREAD_SCOPE_SYSTEM */
  59 #define THR_NEW_LWP             0x00000002
  60 #define THR_DETACHED            0x00000040      /* = PTHREAD_CREATE_DETACHED */


 246 
 247                 mutex_enter(&tq->tq_lock);
 248                 if (!prealloc)
 249                         task_free(tq, t);
 250         }
 251         tq->tq_nthreads--;
 252         cv_broadcast(&tq->tq_wait_cv);
 253         mutex_exit(&tq->tq_lock);
 254         return (NULL);
 255 }
 256 
 257 /*ARGSUSED*/
 258 taskq_t *
 259 taskq_create(const char *name, int nthr, pri_t pri, int minalloc,
 260     int maxalloc, uint_t flags)
 261 {
 262         return (taskq_create_proc(name, nthr, pri,
 263             minalloc, maxalloc, NULL, flags));
 264 }
 265 









 266 /*ARGSUSED*/
 267 taskq_t *
 268 taskq_create_proc(const char *name, int nthreads, pri_t pri,
 269         int minalloc, int maxalloc, proc_t *proc, uint_t flags)
 270 {
 271         taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP);
 272         int t;
 273 
 274         if (flags & TASKQ_THREADS_CPU_PCT) {
 275                 int pct;
 276                 ASSERT3S(nthreads, >=, 0);
 277                 ASSERT3S(nthreads, <=, 100);
 278                 pct = MIN(nthreads, 100);
 279                 pct = MAX(pct, 0);
 280 
 281                 nthreads = (sysconf(_SC_NPROCESSORS_ONLN) * pct) / 100;
 282                 nthreads = MAX(nthreads, 1);    /* need at least 1 thread */
 283         } else {
 284                 ASSERT3S(nthreads, >=, 1);
 285         }




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
  27  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  28  * Copyright 2017 RackTop Systems.
  29  */
  30 
  31 #include <sys/taskq_impl.h>
  32 
  33 #include <sys/class.h>
  34 #include <sys/debug.h>
  35 #include <sys/ksynch.h>
  36 #include <sys/kmem.h>
  37 #include <sys/time.h>
  38 #include <sys/systm.h>
  39 #include <sys/sysmacros.h>
  40 #include <sys/unistd.h>
  41 
  42 /* avoid <sys/disp.h> */
  43 #define   maxclsyspri     99
  44 
  45 /* avoid <unistd.h> */
  46 extern long sysconf(int);
  47 
  48 /* avoiding <thread.h> */
  49 typedef unsigned int thread_t;
  50 typedef unsigned int thread_key_t;
  51 
  52 extern int thr_create(void *, size_t, void *(*)(void *), void *, long,
  53                         thread_t *);
  54 extern int thr_join(thread_t, thread_t *, void **);
  55 
  56 /*
  57  * POSIX.1c Note:
  58  * THR_BOUND is defined same as PTHREAD_SCOPE_SYSTEM in <pthread.h>
  59  * THR_DETACHED is defined same as PTHREAD_CREATE_DETACHED in <pthread.h>
  60  * Any changes in these definitions should be reflected in <pthread.h>
  61  */
  62 #define THR_BOUND               0x00000001      /* = PTHREAD_SCOPE_SYSTEM */
  63 #define THR_NEW_LWP             0x00000002
  64 #define THR_DETACHED            0x00000040      /* = PTHREAD_CREATE_DETACHED */


 250 
 251                 mutex_enter(&tq->tq_lock);
 252                 if (!prealloc)
 253                         task_free(tq, t);
 254         }
 255         tq->tq_nthreads--;
 256         cv_broadcast(&tq->tq_wait_cv);
 257         mutex_exit(&tq->tq_lock);
 258         return (NULL);
 259 }
 260 
 261 /*ARGSUSED*/
 262 taskq_t *
 263 taskq_create(const char *name, int nthr, pri_t pri, int minalloc,
 264     int maxalloc, uint_t flags)
 265 {
 266         return (taskq_create_proc(name, nthr, pri,
 267             minalloc, maxalloc, NULL, flags));
 268 }
 269 
 270 /*ARGSUSED*/
 271 taskq_t *
 272 taskq_create_sysdc(const char *name, int nthr, int minalloc,
 273     int maxalloc, proc_t *proc, uint_t dc, uint_t flags)
 274 {
 275         return (taskq_create_proc(name, nthr, maxclsyspri,
 276             minalloc, maxalloc, proc, flags));
 277 }
 278 
 279 /*ARGSUSED*/
 280 taskq_t *
 281 taskq_create_proc(const char *name, int nthreads, pri_t pri,
 282         int minalloc, int maxalloc, proc_t *proc, uint_t flags)
 283 {
 284         taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP);
 285         int t;
 286 
 287         if (flags & TASKQ_THREADS_CPU_PCT) {
 288                 int pct;
 289                 ASSERT3S(nthreads, >=, 0);
 290                 ASSERT3S(nthreads, <=, 100);
 291                 pct = MIN(nthreads, 100);
 292                 pct = MAX(pct, 0);
 293 
 294                 nthreads = (sysconf(_SC_NPROCESSORS_ONLN) * pct) / 100;
 295                 nthreads = MAX(nthreads, 1);    /* need at least 1 thread */
 296         } else {
 297                 ASSERT3S(nthreads, >=, 1);
 298         }