xref: /titanic_51/usr/src/uts/common/sys/cpucaps_impl.h (revision d3d50737e566cade9a08d73d2af95105ac7cd960)
1c97ad5cdSakolb /*
2c97ad5cdSakolb  * CDDL HEADER START
3c97ad5cdSakolb  *
4c97ad5cdSakolb  * The contents of this file are subject to the terms of the
5c97ad5cdSakolb  * Common Development and Distribution License (the "License").
6c97ad5cdSakolb  * You may not use this file except in compliance with the License.
7c97ad5cdSakolb  *
8c97ad5cdSakolb  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c97ad5cdSakolb  * or http://www.opensolaris.org/os/licensing.
10c97ad5cdSakolb  * See the License for the specific language governing permissions
11c97ad5cdSakolb  * and limitations under the License.
12c97ad5cdSakolb  *
13c97ad5cdSakolb  * When distributing Covered Code, include this CDDL HEADER in each
14c97ad5cdSakolb  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c97ad5cdSakolb  * If applicable, add the following below this CDDL HEADER, with the
16c97ad5cdSakolb  * fields enclosed by brackets "[]" replaced with your own identifying
17c97ad5cdSakolb  * information: Portions Copyright [yyyy] [name of copyright owner]
18c97ad5cdSakolb  *
19c97ad5cdSakolb  * CDDL HEADER END
20c97ad5cdSakolb  */
21c97ad5cdSakolb 
22c97ad5cdSakolb /*
23*d3d50737SRafael Vanoni  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24c97ad5cdSakolb  * Use is subject to license terms.
25c97ad5cdSakolb  */
26c97ad5cdSakolb 
27c97ad5cdSakolb #ifndef	_SYS_CPUCAPS_IMPL_H
28c97ad5cdSakolb #define	_SYS_CPUCAPS_IMPL_H
29c97ad5cdSakolb 
30c97ad5cdSakolb #ifdef	__cplusplus
31c97ad5cdSakolb extern "C" {
32c97ad5cdSakolb #endif
33c97ad5cdSakolb 
34c97ad5cdSakolb #ifdef _KERNEL
35c97ad5cdSakolb 
36c97ad5cdSakolb #include <sys/kstat.h>
37c97ad5cdSakolb #include <sys/cpucaps.h>
38c97ad5cdSakolb #include <sys/list.h>
39c97ad5cdSakolb #include <sys/time.h>
40c97ad5cdSakolb #include <sys/waitq.h>
41c97ad5cdSakolb 
42c97ad5cdSakolb /*
43c97ad5cdSakolb  * When resource control framework sets the cap to NOCAP value the cap
44c97ad5cdSakolb  * is disabled.
45c97ad5cdSakolb  */
46c97ad5cdSakolb #define	NOCAP	MAXCAP
47c97ad5cdSakolb 
48c97ad5cdSakolb /*
49c97ad5cdSakolb  * Maximum value for the cap usage. Should be the maximum value for hrtime_t
50c97ad5cdSakolb  */
51c97ad5cdSakolb #if defined(_LP64)
52c97ad5cdSakolb #define	MAX_USAGE LONG_MAX
53c97ad5cdSakolb #else
54c97ad5cdSakolb #define	MAX_USAGE 9223372036854775807LL
55c97ad5cdSakolb #endif
56c97ad5cdSakolb 
57c97ad5cdSakolb 
58c97ad5cdSakolb /*
59c97ad5cdSakolb  * Most of the per-project or per-zone state related to CPU caps is kept in the
60c97ad5cdSakolb  * cpucap_t structure.
61c97ad5cdSakolb  */
62c97ad5cdSakolb typedef struct cpucap {
63c97ad5cdSakolb 	list_node_t	cap_link;	/* next/prev capped entity	*/
64c97ad5cdSakolb 	struct kproject	*cap_project;	/* project for the cap		*/
65c97ad5cdSakolb 	struct zone	*cap_zone;	/* zone for the cap		*/
66c97ad5cdSakolb 	waitq_t		cap_waitq;	/* waitq for capped threads	*/
67c97ad5cdSakolb 	kstat_t		*cap_kstat;	/* cpucaps specific kstat	*/
68*d3d50737SRafael Vanoni 	int64_t		cap_gen;	/* zone cap specific 		*/
69c97ad5cdSakolb 	hrtime_t	cap_value;	/* scaled CPU usage cap		*/
70c97ad5cdSakolb 	hrtime_t	cap_usage;	/* current CPU usage		*/
71c97ad5cdSakolb 	disp_lock_t	cap_usagelock;	/* protects cap_usage above	*/
72c97ad5cdSakolb 	/*
73c97ad5cdSakolb 	 * Per cap statistics.
74c97ad5cdSakolb 	 */
75c97ad5cdSakolb 	hrtime_t	cap_maxusage;	/* maximum cap usage		*/
76c97ad5cdSakolb 	u_longlong_t	cap_below;	/* # of ticks spend below the cap */
77c97ad5cdSakolb 	u_longlong_t	cap_above;	/* # of ticks spend above the cap */
78c97ad5cdSakolb } cpucap_t;
79c97ad5cdSakolb 
80c97ad5cdSakolb /*
81c97ad5cdSakolb  * Wrapper macros for checking cap state.
82c97ad5cdSakolb  */
83c97ad5cdSakolb #define	CAP_ENABLED(cap) ((cap)->cap_value != 0)
84c97ad5cdSakolb #define	CAP_DISABLED(cap) (!CAP_ENABLED(cap))
85c97ad5cdSakolb 
86c97ad5cdSakolb #define	PROJECT_IS_CAPPED(project) \
87c97ad5cdSakolb 	(((project)->kpj_cpucap != NULL) && \
88c97ad5cdSakolb 	CAP_ENABLED((project)->kpj_cpucap))
89c97ad5cdSakolb 
90c97ad5cdSakolb #define	ZONE_IS_CAPPED(zone) \
91c97ad5cdSakolb 	(((zone)->zone_cpucap != NULL) && \
92c97ad5cdSakolb 	CAP_ENABLED((zone)->zone_cpucap))
93c97ad5cdSakolb 
94c97ad5cdSakolb #endif	/* _KERNEL */
95c97ad5cdSakolb 
96c97ad5cdSakolb #ifdef	__cplusplus
97c97ad5cdSakolb }
98c97ad5cdSakolb #endif
99c97ad5cdSakolb 
100c97ad5cdSakolb #endif	/* _SYS_CPUCAPS_IMPL_H */
101