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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2012 Joyent, Inc. All rights reserved.
31 #include <sys/types.h>
32 #include <sys/thread.h>
33 #include <sys/project.h>
34 #include <sys/cpucaps.h>
42 typedef uint64_t fsspri_t
;
43 typedef uint64_t fssusage_t
;
48 * Valid arg1's for fss_allocbuf()
50 #define FSS_NPSET_BUF 1
51 #define FSS_NPROJ_BUF 2
55 * Valid arg2's for fss_allocbuf()
57 #define FSS_ALLOC_PROJ 1
58 #define FSS_ALLOC_ZONE 2
60 #define FSS_MAXSHARES 65535
62 typedef struct fssbuf
{
67 void *fss_allocbuf(int, int);
68 void fss_freebuf(fssbuf_t
*, int);
69 void fss_changeproj(kthread_id_t
, void *, void *, fssbuf_t
*, fssbuf_t
*);
70 void fss_changepset(kthread_id_t
, void *, fssbuf_t
*, fssbuf_t
*);
73 * Fair share scheduling class specific cpu partition structure
75 typedef struct fsspset
{
76 kmutex_t fssps_lock
; /* lock to protect per-pset */
77 /* list of fssproj structures */
78 disp_lock_t fssps_displock
; /* lock for fsps_maxfsspri */
79 struct cpupart
*fssps_cpupart
; /* ptr to our cpu partition */
80 /* protected by fsspsets_lock */
81 fsspri_t fssps_maxfsspri
; /* maximum fsspri value among */
82 /* all projects on this pset */
83 uint32_t fssps_shares
; /* number of active shares */
84 uint32_t fssps_nproj
; /* number of fssproj structures */
86 struct fssproj
*fssps_list
; /* list of project parts */
87 struct fsszone
*fssps_zones
; /* list of fsszone_t's in pset */
88 uint32_t fssps_gen
; /* generation for zone's kstats */
92 * One of these structures is allocated to each project running within each
93 * active cpu partition.
95 typedef struct fssproj
{
96 kproject_t
*fssp_proj
; /* ptr to our project structure */
97 fsspset_t
*fssp_pset
; /* ptr to our fsspset structure */
98 uint32_t fssp_threads
; /* total number of threads here */
99 /* protected by fssps_lock */
100 uint32_t fssp_runnable
; /* number of runnable threads */
101 /* protected by fssps_lock */
102 uint32_t fssp_shares
; /* copy of our kpj_shares */
103 /* protected by fssps_displock */
104 uint32_t fssp_ticks
; /* total of nice tick values */
105 /* protected by fssps_displock */
106 uint32_t fssp_tick_cnt
; /* cnt of all ticks in this sec */
107 uint32_t fssp_shr_pct
; /* active shr % in this sec */
108 /* protected by fssps_displock */
109 fssusage_t fssp_usage
; /* this project's decayed usage */
110 fssusage_t fssp_shusage
; /* normalized usage */
111 struct fssproj
*fssp_next
; /* next project on this pset */
112 struct fssproj
*fssp_prev
; /* prev project on this pset */
113 struct fsszone
*fssp_fsszone
; /* fsszone_t for this fssproj */
117 * Fair share scheduling class specific thread structure
119 typedef struct fssproc
{
120 kthread_t
*fss_tp
; /* pointer back to our thread */
121 fssproj_t
*fss_proj
; /* pointer to our project FSS data */
122 uchar_t fss_flags
; /* flags defined below */
123 int fss_timeleft
; /* time remaining in procs quantum */
124 uint32_t fss_ticks
; /* ticks accumulated by this thread */
125 pri_t fss_upri
; /* user supplied priority (to priocntl) */
126 pri_t fss_uprilim
; /* user priority limit */
127 pri_t fss_umdpri
; /* user mode priority within fs class */
128 pri_t fss_scpri
; /* remembered priority, for schedctl */
129 int fss_nice
; /* nice value for compatibility with ts */
130 fsspri_t fss_fsspri
; /* internal fair share priority */
131 int fss_runnable
; /* to indicate runnable/sleeping thread */
132 struct fssproc
*fss_next
; /* pointer to next fssproc_t struct */
133 struct fssproc
*fss_prev
; /* pointer to prev fssproc_t sturct */
134 caps_sc_t fss_caps
; /* CPU caps specific data */
138 * One of these structures is allocated to each zone running within
139 * each active cpu partition. This means that if a zone spans more
140 * than one cpu partition then it will have a few of these structures.
142 typedef struct fsszone
{
143 struct zone
*fssz_zone
; /* ptr to our zone structure */
144 struct fsszone
*fssz_next
; /* next fsszone_t in fsspset_t */
145 struct fsszone
*fssz_prev
; /* prev fsszone_t in fsspset_t */
146 uint32_t fssz_shares
; /* sum of all project shares */
147 uint32_t fssz_nproj
; /* # of projects */
148 uint32_t fssz_rshares
; /* "real" shares given to zone */
149 uint32_t fssz_runnable
; /* # of runnable projects */
152 #define FSSPROC(tx) ((fssproc_t *)(tx->t_cldata))
153 #define FSSPROC2FSSPROJ(fssx) ((fssx)->fss_proj);
154 #define FSSPROC2FSSPSET(fssx) (FSSPROC2FSSPROJ(fssx)->fssp_pset)
155 #define FSSPROJ(tx) (FSSPROC(tx)->fss_proj)
156 #define FSSPROJ2FSSPSET(fssx) ((fssx)->fssp_pset)
157 #define FSSPROJ2KPROJ(fssx) ((fssx)->fssp_proj)
158 #define FSSPROJ2FSSZONE(fssx) ((fssx)->fssp_fsszone)
163 #define FSSKPRI 0x01 /* the thread is in kernel mode */
164 #define FSSBACKQ 0x02 /* thread should be placed at the back of */
165 /* the dispatch queue if preempted */
166 #define FSSRESTORE 0x04 /* thread was not preempted, due to schedctl */
167 /* restore priority from fss_scpri */
175 #endif /* _SYS_FSS_H */