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