2014-12-09 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libcilkrts / runtime / stats.h
blobaaa992747650da6f925b7acc8f3eac01c489a102
1 /* stats.h -*-C++-*-
3 *************************************************************************
5 * @copyright
6 * Copyright (C) 2009-2013, Intel Corporation
7 * All rights reserved.
8 *
9 * @copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * @copyright
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 **************************************************************************/
39 /**
40 * @file stats.h
42 * @brief Support for gathering and reporting statistics on Cilk applications.
44 * Note that stats are normally NOT compiled in because it increases the
45 * overhead of stealing. To compile in profiling support, define CILK_PROFILE.
48 #ifndef INCLUDED_STATS_DOT_H
49 #define INCLUDED_STATS_DOT_H
51 /* #define CILK_PROFILE 1 */
52 // @note The CILK_PROFILE flag and intervals is known to be broken
53 // in at least programs with Windows exceptions.
54 // Enable this flag at your own peril. :)
56 #include <cilk/common.h>
57 #include "rts-common.h"
58 #include "internal/abi.h"
60 #ifdef CILK_PROFILE
61 #include <stdio.h> // Define FILE *
62 #endif
64 __CILKRTS_BEGIN_EXTERN_C
66 /** @brief Events that we measure. */
67 enum interval
69 INTERVAL_IN_SCHEDULER, ///< Time threads spend "bound" to Cilk
70 INTERVAL_WORKING, ///< Time spent working
71 INTERVAL_IN_RUNTIME, ///< Time spent executing runtime scheduling loop
72 INTERVAL_STEALING, ///< Time spent stealing work
73 INTERVAL_STEAL_SUCCESS, ///< Time to do a successful steal
74 INTERVAL_STEAL_FAIL_EMPTYQ, ///< Count of steal failures due to lack of stealable work
75 INTERVAL_STEAL_FAIL_LOCK, ///< Count of steal failures due to failure to lock worker
76 INTERVAL_STEAL_FAIL_USER_WORKER, ///< Count of steal failures by user workers which attempt to steal from another team
77 INTERVAL_STEAL_FAIL_DEKKER, ///< Count of steal failures due to Dekker protocol failure
78 INTERVAL_SYNC_CHECK, ///< Time spent processing syncs
79 INTERVAL_THE_EXCEPTION_CHECK, ///< Time spent performing THE exception checks
80 INTERVAL_THE_EXCEPTION_CHECK_USELESS, ///< Count of useless THE exception checks
81 INTERVAL_RETURNING, ///< Time spent returning from calls
82 INTERVAL_FINALIZE_CHILD, ///< Time spent in finalize_child
83 INTERVAL_PROVABLY_GOOD_STEAL, ///< Time spent in provably_good_steal
84 INTERVAL_UNCONDITIONAL_STEAL, ///< Time spent in unconditional_steal
85 INTERVAL_ALLOC_FULL_FRAME, ///< Time spent in __cilkrts_make_full_frame
86 INTERVAL_FRAME_ALLOC_LARGE, ///< Count of calls to __cilkrts_frame_malloc for buffers bigger than FRAME_MALLOC_MAX_SIZE or with a NULL worker
87 INTERVAL_FRAME_ALLOC, ///< Time spent allocating memory from worker buckets
88 INTERVAL_FRAME_ALLOC_GLOBAL, ///< Time spent calling memory allocator when buckets are empty
89 INTERVAL_FRAME_FREE_LARGE, ///< Count of calls to __cilkrts_frame_malloc for buffers bigger than FRAME_MALLOC_MAX_SIZE or with a NULL worker
90 INTERVAL_FRAME_FREE, ///< Time spent freeing memory to worker buckets
91 INTERVAL_FRAME_FREE_GLOBAL, ///< Time spent calling memory deallocator when buckets are full
92 INTERVAL_MUTEX_LOCK, ///< Count of calls to __cilkrts_mutex_lock for a worker
93 INTERVAL_MUTEX_LOCK_SPINNING, ///< Time spent spinning in __cilkrts_mutex_lock for a worker
94 INTERVAL_MUTEX_LOCK_YIELDING, ///< Time spent yielding in __cilkrts_mutex_lock for a worker
95 INTERVAL_MUTEX_TRYLOCK, ///< Count of calls to __cilkrts_mutex_trylock
96 INTERVAL_FIBER_ALLOCATE, ///< Time spent calling cilk_fiber_allocate
97 INTERVAL_FIBER_DEALLOCATE, ///< Time spent calling cilk_fiber_deallocate (not from thread)
98 INTERVAL_FIBER_ALLOCATE_FROM_THREAD, ///< Time spent calling cilk_fiber_allocate_from_thread
99 INTERVAL_FIBER_DEALLOCATE_FROM_THREAD, ///< Time spent calling cilk_fiber_deallocate (from thread)
100 INTERVAL_SUSPEND_RESUME_OTHER, ///< Count of fiber suspend_self_and_resume_other
101 INTERVAL_DEALLOCATE_RESUME_OTHER, ///< Count of fiber deallocate_self_and_resume_other
102 INTERVAL_N ///< Number of intervals, must be last
106 * @brief Struct that collects of all runtime statistics.
108 * There is an instance of this structure in each worker's
109 * local_state, as well as one in the @c global_state_t which will be
110 * used to accumulate the per-worker stats.
112 typedef struct statistics
114 /** Number of times each interval is entered */
115 unsigned long long count[INTERVAL_N];
118 * Time when the system entered each interval, in system-dependent
119 * "ticks"
121 unsigned long long start[INTERVAL_N];
123 /** Total time spent in each interval, in system-dependent "ticks" */
124 unsigned long long accum[INTERVAL_N];
127 * Largest global number of stacks seen by this worker.
128 * The true maximum at end of execution is the max of the
129 * worker maxima.
131 long stack_hwm;
132 } statistics;
135 * Initializes a statistics structure
137 * @param s The statistics structure to be initialized.
139 COMMON_PORTABLE void __cilkrts_init_stats(statistics *s);
142 * @brief Sums statistics from worker to the global struct
144 * @param to The statistics structure that will accumulate the information.
145 * This structure is usually @c g->stats.
146 * @param from The statistics structure that will be accumulated.
147 * This structure is usually statistics kept per worker.
149 COMMON_PORTABLE
150 void __cilkrts_accum_stats(statistics *to, statistics *from);
153 * @brief Mark the start of an interval by saving the current tick count.
155 * @pre Start time == INVALID_START
157 * @param w The worker we're accumulating stats for.
158 * @param i The interval we're accumulating stats for.
160 COMMON_PORTABLE
161 void __cilkrts_start_interval(__cilkrts_worker *w, enum interval i);
164 * @brief Mark the end of an interval by adding the ticks since the
165 * start to the accumulated time.
167 * @pre Start time != INVALID_START
169 * @param w The worker we're accumulating stats for.
170 * @param i The interval we're accumulating stats for.
172 COMMON_PORTABLE
173 void __cilkrts_stop_interval(__cilkrts_worker *w, enum interval i);
176 * @brief Start and stop interval I, charging zero time against it
178 * Precondition:
179 * - Start time == INVALID_START
181 * @param w The worker we're accumulating stats for.
182 * @param i The interval we're accumulating stats for.
184 COMMON_PORTABLE
185 void __cilkrts_note_interval(__cilkrts_worker *w, enum interval i);
187 #ifdef CILK_PROFILE
188 COMMON_PORTABLE
189 void dump_stats_to_file(FILE *stat_file, statistics *s);
190 #endif
193 #ifdef CILK_PROFILE
194 # define START_INTERVAL(w, i) __cilkrts_start_interval(w, i);
195 # define STOP_INTERVAL(w, i) __cilkrts_stop_interval(w, i);
196 # define NOTE_INTERVAL(w, i) __cilkrts_note_interval(w, i);
197 #else
198 /** Start an interval. No effect unless CILK_PROFILE is defined. */
199 # define START_INTERVAL(w, i)
200 /** End an interval. No effect unless CILK_PROFILE is defined. */
201 # define STOP_INTERVAL(w, i)
202 /** Increment a counter. No effect unless CILK_PROFILE is defined. */
203 # define NOTE_INTERVAL(w, i)
204 #endif
206 __CILKRTS_END_EXTERN_C
208 #endif // ! defined(INCLUDED_STATS_DOT_H)