xref: /titanic_52/usr/src/uts/common/sys/fss.h (revision c97ad5cdc75eb73e3cc38542ca3ba783574b0a7a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*c97ad5cdSakolb  * Common Development and Distribution License (the "License").
6*c97ad5cdSakolb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
219ac8606fSraf 
227c478bd9Sstevel@tonic-gate /*
23*c97ad5cdSakolb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_FSS_H
287c478bd9Sstevel@tonic-gate #define	_SYS_FSS_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/thread.h>
347c478bd9Sstevel@tonic-gate #include <sys/project.h>
35*c97ad5cdSakolb #include <sys/cpucaps.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
41*c97ad5cdSakolb #ifdef	_KERNEL
42*c97ad5cdSakolb 
437c478bd9Sstevel@tonic-gate typedef uint64_t fsspri_t;
447c478bd9Sstevel@tonic-gate typedef	uint64_t fssusage_t;
457c478bd9Sstevel@tonic-gate struct cpupart;
467c478bd9Sstevel@tonic-gate struct zone;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Valid arg1's for fss_allocbuf()
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #define	FSS_NPSET_BUF	1
527c478bd9Sstevel@tonic-gate #define	FSS_NPROJ_BUF	2
537c478bd9Sstevel@tonic-gate #define	FSS_ONE_BUF	3
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Valid arg2's for fss_allocbuf()
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	FSS_ALLOC_PROJ	1
597c478bd9Sstevel@tonic-gate #define	FSS_ALLOC_ZONE	2
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	FSS_MAXSHARES	65535
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef struct fssbuf {
647c478bd9Sstevel@tonic-gate 	int	fssb_size;
657c478bd9Sstevel@tonic-gate 	void	**fssb_list;
667c478bd9Sstevel@tonic-gate } fssbuf_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate void *fss_allocbuf(int, int);
697c478bd9Sstevel@tonic-gate void fss_freebuf(fssbuf_t *, int);
707c478bd9Sstevel@tonic-gate void fss_changeproj(kthread_id_t, void *, void *, fssbuf_t *, fssbuf_t *);
717c478bd9Sstevel@tonic-gate void fss_changepset(kthread_id_t, void *, fssbuf_t *, fssbuf_t *);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Fair share scheduling class specific cpu partition structure
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate typedef struct fsspset {
777c478bd9Sstevel@tonic-gate 	kmutex_t	fssps_lock;	/* lock to protect per-pset	*/
787c478bd9Sstevel@tonic-gate 					/* list of fssproj structures	*/
79*c97ad5cdSakolb 	disp_lock_t	fssps_displock;	/* lock for fsps_maxfsspri	*/
807c478bd9Sstevel@tonic-gate 	struct cpupart	*fssps_cpupart;	/* ptr to our cpu partition	*/
817c478bd9Sstevel@tonic-gate 					/* protected by fsspsets_lock	*/
827c478bd9Sstevel@tonic-gate 	fsspri_t	fssps_maxfsspri; /* maximum fsspri value among	*/
837c478bd9Sstevel@tonic-gate 					/* all projects on this pset	*/
847c478bd9Sstevel@tonic-gate 	uint32_t	fssps_shares;	/* number of active shares	*/
857c478bd9Sstevel@tonic-gate 	uint32_t	fssps_nproj;	/* number of fssproj structures */
867c478bd9Sstevel@tonic-gate 					/* on the list			*/
877c478bd9Sstevel@tonic-gate 	struct fssproj	*fssps_list;	/* list of project parts	*/
887c478bd9Sstevel@tonic-gate 	struct fsszone	*fssps_zones;	/* list of fsszone_t's in pset	*/
897c478bd9Sstevel@tonic-gate } fsspset_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * One of these structures is allocated to each project running within each
937c478bd9Sstevel@tonic-gate  * active cpu partition.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate typedef struct fssproj {
967c478bd9Sstevel@tonic-gate 	kproject_t	*fssp_proj;	/* ptr to our project structure	*/
977c478bd9Sstevel@tonic-gate 	fsspset_t	*fssp_pset;	/* ptr to our fsspset structure	*/
987c478bd9Sstevel@tonic-gate 	uint32_t	fssp_threads;	/* total number of threads here */
997c478bd9Sstevel@tonic-gate 					/* protected by fssps_lock	*/
1007c478bd9Sstevel@tonic-gate 	uint32_t	fssp_runnable;	/* number of runnable threads	*/
1017c478bd9Sstevel@tonic-gate 					/* protected by fssps_lock	*/
1027c478bd9Sstevel@tonic-gate 	uint32_t	fssp_shares;	/* copy of our kpj_shares	*/
1037c478bd9Sstevel@tonic-gate 					/* protected by fssps_displock	*/
1047c478bd9Sstevel@tonic-gate 	uint32_t	fssp_ticks;	/* total of all ticks		*/
1057c478bd9Sstevel@tonic-gate 					/* protected by fssps_displock	*/
1067c478bd9Sstevel@tonic-gate 	fssusage_t	fssp_usage;	/* this project's decayed usage */
1077c478bd9Sstevel@tonic-gate 	fssusage_t	fssp_shusage;	/* normalized usage		*/
1087c478bd9Sstevel@tonic-gate 	struct fssproj	*fssp_next;	/* next project on this pset	*/
1097c478bd9Sstevel@tonic-gate 	struct fssproj	*fssp_prev;	/* prev project on this pset	*/
1107c478bd9Sstevel@tonic-gate 	struct fsszone	*fssp_fsszone;	/* fsszone_t for this fssproj	*/
1117c478bd9Sstevel@tonic-gate } fssproj_t;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * Fair share scheduling class specific thread structure
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate typedef struct fssproc {
1177c478bd9Sstevel@tonic-gate 	kthread_t *fss_tp;	/* pointer back to our thread		*/
118*c97ad5cdSakolb 	fssproj_t *fss_proj;	/* pointer to our project FSS data	*/
1197c478bd9Sstevel@tonic-gate 	uchar_t fss_flags;	/* flags defined below			*/
1207c478bd9Sstevel@tonic-gate 	int	fss_timeleft;	/* time remaining in procs quantum	*/
1217c478bd9Sstevel@tonic-gate 	uint32_t fss_ticks;	/* ticks accumulated by this thread	*/
1227c478bd9Sstevel@tonic-gate 	pri_t	fss_upri;	/* user supplied priority (to priocntl)	*/
1237c478bd9Sstevel@tonic-gate 	pri_t	fss_uprilim;	/* user priority limit			*/
1247c478bd9Sstevel@tonic-gate 	pri_t	fss_umdpri;	/* user mode priority within fs class	*/
1259ac8606fSraf 	pri_t	fss_scpri;	/* remembered priority, for schedctl	*/
1267c478bd9Sstevel@tonic-gate 	int	fss_nice;	/* nice value for compatibility with ts	*/
1277c478bd9Sstevel@tonic-gate 	fsspri_t fss_fsspri;	/* internal fair share priority		*/
1287c478bd9Sstevel@tonic-gate 	int	fss_runnable;	/* to indicate runnable/sleeping thread	*/
1297c478bd9Sstevel@tonic-gate 	struct fssproc *fss_next; /* pointer to next fssproc_t struct	*/
1307c478bd9Sstevel@tonic-gate 	struct fssproc *fss_prev; /* pointer to prev fssproc_t sturct	*/
131*c97ad5cdSakolb 	caps_sc_t fss_caps;	/* CPU caps specific data		*/
1327c478bd9Sstevel@tonic-gate } fssproc_t;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
135*c97ad5cdSakolb  * One of these structures is allocated to each zone running within
136*c97ad5cdSakolb  * each active cpu partition.  This means that if a zone spans more
137*c97ad5cdSakolb  * than one cpu partition then it will have a few of these structures.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate typedef struct fsszone {
1407c478bd9Sstevel@tonic-gate 	struct zone 	*fssz_zone;	/* ptr to our zone structure	*/
141*c97ad5cdSakolb 	struct fsszone	*fssz_next;	/* next fsszone_t in fsspset_t	*/
142*c97ad5cdSakolb 	struct fsszone	*fssz_prev;	/* prev fsszone_t in fsspset_t	*/
143*c97ad5cdSakolb 	uint32_t	fssz_shares;	/* sum of all project shares	*/
144*c97ad5cdSakolb 	uint32_t	fssz_nproj;	/* # of projects		*/
1457c478bd9Sstevel@tonic-gate 	uint32_t	fssz_rshares;	/* "real" shares given to zone	*/
146*c97ad5cdSakolb 	uint32_t	fssz_runnable;	/* # of runnable projects	*/
1477c478bd9Sstevel@tonic-gate } fsszone_t;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #define	FSSPROC(tx)		((fssproc_t *)(tx->t_cldata))
1507c478bd9Sstevel@tonic-gate #define	FSSPROC2FSSPROJ(fssx)	((fssx)->fss_proj);
1517c478bd9Sstevel@tonic-gate #define	FSSPROC2FSSPSET(fssx)	(FSSPROC2FSSPROJ(fssx)->fssp_pset)
1527c478bd9Sstevel@tonic-gate #define	FSSPROJ(tx)		(FSSPROC(tx)->fss_proj)
1537c478bd9Sstevel@tonic-gate #define	FSSPROJ2FSSPSET(fssx)	((fssx)->fssp_pset)
1547c478bd9Sstevel@tonic-gate #define	FSSPROJ2KPROJ(fssx)	((fssx)->fssp_proj)
1557c478bd9Sstevel@tonic-gate #define	FSSPROJ2FSSZONE(fssx)	((fssx)->fssp_fsszone)
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * fss_flags
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	FSSKPRI		0x01	/* the thread is in kernel mode	*/
1617c478bd9Sstevel@tonic-gate #define	FSSBACKQ	0x02	/* thread should be placed at the back of */
1627c478bd9Sstevel@tonic-gate 				/* the dispatch queue if preempted */
1639ac8606fSraf #define	FSSRESTORE	0x04	/* thread was not preempted, due to schedctl */
1649ac8606fSraf 				/* restore priority from fss_scpri */
165*c97ad5cdSakolb 
166*c97ad5cdSakolb #endif	/* _KERNEL */
167*c97ad5cdSakolb 
1687c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate #endif
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #endif	/* _SYS_FSS_H */
173