xref: /titanic_51/usr/src/uts/common/sys/cmt.h (revision 67dbe2be0c0f1e2eb428b89088bb5667e8f0b9f6)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_CMT_H
27 #define	_CMT_H
28 
29 /*
30  * CMT PG class
31  */
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #if (defined(_KERNEL) || defined(_KMEMUSER))
38 #include <sys/group.h>
39 #include <sys/pghw.h>
40 #include <sys/lgrp.h>
41 #include <sys/types.h>
42 
43 /*
44  * CMT related dispatcher policies
45  */
46 #define	CMT_NO_POLICY	0x0
47 #define	CMT_BALANCE	0x1
48 #define	CMT_COALESCE	0x2
49 #define	CMT_AFFINITY	0x4
50 
51 typedef uint_t pg_cmt_policy_t;
52 
53 /*
54  * CMT pg structure
55  */
56 typedef struct pg_cmt {
57 	struct pghw	cmt_pg;			/* physical grouping */
58 	struct group	*cmt_siblings;		/* CMT PGs to balance with */
59 	struct pg_cmt	*cmt_parent;		/* Parent CMT PG */
60 	struct group	*cmt_children;		/* Active children CMT PGs */
61 	pg_cmt_policy_t	cmt_policy;		/* Dispatcher policies to use */
62 	uint32_t	cmt_utilization;	/* Group's utilization */
63 	int		cmt_nchildren;		/* # of children CMT PGs */
64 	struct group	cmt_cpus_actv;
65 	struct bitset	cmt_cpus_actv_set;	/* bitset of active CPUs */
66 } pg_cmt_t;
67 
68 /*
69  * CMT lgroup structure
70  */
71 typedef struct cmt_lgrp {
72 	group_t		cl_pgs;		/* Top level group of active CMT PGs */
73 	int		cl_npgs;	/* # of top level PGs in the lgroup */
74 	lgrp_handle_t	cl_hand;	/* lgroup's platform handle */
75 	struct cmt_lgrp	*cl_next;	/* next cmt_lgrp */
76 } cmt_lgrp_t;
77 
78 /*
79  * Change the number of running threads on the pg
80  */
81 #define	PG_NRUN_UPDATE(cp, n)		(pg_cmt_load((cp), (n)))
82 
83 /*
84  * Indicate that the given logical CPU is (or isn't) currently utilized
85  */
86 #define	CMT_CPU_UTILIZED(cp)		(pg_cmt_load((cp), 1))
87 #define	CMT_CPU_NOT_UTILIZED(cp)	(pg_cmt_load((cp), -1))
88 
89 /*
90  * CMT PG's capacity
91  *
92  * Currently, this is defined to be the number of active
93  * logical CPUs in the group.
94  *
95  * This will be used in conjunction with the utilization, which is defined
96  * to be the number of threads actively running on CPUs in the group.
97  */
98 #define	CMT_CAPACITY(pg)	(GROUP_SIZE(&((pg_cmt_t *)pg)->cmt_cpus_actv))
99 
100 void		pg_cmt_load(cpu_t *, int);
101 void		pg_cmt_cpu_startup(cpu_t *);
102 int		pg_cmt_can_migrate(cpu_t *, cpu_t *);
103 
104 /*
105  * CMT platform interfaces
106  */
107 pg_cmt_policy_t	pg_plat_cmt_policy(pghw_type_t);
108 int		pg_plat_cmt_rank(pg_cmt_t *, pg_cmt_t *);
109 
110 /*
111  * CMT dispatcher policy
112  */
113 cpu_t		*cmt_balance(kthread_t *, cpu_t *);
114 
115 /*
116  * Power Aware Dispatcher Interfaces
117  */
118 int		cmt_pad_enable(pghw_type_t);
119 int		cmt_pad_disable(pghw_type_t);
120 
121 #endif	/* !_KERNEL && !_KMEMUSER */
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif /* _CMT_H */
128