1/* 2 * Copyright (c) 2011-2012 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * Mach Operating System 30 * Copyright (c) 1989 Carnegie-Mellon University 31 * Copyright (c) 1988 Carnegie-Mellon University 32 * Copyright (c) 1987 Carnegie-Mellon University 33 * All rights reserved. The CMU software License Agreement specifies 34 * the terms and conditions for use and redistribution. 35 */ 36 37/* 38 * EXC_RESOURCE related macros, namespace etc. 39 */ 40 41#ifndef _EXC_RESOURCE_H_ 42#define _EXC_RESOURCE_H_ 43 44/* 45 * Generic exception code format: 46 * 47 * code: 48 * +----------------------------------------------------------+ 49 * |[63:61] type | [60:58] flavor | [57:0] type-specific data | 50 * +----------------------------------------------------------+ 51 */ 52 53 54/* EXC_RESOURCE type and flavor decoding routines */ 55#define EXC_RESOURCE_DECODE_RESOURCE_TYPE(code) \ 56 (((code) >> 61) & 0x7ULL) 57#define EXC_RESOURCE_DECODE_FLAVOR(code) \ 58 (((code) >> 58) & 0x7ULL) 59 60/* EXC_RESOURCE Types */ 61#define RESOURCE_TYPE_CPU 1 62#define RESOURCE_TYPE_WAKEUPS 2 63#define RESOURCE_TYPE_MEMORY 3 64 65/* RESOURCE_TYPE_CPU flavors */ 66#define FLAVOR_CPU_MONITOR 1 67 68/* 69 * RESOURCE_TYPE_CPU exception code & subcode. 70 * 71 * This is sent by the kernel when the CPU usage monitor 72 * is tripped. [See proc_set_cpumon_params()] 73 * 74 * code: 75 * +-----------------------------------------------+ 76 * |[63:61] RESOURCE |[60:58] FLAVOR_CPU_ |[57:32] | 77 * |_TYPE_CPU |MONITOR |Unused | 78 * +-----------------------------------------------+ 79 * |[31:7] Interval (sec) | [6:0] CPU limit (%)| 80 * +-----------------------------------------------+ 81 * 82 * subcode: 83 * +-----------------------------------------------+ 84 * | | [6:0] % of CPU | 85 * | | actually consumed | 86 * +-----------------------------------------------+ 87 * 88 */ 89 90/* RESOURCE_TYPE_CPU decoding macros */ 91#define EXC_RESOURCE_CPUMONITOR_DECODE_INTERVAL(code) \ 92 (((code) >> 7) & 0x1FFFFFFULL) 93#define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE(code) \ 94 ((code) & 0x7FULL) 95#define EXC_RESOURCE_CPUMONITOR_DECODE_PERCENTAGE_OBSERVED(subcode) \ 96 ((subcode) & 0x7FULL) 97 98 99/* RESOURCE_TYPE_WAKEUPS flavors */ 100#define FLAVOR_WAKEUPS_MONITOR 1 101 102/* 103 * RESOURCE_TYPE_WAKEUPS exception code & subcode. 104 * 105 * This is sent by the kernel when the platform idle 106 * wakeups monitor is tripped. 107 * [See proc_set_wakeupsmon_params()] 108 * 109 * code: 110 * +-----------------------------------------------+ 111 * |[63:61] RESOURCE |[60:58] FLAVOR_ |[57:32] | 112 * |_TYPE_WAKEUPS |WAKEUPS_MONITOR |Unused | 113 * +-----------------------------------------------+ 114 * | [31:20] Observation | [19:0] # of wakeups | 115 * | interval (sec) | permitted (per sec) | 116 * +-----------------------------------------------+ 117 * 118 * subcode: 119 * +-----------------------------------------------+ 120 * | | [19:0] # of wakeups | 121 * | | observed (per sec) | 122 * +-----------------------------------------------+ 123 * 124 */ 125 126#define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_PERMITTED(code) \ 127 ((code) & 0xFFFULL) 128#define EXC_RESOURCE_CPUMONITOR_DECODE_OBSERVATION_INTERVAL(code) \ 129 (((code) >> 20) & 0xFFFFFULL) 130#define EXC_RESOURCE_CPUMONITOR_DECODE_WAKEUPS_OBSERVED(subcode) \ 131 ((subcode) & 0xFFFFFULL) 132 133/* RESOURCE_TYPE_MEMORY flavors */ 134#define FLAVOR_HIGH_WATERMARK 1 135 136/* 137 * RESOURCE_TYPE_MEMORY / FLAVOR_HIGH_WATERMARK 138 * exception code & subcode. 139 * 140 * This is sent by the kernel when a task crosses its high 141 * watermark memory limit. 142 * 143 * code: 144 * +------------------------------------------------+ 145 * |[63:61] RESOURCE |[60:58] FLAVOR_HIGH_ |[57:32] | 146 * |_TYPE_MEMORY |WATERMARK |Unused | 147 * +------------------------------------------------+ 148 * | | [12:0] HWM limit (MB)| 149 * +------------------------------------------------+ 150 * 151 * subcode: 152 * +------------------------------------------------+ 153 * | unused | 154 * +------------------------------------------------+ 155 * 156 */ 157 158#define EXC_RESOURCE_HWM_DECODE_LIMIT(code) \ 159 ((code) & 0x1FFFULL) 160 161 162#ifdef KERNEL 163 164/* EXC_RESOURCE type and flavor encoding macros */ 165#define EXC_RESOURCE_ENCODE_TYPE(code, type) \ 166 ((code) |= (((uint64_t)(type) & 0x7ULL) << 61)) 167#define EXC_RESOURCE_ENCODE_FLAVOR(code, flavor) \ 168 ((code) |= (((uint64_t)(flavor) & 0x7ULL) << 58)) 169 170/* RESOURCE_TYPE_CPU::FLAVOR_CPU_MONITOR specific encoding macros */ 171#define EXC_RESOURCE_CPUMONITOR_ENCODE_INTERVAL(code, interval) \ 172 ((code) |= (((uint64_t)(interval) & 0x1FFFFFFULL) << 7)) 173#define EXC_RESOURCE_CPUMONITOR_ENCODE_PERCENTAGE(code, percentage) \ 174 ((code) |= (((uint64_t)(percentage) & 0x7FULL))) 175 176/* RESOURCE_TYPE_WAKEUPS::FLAVOR_WAKEUPS_MONITOR specific encoding macros */ 177#define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_PERMITTED(code, num) \ 178 ((code) |= ((uint64_t)(num) & 0xFFFFFULL)) 179#define EXC_RESOURCE_CPUMONITOR_ENCODE_OBSERVATION_INTERVAL(code, num) \ 180 ((code) |= (((uint64_t)(num) & 0xFFFULL) << 20)) 181#define EXC_RESOURCE_CPUMONITOR_ENCODE_WAKEUPS_OBSERVED(subcode, num) \ 182 ((subcode) |= ((uint64_t)(num) & 0xFFFFFULL)) 183 184/* RESOURCE_TYPE_MEMORY::FLAVOR_HIGH_WATERMARK specific encoding macros */ 185#define EXC_RESOURCE_HWM_ENCODE_LIMIT(code, num) \ 186 ((code) |= ((uint64_t)(num) & 0x1FFFULL)) 187 188#endif /* KERNEL */ 189 190 191#endif /* _EXC_RESOURCE_H_ */ 192