xref: /titanic_50/usr/src/uts/common/sys/cpupart.h (revision 927a453e165c072d45bd6aa2945b3db0fce17c56)
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 2006 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/chip.h>
39 #include <sys/time.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #ifdef _KERNEL
46 
47 typedef int	cpupartid_t;
48 
49 /*
50  * Special partition id.
51  */
52 #define	CP_DEFAULT	0
53 
54 /*
55  * Flags for cpupart_list()
56  */
57 #define	CP_ALL		0		/* return all cpu partitions */
58 #define	CP_NONEMPTY	1		/* return only non-empty ones */
59 
60 #if defined(_MACHDEP)
61 struct mach_cpupart {
62 	cpuset_t	mc_haltset;
63 	chip_set_t	mc_chipset;
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 
106 	struct mach_cpupart *cp_mach;   /* mach-specific */
107 } cpupart_t;
108 
109 typedef struct cpupart_kstat {
110 	kstat_named_t	cpk_updates;		/* number of updates */
111 	kstat_named_t	cpk_runnable;		/* cum # of runnable threads */
112 	kstat_named_t	cpk_waiting;		/* cum # waiting for I/O */
113 	kstat_named_t	cpk_ncpus;		/* current # of CPUs */
114 	kstat_named_t	cpk_avenrun_1min;	/* 1-minute load average */
115 	kstat_named_t	cpk_avenrun_5min;	/* 5-minute load average */
116 	kstat_named_t	cpk_avenrun_15min;	/* 15-minute load average */
117 } cpupart_kstat_t;
118 
119 /*
120  * Macro to obtain the maximum run priority for the global queue associated
121  * with given cpu partition.
122  */
123 #define	CP_MAXRUNPRI(cp)	((cp)->cp_kp_queue.disp_maxrunpri)
124 
125 /*
126  * This macro is used to determine if the given thread must surrender
127  * CPU to higher priority runnable threads on one of its dispatch queues.
128  * This should really be defined in <sys/disp.h> but it is not because
129  * including <sys/cpupart.h> there would cause recursive includes.
130  */
131 #define	DISP_MUST_SURRENDER(t)				\
132 	((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) ||		\
133 	(CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
134 
135 extern cpupart_t	cp_default;
136 extern cpupart_t	*cp_list_head;
137 extern uint_t		cp_numparts;
138 extern uint_t		cp_numparts_nonempty;
139 
140 extern void	cpupart_initialize_default();
141 extern cpupart_t *cpupart_find(psetid_t);
142 extern int	cpupart_create(psetid_t *);
143 extern int	cpupart_destroy(psetid_t);
144 extern psetid_t	cpupart_query_cpu(cpu_t *);
145 extern int	cpupart_attach_cpu(psetid_t, cpu_t *, int);
146 extern int	cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *);
147 extern int	cpupart_bind_thread(kthread_id_t, psetid_t, int, void *,
148     void *);
149 extern void	cpupart_kpqalloc(pri_t);
150 extern int	cpupart_get_loadavg(psetid_t, int *, int);
151 extern uint_t	cpupart_list(psetid_t *, uint_t, int);
152 extern int	cpupart_setattr(psetid_t, uint_t);
153 extern int	cpupart_getattr(psetid_t, uint_t *);
154 
155 #endif	/* _KERNEL */
156 
157 #ifdef	__cplusplus
158 }
159 #endif
160 
161 #endif	/* _SYS_CPUPART_H */
162