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.
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.
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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_CPUPART_H
27 #define _SYS_CPUPART_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
32 #include <sys/processor.h>
33 #include <sys/cpuvar.h>
37 #include <sys/lgrp_user.h>
39 #include <sys/bitset.h>
48 typedef int cpupartid_t;
51 * Special partition id.
56 * Flags for cpupart_list()
58 #define CP_ALL 0 /* return all cpu partitions */
59 #define CP_NONEMPTY 1 /* return only non-empty ones */
66 extern struct mach_cpupart cp_default_mach;
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 */
81 * cp_nrunnable and cp_nrunning are used to calculate load average.
83 uint_t cp_nrunnable; /* current # of runnable threads */
84 uint_t cp_nrunning; /* current # of running threads */
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.
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 */
94 struct loadavg_s cp_loadavg; /* cpupart loadavg */
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 */
107 struct mach_cpupart *cp_mach; /* mach-specific */
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 */
121 * Macro to obtain the maximum run priority for the global queue associated
122 * with given cpu partition.
124 #define CP_MAXRUNPRI(cp) ((cp)->cp_kp_queue.disp_maxrunpri)
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.
132 #define DISP_MUST_SURRENDER(t) \
133 ((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) || \
134 (CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
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;
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 *,
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 *);
162 #endif /* _SYS_CPUPART_H */