5027 zfs large block support (add copyright)
[unleashed.git] / usr / src / uts / common / sys / cpupart.h
blobb44dda5e84182fbf0c185be3be8c5a1bd26fca29
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _SYS_CPUPART_H
26 #define _SYS_CPUPART_H
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>
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
43 #ifdef _KERNEL
45 typedef int cpupartid_t;
48 * Special partition id.
50 #define CP_DEFAULT 0
53 * Flags for cpupart_list()
55 #define CP_ALL 0 /* return all cpu partitions */
56 #define CP_NONEMPTY 1 /* return only non-empty ones */
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 */
68 * cp_nrunnable and cp_nrunning are used to calculate load average.
70 uint_t cp_nrunnable; /* current # of runnable threads */
71 uint_t cp_nrunning; /* current # of running threads */
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.
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 */
81 struct loadavg_s cp_loadavg; /* cpupart loadavg */
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;
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;
107 * Macro to obtain the maximum run priority for the global queue associated
108 * with given cpu partition.
110 #define CP_MAXRUNPRI(cp) ((cp)->cp_kp_queue.disp_maxrunpri)
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.
118 #define DISP_MUST_SURRENDER(t) \
119 ((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) || \
120 (CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
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;
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.
134 extern uint_t cp_haltset_fanout;
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 *);
151 #endif /* _KERNEL */
153 #ifdef __cplusplus
155 #endif
157 #endif /* _SYS_CPUPART_H */