Print this page
re #13613 rb4516 Tunables needs volatile keyword


   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */



  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 /*
  29  * This file contains global data and code shared between master and slave parts
  30  * of the pseudo-terminal driver.
  31  *
  32  * Pseudo terminals (or pt's for short) are allocated dynamically.
  33  * pt's are put in the global ptms_slots array indexed by minor numbers.
  34  *
  35  * The slots array is initially small (of the size NPTY_MIN). When more pt's are
  36  * needed than the slot array size, the larger slot array is allocated and all
  37  * opened pt's move to the new one.
  38  *
  39  * Resource allocation:
  40  *
  41  *      pt_ttys structures are allocated via pt_ttys_alloc, which uses
  42  *              kmem_cache_alloc().
  43  *      Minor number space is allocated via vmem_alloc() interface.
  44  *      ptms_slots arrays are allocated via kmem_alloc().
  45  *
  46  *   Minors are started from 1 instead of 0 because vmem_alloc returns 0 in case
  47  *   of failure. Also, in anticipation of removing clone device interface to


 177 #include <sys/bitmap.h>
 178 #include <sys/sysmacros.h>
 179 #include <sys/ddi_impldefs.h>
 180 #include <sys/zone.h>
 181 #ifdef DEBUG
 182 #include <sys/strlog.h>
 183 #endif
 184 
 185 
 186 /* Initial number of ptms slots */
 187 #define NPTY_INITIAL 16
 188 
 189 #define NPTY_PERCENT 5
 190 
 191 /* Maximum increment of the slot table size */
 192 #define PTY_MAXDELTA 128
 193 
 194 /*
 195  * Tuneable variables.
 196  */
 197 uint_t  pt_cnt = 0;                     /* Minimum number of ptys */
 198 size_t  pt_max_pty = 0;                 /* Maximum number of ptys */
 199 uint_t  pt_init_cnt = NPTY_INITIAL;     /* Initial number of ptms slots */
 200 uint_t  pt_pctofmem = NPTY_PERCENT;     /* Percent of memory to use for ptys */

 201 uint_t  pt_maxdelta = PTY_MAXDELTA;     /* Max increment for slot table size */
 202 
 203 /* Other global variables */
 204 
 205 kmutex_t ptms_lock;                     /* Global data access lock */
 206 
 207 /*
 208  * Slot array and its management variables
 209  */
 210 static struct pt_ttys **ptms_slots = NULL; /* Slots for actual pt structures */
 211 static size_t ptms_nslots = 0;          /* Size of slot array */
 212 static size_t ptms_ptymax = 0;          /* Maximum number of ptys */
 213 static size_t ptms_inuse = 0;           /* # of ptys currently allocated */
 214 
 215 dev_info_t      *pts_dip = NULL;        /* set if slave is attached */
 216 
 217 static struct kmem_cache *ptms_cache = NULL;    /* pty cache */
 218 
 219 static vmem_t *ptms_minor_arena = NULL; /* Arena for device minors */
 220 




   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  27  */
  28 


  29 /*
  30  * This file contains global data and code shared between master and slave parts
  31  * of the pseudo-terminal driver.
  32  *
  33  * Pseudo terminals (or pt's for short) are allocated dynamically.
  34  * pt's are put in the global ptms_slots array indexed by minor numbers.
  35  *
  36  * The slots array is initially small (of the size NPTY_MIN). When more pt's are
  37  * needed than the slot array size, the larger slot array is allocated and all
  38  * opened pt's move to the new one.
  39  *
  40  * Resource allocation:
  41  *
  42  *      pt_ttys structures are allocated via pt_ttys_alloc, which uses
  43  *              kmem_cache_alloc().
  44  *      Minor number space is allocated via vmem_alloc() interface.
  45  *      ptms_slots arrays are allocated via kmem_alloc().
  46  *
  47  *   Minors are started from 1 instead of 0 because vmem_alloc returns 0 in case
  48  *   of failure. Also, in anticipation of removing clone device interface to


 178 #include <sys/bitmap.h>
 179 #include <sys/sysmacros.h>
 180 #include <sys/ddi_impldefs.h>
 181 #include <sys/zone.h>
 182 #ifdef DEBUG
 183 #include <sys/strlog.h>
 184 #endif
 185 
 186 
 187 /* Initial number of ptms slots */
 188 #define NPTY_INITIAL 16
 189 
 190 #define NPTY_PERCENT 5
 191 
 192 /* Maximum increment of the slot table size */
 193 #define PTY_MAXDELTA 128
 194 
 195 /*
 196  * Tuneable variables.
 197  */
 198 volatile uint_t pt_cnt = 0;             /* Minimum number of ptys */
 199 volatile size_t pt_max_pty = 0;         /* Maximum number of ptys */
 200 uint_t  pt_init_cnt = NPTY_INITIAL;     /* Initial number of ptms slots */
 201 volatile uint_t pt_pctofmem = NPTY_PERCENT;     /* Percent of memory to use */
 202                                                 /* for ptys */
 203 uint_t  pt_maxdelta = PTY_MAXDELTA;     /* Max increment for slot table size */
 204 
 205 /* Other global variables */
 206 
 207 kmutex_t ptms_lock;                     /* Global data access lock */
 208 
 209 /*
 210  * Slot array and its management variables
 211  */
 212 static struct pt_ttys **ptms_slots = NULL; /* Slots for actual pt structures */
 213 static size_t ptms_nslots = 0;          /* Size of slot array */
 214 static size_t ptms_ptymax = 0;          /* Maximum number of ptys */
 215 static size_t ptms_inuse = 0;           /* # of ptys currently allocated */
 216 
 217 dev_info_t      *pts_dip = NULL;        /* set if slave is attached */
 218 
 219 static struct kmem_cache *ptms_cache = NULL;    /* pty cache */
 220 
 221 static vmem_t *ptms_minor_arena = NULL; /* Arena for device minors */
 222