Loading...
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /* * Copyright (c) 2011-2021 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef KPERF_KPTIMER_H #define KPERF_KPTIMER_H /* * kptimer is responsible for managing the kperf's on-CPU timers. These * timers sample threads that are running on CPUs at a cadence determined by a * specified period. When they fire, a handler runs the specified action and * reprograms the timer to fire again. To get everything started or stopped, * kptimer issues a broadcast IPI to modify kperf's multiplexed per-CPU timer, * stored in the machine-dependent per-CPU structure. * * On-CPU timers are disabled when the CPU they've been programmed for goes idle * to prevent waking up the idle CPU when it's not running anything interesting. * This logic lives in the platform code that's responsible for entering and * exiting idle. * * Traditional PET is configured here (since it's defined by identifying a timer * to use for PET) but its mechanism is in osfmk/kperf/pet.c. Lightweight PET * does use kptimer to increment its generation count, however. */ /* * The minimum allowed timer period depends on the type of client (foreground vs. * background) and timer (on-CPU vs. PET). */ enum kptimer_period_limit { KTPL_FG, KTPL_BG, KTPL_FG_PET, KTPL_BG_PET, KTPL_MAX, }; /* * The minimum timer periods allowed by kperf. There's no other mechanism * to prevent interrupt storms due to kptimer. */ extern const uint64_t kptimer_minperiods_ns[KTPL_MAX]; /* * Called from the kernel startup thread to set up kptimer. */ void kptimer_init(void); /* * Return the minimum timer period in Mach time units. */ uint64_t kptimer_min_period_abs(bool pet); /* * Return the number of timers available. */ unsigned int kptimer_get_count(void); /* * Set the number of timers available to `count`. * * Returns 0 on success, and non-0 on error. */ int kptimer_set_count(unsigned int count); /* * Return the period of the timer identified by `timerid` in `period_out`. * * Returns 0 on success, and non-0 on error. */ int kptimer_get_period(unsigned int timerid, uint64_t *period_out); /* * Set the period of the timer identified by `timerid` to `period`. * * Returns non-zero on error, and zero otherwise. */ int kptimer_set_period(unsigned int timerid, uint64_t period); /* * Return the action of the timer identified by `timerid` in * `actionid_out`. */ int kptimer_get_action(unsigned int timerid, uint32_t *actionid_out); /* * Set the action of the timer identified by `timerid` to `actionid`. */ int kptimer_set_action(unsigned int timer, uint32_t actionid); /* * Set the PET timer to the timer identified by `timerid`. */ int kptimer_set_pet_timerid(unsigned int timerid); /* * Return the ID of the PET timer. */ unsigned int kptimer_get_pet_timerid(void); /* * For PET to rearm its timer after its sampling thread took `sampledur_abs` * to sample. */ void kptimer_pet_enter(uint64_t sampledur_abs); /* * Start all active timers. The ktrace lock must be held. */ void kptimer_start(void); /* * Stop all active timers, waiting for them to stop. The ktrace lock must be held. */ void kptimer_stop(void); /* * Cancel outstanding kperf timer for this CPU. */ void kptimer_stop_curcpu(void); /* * Reconfigure this CPU's kptimer expiration when it's brought online */ void kptimer_curcpu_up(void); /* * To indicate the next timer has expired. */ void kptimer_expire(processor_t processor, int cpuid, uint64_t now); /* * Reset the kptimer system. */ void kptimer_reset(void); #endif /* !defined(KPERF_KPTIMER_H) */ |