|
root / base / usr / src / uts / common / sys / cpucaps_impl.h
cpucaps_impl.h C 101 lines 2.7 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYS_CPUCAPS_IMPL_H
#define	_SYS_CPUCAPS_IMPL_H

#ifdef	__cplusplus
extern "C" {
#endif

#ifdef _KERNEL

#include <sys/kstat.h>
#include <sys/cpucaps.h>
#include <sys/list.h>
#include <sys/time.h>
#include <sys/waitq.h>

/*
 * When resource control framework sets the cap to NOCAP value the cap
 * is disabled.
 */
#define	NOCAP	MAXCAP

/*
 * Maximum value for the cap usage. Should be the maximum value for hrtime_t
 */
#if defined(_LP64)
#define	MAX_USAGE LONG_MAX
#else
#define	MAX_USAGE 9223372036854775807LL
#endif


/*
 * Most of the per-project or per-zone state related to CPU caps is kept in the
 * cpucap_t structure.
 */
typedef struct cpucap {
	list_node_t	cap_link;	/* next/prev capped entity	*/
	struct kproject	*cap_project;	/* project for the cap		*/
	struct zone	*cap_zone;	/* zone for the cap		*/
	waitq_t		cap_waitq;	/* waitq for capped threads	*/
	kstat_t		*cap_kstat;	/* cpucaps specific kstat	*/
	int64_t		cap_gen;	/* zone cap specific 		*/
	hrtime_t	cap_value;	/* scaled CPU usage cap		*/
	hrtime_t	cap_usage;	/* current CPU usage		*/
	disp_lock_t	cap_usagelock;	/* protects cap_usage above	*/
	/*
	 * Per cap statistics.
	 */
	hrtime_t	cap_maxusage;	/* maximum cap usage		*/
	u_longlong_t	cap_below;	/* # of ticks spend below the cap */
	u_longlong_t	cap_above;	/* # of ticks spend above the cap */
} cpucap_t;

/*
 * Wrapper macros for checking cap state.
 */
#define	CAP_ENABLED(cap) ((cap)->cap_value != 0)
#define	CAP_DISABLED(cap) (!CAP_ENABLED(cap))

#define	PROJECT_IS_CAPPED(project) \
	(((project)->kpj_cpucap != NULL) && \
	CAP_ENABLED((project)->kpj_cpucap))

#define	ZONE_IS_CAPPED(zone) \
	(((zone)->zone_cpucap != NULL) && \
	CAP_ENABLED((zone)->zone_cpucap))

#endif	/* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_CPUCAPS_IMPL_H */