]>
Commit | Line | Data |
---|---|---|
39037602 A |
1 | #ifndef KPERF_TIMER_H |
2 | #define KPERF_TIMER_H | |
1c79356b | 3 | /* |
316670eb | 4 | * Copyright (c) 2011 Apple Computer, Inc. All rights reserved. |
1c79356b | 5 | * |
2d21ac55 | 6 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 7 | * |
2d21ac55 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. The rights granted to you under the License | |
12 | * may not be used to create, or enable the creation or redistribution of, | |
13 | * unlawful or unlicensed copies of an Apple operating system, or to | |
14 | * circumvent, violate, or enable the circumvention or violation of, any | |
15 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 16 | * |
2d21ac55 A |
17 | * Please obtain a copy of the License at |
18 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 19 | * |
2d21ac55 A |
20 | * The Original Code and all software distributed under the License are |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
0a7de745 | 27 | * |
2d21ac55 | 28 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 29 | */ |
91447636 | 30 | |
39037602 A |
31 | #include <kern/timer_call.h> |
32 | #include <kern/bits.h> | |
1c79356b | 33 | |
39037602 A |
34 | struct kperf_timer { |
35 | struct timer_call tcall; | |
36 | uint64_t period; | |
0a7de745 A |
37 | _Atomic uint32_t action_state; |
38 | uint32_t actionid; | |
39037602 A |
39 | |
40 | /* | |
41 | * A bitmap of CPUs that have a pending timer to service. On Intel, it | |
42 | * allows the core responding to the timer interrupt to not queue up | |
43 | * cross-calls on cores that haven't yet responded. On ARM, it allows | |
44 | * the signal handler to multiplex simultaneous fires of different | |
45 | * timers. | |
46 | */ | |
0a7de745 | 47 | _Atomic bitmap_t pending_cpus; |
a39ff7e2 A |
48 | |
49 | #if DEVELOPMENT || DEBUG | |
50 | uint64_t fire_time; | |
51 | #endif /* DEVELOPMENT || DEBUG */ | |
39037602 A |
52 | }; |
53 | ||
54 | extern struct kperf_timer *kperf_timerv; | |
55 | extern unsigned int kperf_timerc; | |
56 | ||
57 | void kperf_timer_reprogram(void); | |
58 | void kperf_timer_reprogram_all(void); | |
59 | ||
60 | void kperf_ipi_handler(void *param); | |
1c79356b | 61 | |
316670eb A |
62 | // return values from the action |
63 | #define TIMER_REPROGRAM (0) | |
39037602 | 64 | #define TIMER_STOP (1) |
1c79356b | 65 | |
5ba3f43e A |
66 | #if defined(__x86_64__) |
67 | ||
68 | #define KP_MIN_PERIOD_NS (20 * NSEC_PER_USEC) | |
d9a64523 | 69 | #define KP_MIN_PERIOD_BG_NS (1 * NSEC_PER_MSEC) |
5ba3f43e | 70 | #define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC) |
d9a64523 | 71 | #define KP_MIN_PERIOD_PET_BG_NS (5 * NSEC_PER_MSEC) |
5ba3f43e A |
72 | |
73 | #elif defined(__arm64__) | |
74 | ||
75 | #define KP_MIN_PERIOD_NS (50 * NSEC_PER_USEC) | |
d9a64523 | 76 | #define KP_MIN_PERIOD_BG_NS (1 * NSEC_PER_MSEC) |
5ba3f43e | 77 | #define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC) |
d9a64523 | 78 | #define KP_MIN_PERIOD_PET_BG_NS (10 * NSEC_PER_MSEC) |
5ba3f43e A |
79 | |
80 | #elif defined(__arm__) | |
81 | ||
82 | #define KP_MIN_PERIOD_NS (100 * NSEC_PER_USEC) | |
d9a64523 | 83 | #define KP_MIN_PERIOD_BG_NS (10 * NSEC_PER_MSEC) |
5ba3f43e | 84 | #define KP_MIN_PERIOD_PET_NS (2 * NSEC_PER_MSEC) |
d9a64523 | 85 | #define KP_MIN_PERIOD_PET_BG_NS (50 * NSEC_PER_MSEC) |
5ba3f43e A |
86 | |
87 | #else /* defined(__x86_64__) */ | |
88 | #error "unsupported architecture" | |
89 | #endif /* defined(__x86_64__) */ | |
90 | ||
39236c6e | 91 | /* getters and setters on timers */ |
39037602 A |
92 | unsigned kperf_timer_get_count(void); |
93 | int kperf_timer_set_count(unsigned int count); | |
1c79356b | 94 | |
39037602 A |
95 | int kperf_timer_get_period(unsigned int timer, uint64_t *period); |
96 | int kperf_timer_set_period(unsigned int timer, uint64_t period); | |
1c79356b | 97 | |
39037602 A |
98 | int kperf_timer_get_action(unsigned int timer, uint32_t *action); |
99 | int kperf_timer_set_action(unsigned int timer, uint32_t action); | |
39236c6e | 100 | |
39037602 A |
101 | void kperf_timer_go(void); |
102 | void kperf_timer_stop(void); | |
103 | void kperf_timer_reset(void); | |
1c79356b | 104 | |
39037602 A |
105 | unsigned int kperf_timer_get_petid(void); |
106 | int kperf_timer_set_petid(unsigned int count); | |
91447636 | 107 | |
316670eb | 108 | /* so PET thread can re-arm the timer */ |
39037602 A |
109 | void kperf_timer_pet_rearm(uint64_t elapsed_ticks); |
110 | ||
111 | #endif /* !defined(KPERF_TIMER_H) */ |