xref: /illumos-gate/usr/src/uts/common/sys/cpupart.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_CPUPART_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_CPUPART_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/processor.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/disp.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/pset.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/lgrp.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/lgrp_user.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/chip.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
43*7c478bd9Sstevel@tonic-gate extern "C" {
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate typedef int	cpupartid_t;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * Special partition id.
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate #define	CP_DEFAULT	0
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate  * Flags for cpupart_list()
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate #define	CP_ALL		0		/* return all cpu partitions */
59*7c478bd9Sstevel@tonic-gate #define	CP_NONEMPTY	1		/* return only non-empty ones */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate typedef struct cpupart {
62*7c478bd9Sstevel@tonic-gate 	disp_t		cp_kp_queue;	/* partition-wide kpreempt queue */
63*7c478bd9Sstevel@tonic-gate 	cpupartid_t	cp_id;		/* partition ID */
64*7c478bd9Sstevel@tonic-gate 	int		cp_ncpus;	/* number of online processors */
65*7c478bd9Sstevel@tonic-gate 	struct cpupart	*cp_next;	/* next partition in list */
66*7c478bd9Sstevel@tonic-gate 	struct cpupart	*cp_prev;	/* previous partition in list */
67*7c478bd9Sstevel@tonic-gate 	struct cpu	*cp_cpulist;	/* processor list */
68*7c478bd9Sstevel@tonic-gate 	struct kstat	*cp_kstat;	/* per-partition statistics */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	/*
71*7c478bd9Sstevel@tonic-gate 	 * cp_nrunnable and cp_nrunning are used to calculate load average.
72*7c478bd9Sstevel@tonic-gate 	 */
73*7c478bd9Sstevel@tonic-gate 	uint_t		cp_nrunnable;	/* current # of runnable threads */
74*7c478bd9Sstevel@tonic-gate 	uint_t		cp_nrunning;	/* current # of running threads */
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	/*
77*7c478bd9Sstevel@tonic-gate 	 * cp_updates, cp_nrunnable_cum, cp_nwaiting_cum, and cp_hp_avenrun
78*7c478bd9Sstevel@tonic-gate 	 * are used to generate kstat information on an as-needed basis.
79*7c478bd9Sstevel@tonic-gate 	 */
80*7c478bd9Sstevel@tonic-gate 	uint64_t	cp_updates;	/* number of statistics updates */
81*7c478bd9Sstevel@tonic-gate 	uint64_t	cp_nrunnable_cum; /* cum. # of runnable threads */
82*7c478bd9Sstevel@tonic-gate 	uint64_t	cp_nwaiting_cum;  /* cum. # of waiting threads */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	struct loadavg_s cp_loadavg;	/* cpupart loadavg */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	klgrpset_t	cp_lgrpset;	/* set of lgroups on which this */
87*7c478bd9Sstevel@tonic-gate 					/*    partition has cpus */
88*7c478bd9Sstevel@tonic-gate 	lpl_t		*cp_lgrploads;	/* table of load averages for this  */
89*7c478bd9Sstevel@tonic-gate 					/*    partition, indexed by lgrp ID */
90*7c478bd9Sstevel@tonic-gate 	int		cp_nlgrploads;	/* size of cp_lgrploads table */
91*7c478bd9Sstevel@tonic-gate 	uint64_t	cp_hp_avenrun[3]; /* high-precision load average */
92*7c478bd9Sstevel@tonic-gate 	uint_t		cp_attr;	/* bitmask of attributes */
93*7c478bd9Sstevel@tonic-gate 	lgrp_gen_t	cp_gen;		/* generation number */
94*7c478bd9Sstevel@tonic-gate 	lgrp_id_t	cp_lgrp_hint;	/* last home lgroup chosen */
95*7c478bd9Sstevel@tonic-gate #if defined(_MACHDEP)
96*7c478bd9Sstevel@tonic-gate 	/*
97*7c478bd9Sstevel@tonic-gate 	 * These guarded members must reside at the end of the structure
98*7c478bd9Sstevel@tonic-gate 	 */
99*7c478bd9Sstevel@tonic-gate 	cpuset_t	cp_haltset;	/* bitmask of halted cpus */
100*7c478bd9Sstevel@tonic-gate 	chip_set_t	cp_chipset;	/* set of chips spanned by this part */
101*7c478bd9Sstevel@tonic-gate #endif	/* _MACHDEP */
102*7c478bd9Sstevel@tonic-gate } cpupart_t;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate typedef struct cpupart_kstat {
105*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_updates;		/* number of updates */
106*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_runnable;		/* cum # of runnable threads */
107*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_waiting;		/* cum # waiting for I/O */
108*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_ncpus;		/* current # of CPUs */
109*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_1min;	/* 1-minute load average */
110*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_5min;	/* 5-minute load average */
111*7c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_15min;	/* 15-minute load average */
112*7c478bd9Sstevel@tonic-gate } cpupart_kstat_t;
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate  * Macro to obtain the maximum run priority for the global queue associated
116*7c478bd9Sstevel@tonic-gate  * with given cpu partition.
117*7c478bd9Sstevel@tonic-gate  */
118*7c478bd9Sstevel@tonic-gate #define	CP_MAXRUNPRI(cp)	((cp)->cp_kp_queue.disp_maxrunpri)
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate  * This macro is used to determine if the given thread must surrender
122*7c478bd9Sstevel@tonic-gate  * CPU to higher priority runnable threads on one of its dispatch queues.
123*7c478bd9Sstevel@tonic-gate  * This should really be defined in <sys/disp.h> but it is not because
124*7c478bd9Sstevel@tonic-gate  * including <sys/cpupart.h> there would cause recursive includes.
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate #define	DISP_MUST_SURRENDER(t)				\
127*7c478bd9Sstevel@tonic-gate 	((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) ||		\
128*7c478bd9Sstevel@tonic-gate 	(CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate extern cpupart_t	cp_default;
131*7c478bd9Sstevel@tonic-gate extern cpupart_t	*cp_list_head;
132*7c478bd9Sstevel@tonic-gate extern uint_t		cp_numparts;
133*7c478bd9Sstevel@tonic-gate extern uint_t		cp_numparts_nonempty;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate extern void	cpupart_initialize_default();
136*7c478bd9Sstevel@tonic-gate extern cpupart_t *cpupart_find(psetid_t);
137*7c478bd9Sstevel@tonic-gate extern int	cpupart_create(psetid_t *);
138*7c478bd9Sstevel@tonic-gate extern int	cpupart_destroy(psetid_t);
139*7c478bd9Sstevel@tonic-gate extern psetid_t	cpupart_query_cpu(cpu_t *);
140*7c478bd9Sstevel@tonic-gate extern int	cpupart_attach_cpu(psetid_t, cpu_t *, int);
141*7c478bd9Sstevel@tonic-gate extern int	cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *);
142*7c478bd9Sstevel@tonic-gate extern int	cpupart_bind_thread(kthread_id_t, psetid_t, int, void *,
143*7c478bd9Sstevel@tonic-gate     void *);
144*7c478bd9Sstevel@tonic-gate extern void	cpupart_kpqalloc(pri_t);
145*7c478bd9Sstevel@tonic-gate extern int	cpupart_get_loadavg(psetid_t, int *, int);
146*7c478bd9Sstevel@tonic-gate extern uint_t	cpupart_list(psetid_t *, uint_t, int);
147*7c478bd9Sstevel@tonic-gate extern int	cpupart_setattr(psetid_t, uint_t);
148*7c478bd9Sstevel@tonic-gate extern int	cpupart_getattr(psetid_t, uint_t *);
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate #endif
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_CPUPART_H */
157