xref: /illumos-gate/usr/src/uts/common/sys/fss.h (revision 6a0b1217)
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
5c97ad5cdSakolb  * Common Development and Distribution License (the "License").
6c97ad5cdSakolb  * 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 /*
23c97ad5cdSakolb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*6a0b1217SPatrick Mooney  * Copyright 2019 Joyent, Inc.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_SYS_FSS_H
297c478bd9Sstevel@tonic-gate #define	_SYS_FSS_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/thread.h>
337c478bd9Sstevel@tonic-gate #include <sys/project.h>
34c97ad5cdSakolb #include <sys/cpucaps.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
40c97ad5cdSakolb #ifdef	_KERNEL
41c97ad5cdSakolb 
427c478bd9Sstevel@tonic-gate typedef uint64_t fsspri_t;
437c478bd9Sstevel@tonic-gate typedef	uint64_t fssusage_t;
447c478bd9Sstevel@tonic-gate struct cpupart;
457c478bd9Sstevel@tonic-gate struct zone;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Valid arg1's for fss_allocbuf()
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	FSS_NPSET_BUF	1
517c478bd9Sstevel@tonic-gate #define	FSS_NPROJ_BUF	2
527c478bd9Sstevel@tonic-gate #define	FSS_ONE_BUF	3
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Valid arg2's for fss_allocbuf()
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	FSS_ALLOC_PROJ	1
587c478bd9Sstevel@tonic-gate #define	FSS_ALLOC_ZONE	2
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	FSS_MAXSHARES	65535
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct fssbuf {
637c478bd9Sstevel@tonic-gate 	int	fssb_size;
647c478bd9Sstevel@tonic-gate 	void	**fssb_list;
657c478bd9Sstevel@tonic-gate } fssbuf_t;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate void *fss_allocbuf(int, int);
687c478bd9Sstevel@tonic-gate void fss_freebuf(fssbuf_t *, int);
697c478bd9Sstevel@tonic-gate void fss_changeproj(kthread_id_t, void *, void *, fssbuf_t *, fssbuf_t *);
707c478bd9Sstevel@tonic-gate void fss_changepset(kthread_id_t, void *, fssbuf_t *, fssbuf_t *);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Fair share scheduling class specific cpu partition structure
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate typedef struct fsspset {
767c478bd9Sstevel@tonic-gate 	kmutex_t	fssps_lock;	/* lock to protect per-pset	*/
777c478bd9Sstevel@tonic-gate 					/* list of fssproj structures	*/
78c97ad5cdSakolb 	disp_lock_t	fssps_displock;	/* lock for fsps_maxfsspri	*/
797c478bd9Sstevel@tonic-gate 	struct cpupart	*fssps_cpupart;	/* ptr to our cpu partition	*/
807c478bd9Sstevel@tonic-gate 					/* protected by fsspsets_lock	*/
817c478bd9Sstevel@tonic-gate 	fsspri_t	fssps_maxfsspri; /* maximum fsspri value among	*/
827c478bd9Sstevel@tonic-gate 					/* all projects on this pset	*/
837c478bd9Sstevel@tonic-gate 	uint32_t	fssps_shares;	/* number of active shares	*/
847c478bd9Sstevel@tonic-gate 	uint32_t	fssps_nproj;	/* number of fssproj structures */
857c478bd9Sstevel@tonic-gate 					/* on the list			*/
867c478bd9Sstevel@tonic-gate 	struct fssproj	*fssps_list;	/* list of project parts	*/
877c478bd9Sstevel@tonic-gate 	struct fsszone	*fssps_zones;	/* list of fsszone_t's in pset	*/
88482a7749SJerry Jelinek 	uint32_t	fssps_gen;	/* generation for zone's kstats */
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	*/
104482a7749SJerry Jelinek 	uint32_t	fssp_ticks;	/* total of nice tick values	*/
105482a7749SJerry Jelinek 					/* protected by fssps_displock	*/
106482a7749SJerry Jelinek 	uint32_t	fssp_tick_cnt;	/* cnt of all ticks in this sec	*/
107482a7749SJerry Jelinek 	uint32_t	fssp_shr_pct;	/* active shr % in this sec	*/
1087c478bd9Sstevel@tonic-gate 					/* protected by fssps_displock	*/
1097c478bd9Sstevel@tonic-gate 	fssusage_t	fssp_usage;	/* this project's decayed usage */
1107c478bd9Sstevel@tonic-gate 	fssusage_t	fssp_shusage;	/* normalized usage		*/
1117c478bd9Sstevel@tonic-gate 	struct fssproj	*fssp_next;	/* next project on this pset	*/
1127c478bd9Sstevel@tonic-gate 	struct fssproj	*fssp_prev;	/* prev project on this pset	*/
1137c478bd9Sstevel@tonic-gate 	struct fsszone	*fssp_fsszone;	/* fsszone_t for this fssproj	*/
1147c478bd9Sstevel@tonic-gate } fssproj_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Fair share scheduling class specific thread structure
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate typedef struct fssproc {
1207c478bd9Sstevel@tonic-gate 	kthread_t *fss_tp;	/* pointer back to our thread		*/
121c97ad5cdSakolb 	fssproj_t *fss_proj;	/* pointer to our project FSS data	*/
1227c478bd9Sstevel@tonic-gate 	uchar_t fss_flags;	/* flags defined below			*/
1237c478bd9Sstevel@tonic-gate 	int	fss_timeleft;	/* time remaining in procs quantum	*/
1247c478bd9Sstevel@tonic-gate 	uint32_t fss_ticks;	/* ticks accumulated by this thread	*/
1257c478bd9Sstevel@tonic-gate 	pri_t	fss_upri;	/* user supplied priority (to priocntl)	*/
1267c478bd9Sstevel@tonic-gate 	pri_t	fss_uprilim;	/* user priority limit			*/
1277c478bd9Sstevel@tonic-gate 	pri_t	fss_umdpri;	/* user mode priority within fs class	*/
1289ac8606fSraf 	pri_t	fss_scpri;	/* remembered priority, for schedctl	*/
1297c478bd9Sstevel@tonic-gate 	int	fss_nice;	/* nice value for compatibility with ts	*/
1307c478bd9Sstevel@tonic-gate 	fsspri_t fss_fsspri;	/* internal fair share priority		*/
1317c478bd9Sstevel@tonic-gate 	int	fss_runnable;	/* to indicate runnable/sleeping thread	*/
1327c478bd9Sstevel@tonic-gate 	struct fssproc *fss_next; /* pointer to next fssproc_t struct	*/
1337c478bd9Sstevel@tonic-gate 	struct fssproc *fss_prev; /* pointer to prev fssproc_t sturct	*/
134c97ad5cdSakolb 	caps_sc_t fss_caps;	/* CPU caps specific data		*/
1357c478bd9Sstevel@tonic-gate } fssproc_t;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
138c97ad5cdSakolb  * One of these structures is allocated to each zone running within
139c97ad5cdSakolb  * each active cpu partition.  This means that if a zone spans more
140c97ad5cdSakolb  * than one cpu partition then it will have a few of these structures.
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate typedef struct fsszone {
143*6a0b1217SPatrick Mooney 	struct zone	*fssz_zone;	/* ptr to our zone structure	*/
144c97ad5cdSakolb 	struct fsszone	*fssz_next;	/* next fsszone_t in fsspset_t	*/
145c97ad5cdSakolb 	struct fsszone	*fssz_prev;	/* prev fsszone_t in fsspset_t	*/
146c97ad5cdSakolb 	uint32_t	fssz_shares;	/* sum of all project shares	*/
147c97ad5cdSakolb 	uint32_t	fssz_nproj;	/* # of projects		*/
148c97ad5cdSakolb 	uint32_t	fssz_rshares;	/* "real" shares given to zone	*/
149c97ad5cdSakolb 	uint32_t	fssz_runnable;	/* # of runnable projects	*/
1507c478bd9Sstevel@tonic-gate } fsszone_t;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #define	FSSPROC(tx)		((fssproc_t *)(tx->t_cldata))
1537c478bd9Sstevel@tonic-gate #define	FSSPROC2FSSPROJ(fssx)	((fssx)->fss_proj);
1547c478bd9Sstevel@tonic-gate #define	FSSPROC2FSSPSET(fssx)	(FSSPROC2FSSPROJ(fssx)->fssp_pset)
1557c478bd9Sstevel@tonic-gate #define	FSSPROJ(tx)		(FSSPROC(tx)->fss_proj)
1567c478bd9Sstevel@tonic-gate #define	FSSPROJ2FSSPSET(fssx)	((fssx)->fssp_pset)
1577c478bd9Sstevel@tonic-gate #define	FSSPROJ2KPROJ(fssx)	((fssx)->fssp_proj)
1587c478bd9Sstevel@tonic-gate #define	FSSPROJ2FSSZONE(fssx)	((fssx)->fssp_fsszone)
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * fss_flags
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate #define	FSSBACKQ	0x02	/* thread should be placed at the back of */
1647c478bd9Sstevel@tonic-gate 				/* the dispatch queue if preempted */
1659ac8606fSraf #define	FSSRESTORE	0x04	/* thread was not preempted, due to schedctl */
1669ac8606fSraf 				/* restore priority from fss_scpri */
167c97ad5cdSakolb 
168c97ad5cdSakolb #endif	/* _KERNEL */
169c97ad5cdSakolb 
1707c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate #endif
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #endif	/* _SYS_FSS_H */
175