xref: /onnv-gate/usr/src/uts/common/sys/cpucaps_impl.h (revision 11066:cebb50cbe4f9)
13792Sakolb /*
23792Sakolb  * CDDL HEADER START
33792Sakolb  *
43792Sakolb  * The contents of this file are subject to the terms of the
53792Sakolb  * Common Development and Distribution License (the "License").
63792Sakolb  * You may not use this file except in compliance with the License.
73792Sakolb  *
83792Sakolb  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93792Sakolb  * or http://www.opensolaris.org/os/licensing.
103792Sakolb  * See the License for the specific language governing permissions
113792Sakolb  * and limitations under the License.
123792Sakolb  *
133792Sakolb  * When distributing Covered Code, include this CDDL HEADER in each
143792Sakolb  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153792Sakolb  * If applicable, add the following below this CDDL HEADER, with the
163792Sakolb  * fields enclosed by brackets "[]" replaced with your own identifying
173792Sakolb  * information: Portions Copyright [yyyy] [name of copyright owner]
183792Sakolb  *
193792Sakolb  * CDDL HEADER END
203792Sakolb  */
213792Sakolb 
223792Sakolb /*
23*11066Srafael.vanoni@sun.com  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
243792Sakolb  * Use is subject to license terms.
253792Sakolb  */
263792Sakolb 
273792Sakolb #ifndef	_SYS_CPUCAPS_IMPL_H
283792Sakolb #define	_SYS_CPUCAPS_IMPL_H
293792Sakolb 
303792Sakolb #ifdef	__cplusplus
313792Sakolb extern "C" {
323792Sakolb #endif
333792Sakolb 
343792Sakolb #ifdef _KERNEL
353792Sakolb 
363792Sakolb #include <sys/kstat.h>
373792Sakolb #include <sys/cpucaps.h>
383792Sakolb #include <sys/list.h>
393792Sakolb #include <sys/time.h>
403792Sakolb #include <sys/waitq.h>
413792Sakolb 
423792Sakolb /*
433792Sakolb  * When resource control framework sets the cap to NOCAP value the cap
443792Sakolb  * is disabled.
453792Sakolb  */
463792Sakolb #define	NOCAP	MAXCAP
473792Sakolb 
483792Sakolb /*
493792Sakolb  * Maximum value for the cap usage. Should be the maximum value for hrtime_t
503792Sakolb  */
513792Sakolb #if defined(_LP64)
523792Sakolb #define	MAX_USAGE LONG_MAX
533792Sakolb #else
543792Sakolb #define	MAX_USAGE 9223372036854775807LL
553792Sakolb #endif
563792Sakolb 
573792Sakolb 
583792Sakolb /*
593792Sakolb  * Most of the per-project or per-zone state related to CPU caps is kept in the
603792Sakolb  * cpucap_t structure.
613792Sakolb  */
623792Sakolb typedef struct cpucap {
633792Sakolb 	list_node_t	cap_link;	/* next/prev capped entity	*/
643792Sakolb 	struct kproject	*cap_project;	/* project for the cap		*/
653792Sakolb 	struct zone	*cap_zone;	/* zone for the cap		*/
663792Sakolb 	waitq_t		cap_waitq;	/* waitq for capped threads	*/
673792Sakolb 	kstat_t		*cap_kstat;	/* cpucaps specific kstat	*/
68*11066Srafael.vanoni@sun.com 	int64_t		cap_gen;	/* zone cap specific 		*/
693792Sakolb 	hrtime_t	cap_value;	/* scaled CPU usage cap		*/
703792Sakolb 	hrtime_t	cap_usage;	/* current CPU usage		*/
713792Sakolb 	disp_lock_t	cap_usagelock;	/* protects cap_usage above	*/
723792Sakolb 	/*
733792Sakolb 	 * Per cap statistics.
743792Sakolb 	 */
753792Sakolb 	hrtime_t	cap_maxusage;	/* maximum cap usage		*/
763792Sakolb 	u_longlong_t	cap_below;	/* # of ticks spend below the cap */
773792Sakolb 	u_longlong_t	cap_above;	/* # of ticks spend above the cap */
783792Sakolb } cpucap_t;
793792Sakolb 
803792Sakolb /*
813792Sakolb  * Wrapper macros for checking cap state.
823792Sakolb  */
833792Sakolb #define	CAP_ENABLED(cap) ((cap)->cap_value != 0)
843792Sakolb #define	CAP_DISABLED(cap) (!CAP_ENABLED(cap))
853792Sakolb 
863792Sakolb #define	PROJECT_IS_CAPPED(project) \
873792Sakolb 	(((project)->kpj_cpucap != NULL) && \
883792Sakolb 	CAP_ENABLED((project)->kpj_cpucap))
893792Sakolb 
903792Sakolb #define	ZONE_IS_CAPPED(zone) \
913792Sakolb 	(((zone)->zone_cpucap != NULL) && \
923792Sakolb 	CAP_ENABLED((zone)->zone_cpucap))
933792Sakolb 
943792Sakolb #endif	/* _KERNEL */
953792Sakolb 
963792Sakolb #ifdef	__cplusplus
973792Sakolb }
983792Sakolb #endif
993792Sakolb 
1003792Sakolb #endif	/* _SYS_CPUCAPS_IMPL_H */
101