xref: /titanic_41/usr/src/uts/common/sys/cpucaps_impl.h (revision f127cb91970601c2695eead0ee127f1cac48bb7a)
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 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_CPUCAPS_IMPL_H
28 #define	_SYS_CPUCAPS_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef _KERNEL
37 
38 #include <sys/kstat.h>
39 #include <sys/cpucaps.h>
40 #include <sys/list.h>
41 #include <sys/time.h>
42 #include <sys/waitq.h>
43 
44 /*
45  * When resource control framework sets the cap to NOCAP value the cap
46  * is disabled.
47  */
48 #define	NOCAP	MAXCAP
49 
50 /*
51  * Maximum value for the cap usage. Should be the maximum value for hrtime_t
52  */
53 #if defined(_LP64)
54 #define	MAX_USAGE LONG_MAX
55 #else
56 #define	MAX_USAGE 9223372036854775807LL
57 #endif
58 
59 
60 /*
61  * Most of the per-project or per-zone state related to CPU caps is kept in the
62  * cpucap_t structure.
63  */
64 typedef struct cpucap {
65 	list_node_t	cap_link;	/* next/prev capped entity	*/
66 	struct kproject	*cap_project;	/* project for the cap		*/
67 	struct zone	*cap_zone;	/* zone for the cap		*/
68 	waitq_t		cap_waitq;	/* waitq for capped threads	*/
69 	kstat_t		*cap_kstat;	/* cpucaps specific kstat	*/
70 	int64_t		cap_lbolt;	/* zone cap specific 		*/
71 	hrtime_t	cap_value;	/* scaled CPU usage cap		*/
72 	hrtime_t	cap_usage;	/* current CPU usage		*/
73 	disp_lock_t	cap_usagelock;	/* protects cap_usage above	*/
74 	/*
75 	 * Per cap statistics.
76 	 */
77 	hrtime_t	cap_maxusage;	/* maximum cap usage		*/
78 	u_longlong_t	cap_below;	/* # of ticks spend below the cap */
79 	u_longlong_t	cap_above;	/* # of ticks spend above the cap */
80 } cpucap_t;
81 
82 /*
83  * Wrapper macros for checking cap state.
84  */
85 #define	CAP_ENABLED(cap) ((cap)->cap_value != 0)
86 #define	CAP_DISABLED(cap) (!CAP_ENABLED(cap))
87 
88 #define	PROJECT_IS_CAPPED(project) \
89 	(((project)->kpj_cpucap != NULL) && \
90 	CAP_ENABLED((project)->kpj_cpucap))
91 
92 #define	ZONE_IS_CAPPED(zone) \
93 	(((zone)->zone_cpucap != NULL) && \
94 	CAP_ENABLED((zone)->zone_cpucap))
95 
96 #endif	/* _KERNEL */
97 
98 #ifdef	__cplusplus
99 }
100 #endif
101 
102 #endif	/* _SYS_CPUCAPS_IMPL_H */
103