xref: /titanic_44/usr/src/uts/common/sys/cpupart.h (revision a38ddfee9c8c6b6c5a2947ff52fd2338362a4444)
1 /*
2  * CDDL HEADER START
3  *
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.
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_CPUPART_H
27 #define	_SYS_CPUPART_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/processor.h>
33 #include <sys/cpuvar.h>
34 #include <sys/disp.h>
35 #include <sys/pset.h>
36 #include <sys/lgrp.h>
37 #include <sys/lgrp_user.h>
38 #include <sys/pg.h>
39 #include <sys/bitset.h>
40 #include <sys/time.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 #ifdef _KERNEL
47 
48 typedef int	cpupartid_t;
49 
50 /*
51  * Special partition id.
52  */
53 #define	CP_DEFAULT	0
54 
55 /*
56  * Flags for cpupart_list()
57  */
58 #define	CP_ALL		0		/* return all cpu partitions */
59 #define	CP_NONEMPTY	1		/* return only non-empty ones */
60 
61 #if defined(_MACHDEP)
62 struct mach_cpupart {
63 	cpuset_t	mc_haltset;
64 };
65 
66 extern struct mach_cpupart cp_default_mach;
67 #else
68 struct mach_cpupart;
69 #endif
70 
71 typedef struct cpupart {
72 	disp_t		cp_kp_queue;	/* partition-wide kpreempt queue */
73 	cpupartid_t	cp_id;		/* partition ID */
74 	int		cp_ncpus;	/* number of online processors */
75 	struct cpupart	*cp_next;	/* next partition in list */
76 	struct cpupart	*cp_prev;	/* previous partition in list */
77 	struct cpu	*cp_cpulist;	/* processor list */
78 	struct kstat	*cp_kstat;	/* per-partition statistics */
79 
80 	/*
81 	 * cp_nrunnable and cp_nrunning are used to calculate load average.
82 	 */
83 	uint_t		cp_nrunnable;	/* current # of runnable threads */
84 	uint_t		cp_nrunning;	/* current # of running threads */
85 
86 	/*
87 	 * cp_updates, cp_nrunnable_cum, cp_nwaiting_cum, and cp_hp_avenrun
88 	 * are used to generate kstat information on an as-needed basis.
89 	 */
90 	uint64_t	cp_updates;	/* number of statistics updates */
91 	uint64_t	cp_nrunnable_cum; /* cum. # of runnable threads */
92 	uint64_t	cp_nwaiting_cum;  /* cum. # of waiting threads */
93 
94 	struct loadavg_s cp_loadavg;	/* cpupart loadavg */
95 
96 	klgrpset_t	cp_lgrpset;	/* set of lgroups on which this */
97 					/*    partition has cpus */
98 	lpl_t		*cp_lgrploads;	/* table of load averages for this  */
99 					/*    partition, indexed by lgrp ID */
100 	int		cp_nlgrploads;	/* size of cp_lgrploads table */
101 	uint64_t	cp_hp_avenrun[3]; /* high-precision load average */
102 	uint_t		cp_attr;	/* bitmask of attributes */
103 	lgrp_gen_t	cp_gen;		/* generation number */
104 	lgrp_id_t	cp_lgrp_hint;	/* last home lgroup chosen */
105 	bitset_t	cp_cmt_pgs;	/* CMT PGs represented */
106 
107 	struct mach_cpupart *cp_mach;   /* mach-specific */
108 } cpupart_t;
109 
110 typedef struct cpupart_kstat {
111 	kstat_named_t	cpk_updates;		/* number of updates */
112 	kstat_named_t	cpk_runnable;		/* cum # of runnable threads */
113 	kstat_named_t	cpk_waiting;		/* cum # waiting for I/O */
114 	kstat_named_t	cpk_ncpus;		/* current # of CPUs */
115 	kstat_named_t	cpk_avenrun_1min;	/* 1-minute load average */
116 	kstat_named_t	cpk_avenrun_5min;	/* 5-minute load average */
117 	kstat_named_t	cpk_avenrun_15min;	/* 15-minute load average */
118 } cpupart_kstat_t;
119 
120 /*
121  * Macro to obtain the maximum run priority for the global queue associated
122  * with given cpu partition.
123  */
124 #define	CP_MAXRUNPRI(cp)	((cp)->cp_kp_queue.disp_maxrunpri)
125 
126 /*
127  * This macro is used to determine if the given thread must surrender
128  * CPU to higher priority runnable threads on one of its dispatch queues.
129  * This should really be defined in <sys/disp.h> but it is not because
130  * including <sys/cpupart.h> there would cause recursive includes.
131  */
132 #define	DISP_MUST_SURRENDER(t)				\
133 	((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) ||		\
134 	(CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
135 
136 extern cpupart_t	cp_default;
137 extern cpupart_t	*cp_list_head;
138 extern uint_t		cp_numparts;
139 extern uint_t		cp_numparts_nonempty;
140 
141 extern void	cpupart_initialize_default();
142 extern cpupart_t *cpupart_find(psetid_t);
143 extern int	cpupart_create(psetid_t *);
144 extern int	cpupart_destroy(psetid_t);
145 extern psetid_t	cpupart_query_cpu(cpu_t *);
146 extern int	cpupart_attach_cpu(psetid_t, cpu_t *, int);
147 extern int	cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *);
148 extern int	cpupart_bind_thread(kthread_id_t, psetid_t, int, void *,
149     void *);
150 extern void	cpupart_kpqalloc(pri_t);
151 extern int	cpupart_get_loadavg(psetid_t, int *, int);
152 extern uint_t	cpupart_list(psetid_t *, uint_t, int);
153 extern int	cpupart_setattr(psetid_t, uint_t);
154 extern int	cpupart_getattr(psetid_t, uint_t *);
155 
156 #endif	/* _KERNEL */
157 
158 #ifdef	__cplusplus
159 }
160 #endif
161 
162 #endif	/* _SYS_CPUPART_H */
163