2 * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
27 #ifndef __DISPATCH_SHIMS_PERFMON__
28 #define __DISPATCH_SHIMS_PERFMON__
31 #if DISPATCH_INTROSPECTION
32 #error invalid configuration
36 perfmon_thread_no_trace
= 0,
37 perfmon_thread_event_no_steal
, // 1) Event threads that couldn't steal
38 perfmon_thread_event_steal
, // 2) Event threads failing to steal very late
39 perfmon_thread_worker_non_oc
, // 3) Non overcommit threads finding
40 // nothing on the root queues
41 perfmon_thread_worker_oc
, // 4) Overcommit thread finding nothing to do
42 perfmon_thread_manager
,
43 } perfmon_thread_type
;
45 DISPATCH_ALWAYS_INLINE
47 _dispatch_perfmon_workitem_inc(void)
50 cnt
= (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key
);
51 _dispatch_thread_setspecific(dispatch_bcounter_key
, (void *)++cnt
);
54 DISPATCH_ALWAYS_INLINE
56 _dispatch_perfmon_workitem_dec(void)
59 cnt
= (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key
);
60 _dispatch_thread_setspecific(dispatch_bcounter_key
, (void *)--cnt
);
63 #define DISPATCH_PERF_MON_ARGS_PROTO , uint64_t perfmon_start
64 #define DISPATCH_PERF_MON_ARGS , perfmon_start
65 #define DISPATCH_PERF_MON_VAR uint64_t perfmon_start;
66 #define DISPATCH_PERF_MON_VAR_INIT uint64_t perfmon_start = 0;
68 #define _dispatch_perfmon_start_impl(trace) ({ \
69 if (trace) _dispatch_ktrace0(DISPATCH_PERF_MON_worker_thread_start); \
70 perfmon_start = _dispatch_absolute_time(); \
72 #define _dispatch_perfmon_start() \
73 DISPATCH_PERF_MON_VAR _dispatch_perfmon_start_impl(true)
74 #define _dispatch_perfmon_start_notrace() \
75 DISPATCH_PERF_MON_VAR _dispatch_perfmon_start_impl(false)
76 #define _dispatch_perfmon_end(thread_type) \
77 _dispatch_queue_merge_stats(perfmon_start, true, thread_type)
78 #define _dispatch_perfmon_end_notrace() \
79 _dispatch_queue_merge_stats(perfmon_start, false, perfmon_thread_no_trace)
81 void _dispatch_queue_merge_stats(uint64_t start
, bool trace
, perfmon_thread_type type
);
85 #define DISPATCH_PERF_MON_ARGS_PROTO
86 #define DISPATCH_PERF_MON_ARGS
87 #define DISPATCH_PERF_MON_VAR
88 #define DISPATCH_PERF_MON_VAR_INIT
89 #define _dispatch_perfmon_workitem_inc()
90 #define _dispatch_perfmon_workitem_dec()
91 #define _dispatch_perfmon_start_impl(trace)
92 #define _dispatch_perfmon_start()
93 #define _dispatch_perfmon_end(thread_type)
94 #define _dispatch_perfmon_start_notrace()
95 #define _dispatch_perfmon_end_notrace()
97 #endif // DISPATCH_PERF_MON