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