xref: /titanic_52/usr/src/uts/common/sys/cmt.h (revision a4aef2bab3a15f31b03de3834937be168fb83b36)
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 	int		cmt_hint;		/* hint for balancing */
65 	struct group	cmt_cpus_actv;
66 	struct bitset	cmt_cpus_actv_set;	/* bitset of active CPUs */
67 } pg_cmt_t;
68 
69 /*
70  * CMT lgroup structure
71  */
72 typedef struct cmt_lgrp {
73 	group_t		cl_pgs;		/* Top level group of active CMT PGs */
74 	int		cl_npgs;	/* # of top level PGs in the lgroup */
75 	lgrp_handle_t	cl_hand;	/* lgroup's platform handle */
76 	struct cmt_lgrp	*cl_next;	/* next cmt_lgrp */
77 } cmt_lgrp_t;
78 
79 /*
80  * Change the number of running threads on the pg
81  */
82 #define	PG_NRUN_UPDATE(cp, n)		(pg_cmt_load((cp), (n)))
83 
84 /*
85  * Indicate that the given logical CPU is (or isn't) currently utilized
86  */
87 #define	CMT_CPU_UTILIZED(cp)		(pg_cmt_load((cp), 1))
88 #define	CMT_CPU_NOT_UTILIZED(cp)	(pg_cmt_load((cp), -1))
89 
90 /*
91  * CMT PG's capacity
92  *
93  * Currently, this is defined to be the number of active
94  * logical CPUs in the group.
95  *
96  * This will be used in conjunction with the utilization, which is defined
97  * to be the number of threads actively running on CPUs in the group.
98  */
99 #define	CMT_CAPACITY(pg)	(GROUP_SIZE(&((pg_cmt_t *)pg)->cmt_cpus_actv))
100 
101 void		pg_cmt_load(cpu_t *, int);
102 void		pg_cmt_cpu_startup(cpu_t *);
103 int		pg_cmt_can_migrate(cpu_t *, cpu_t *);
104 
105 /*
106  * CMT platform interfaces
107  */
108 pg_cmt_policy_t	pg_plat_cmt_policy(pghw_type_t);
109 int		pg_plat_cmt_rank(pg_cmt_t *, pg_cmt_t *);
110 
111 /*
112  * CMT dispatcher policy
113  */
114 cpu_t		*cmt_balance(kthread_t *, cpu_t *);
115 
116 /*
117  * Power Aware Dispatcher Interfaces
118  */
119 int		cmt_pad_enable(pghw_type_t);
120 int		cmt_pad_disable(pghw_type_t);
121 
122 #endif	/* !_KERNEL && !_KMEMUSER */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif /* _CMT_H */
129