4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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 /*
  23  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2013, Joyent, Inc. All rights reserved.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/param.h>
  29 #include <sys/sysmacros.h>
  30 #include <sys/cred.h>
  31 #include <sys/proc.h>
  32 #include <sys/session.h>
  33 #include <sys/strsubr.h>
  34 #include <sys/user.h>
  35 #include <sys/priocntl.h>
  36 #include <sys/class.h>
  37 #include <sys/disp.h>
  38 #include <sys/procset.h>
  39 #include <sys/debug.h>
  40 #include <sys/kmem.h>
  41 #include <sys/errno.h>
  42 #include <sys/fx.h>
  43 #include <sys/fxpriocntl.h>
  44 #include <sys/cpuvar.h>
 
 
  54 #include <sys/cpupart.h>
  55 #include <sys/cpucaps.h>
  56 
  57 static pri_t fx_init(id_t, int, classfuncs_t **);
  58 
  59 static struct sclass csw = {
  60         "FX",
  61         fx_init,
  62         0
  63 };
  64 
  65 static struct modlsched modlsched = {
  66         &mod_schedops, "Fixed priority sched class", &csw
  67 };
  68 
  69 static struct modlinkage modlinkage = {
  70         MODREV_1, (void *)&modlsched, NULL
  71 };
  72 
  73 
  74 /*
  75  * control flags (kparms->fx_cflags).
  76  */
  77 #define FX_DOUPRILIM    0x01    /* change user priority limit */
  78 #define FX_DOUPRI       0x02    /* change user priority */
  79 #define FX_DOTQ         0x04    /* change FX time quantum */
  80 
  81 
  82 #define FXMAXUPRI 60            /* maximum user priority setting */
  83 
  84 #define FX_MAX_UNPRIV_PRI       0       /* maximum unpriviledge priority */
  85 
  86 /*
  87  * The fxproc_t structures that have a registered callback vector,
  88  * are also kept in an array of circular doubly linked lists. A hash on
  89  * the thread id (from ddi_get_kt_did()) is used to determine which list
  90  * each of such fxproc structures should be placed. Each list has a dummy
  91  * "head" which is never removed, so the list is never empty.
  92  */
  93 
  94 #define FX_CB_LISTS 16          /* number of lists, must be power of 2 */
  95 #define FX_CB_LIST_HASH(ktid)   ((uint_t)ktid & (FX_CB_LISTS - 1))
  96 
  97 /* Insert fxproc into callback list */
  98 #define FX_CB_LIST_INSERT(fxpp)                                         \
  99 {                                                                       \
 100         int index = FX_CB_LIST_HASH(fxpp->fx_ktid);                  \
 101         kmutex_t *lockp = &fx_cb_list_lock[index];                  \
 102         fxproc_t *headp = &fx_cb_plisthead[index];                  \
 103         mutex_enter(lockp);                                             \
 
 | 
 
 
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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 /*
  23  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015, Joyent, Inc.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/param.h>
  29 #include <sys/sysmacros.h>
  30 #include <sys/cred.h>
  31 #include <sys/proc.h>
  32 #include <sys/session.h>
  33 #include <sys/strsubr.h>
  34 #include <sys/user.h>
  35 #include <sys/priocntl.h>
  36 #include <sys/class.h>
  37 #include <sys/disp.h>
  38 #include <sys/procset.h>
  39 #include <sys/debug.h>
  40 #include <sys/kmem.h>
  41 #include <sys/errno.h>
  42 #include <sys/fx.h>
  43 #include <sys/fxpriocntl.h>
  44 #include <sys/cpuvar.h>
 
 
  54 #include <sys/cpupart.h>
  55 #include <sys/cpucaps.h>
  56 
  57 static pri_t fx_init(id_t, int, classfuncs_t **);
  58 
  59 static struct sclass csw = {
  60         "FX",
  61         fx_init,
  62         0
  63 };
  64 
  65 static struct modlsched modlsched = {
  66         &mod_schedops, "Fixed priority sched class", &csw
  67 };
  68 
  69 static struct modlinkage modlinkage = {
  70         MODREV_1, (void *)&modlsched, NULL
  71 };
  72 
  73 
  74 #define FX_MAX_UNPRIV_PRI       0       /* maximum unpriviledge priority */
  75 
  76 /*
  77  * The fxproc_t structures that have a registered callback vector,
  78  * are also kept in an array of circular doubly linked lists. A hash on
  79  * the thread id (from ddi_get_kt_did()) is used to determine which list
  80  * each of such fxproc structures should be placed. Each list has a dummy
  81  * "head" which is never removed, so the list is never empty.
  82  */
  83 
  84 #define FX_CB_LISTS 16          /* number of lists, must be power of 2 */
  85 #define FX_CB_LIST_HASH(ktid)   ((uint_t)ktid & (FX_CB_LISTS - 1))
  86 
  87 /* Insert fxproc into callback list */
  88 #define FX_CB_LIST_INSERT(fxpp)                                         \
  89 {                                                                       \
  90         int index = FX_CB_LIST_HASH(fxpp->fx_ktid);                  \
  91         kmutex_t *lockp = &fx_cb_list_lock[index];                  \
  92         fxproc_t *headp = &fx_cb_plisthead[index];                  \
  93         mutex_enter(lockp);                                             \
 
 |