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