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