annotate libcilkrts/runtime/stats.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* stats.c -*-C-*-
kono
parents:
diff changeset
2 *
kono
parents:
diff changeset
3 *************************************************************************
kono
parents:
diff changeset
4 *
kono
parents:
diff changeset
5 * Copyright (C) 2009-2016, Intel Corporation
kono
parents:
diff changeset
6 * All rights reserved.
kono
parents:
diff changeset
7 *
kono
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
9 * modification, are permitted provided that the following conditions
kono
parents:
diff changeset
10 * are met:
kono
parents:
diff changeset
11 *
kono
parents:
diff changeset
12 * * Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
14 * * Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in
kono
parents:
diff changeset
16 * the documentation and/or other materials provided with the
kono
parents:
diff changeset
17 * distribution.
kono
parents:
diff changeset
18 * * Neither the name of Intel Corporation nor the names of its
kono
parents:
diff changeset
19 * contributors may be used to endorse or promote products derived
kono
parents:
diff changeset
20 * from this software without specific prior written permission.
kono
parents:
diff changeset
21 *
kono
parents:
diff changeset
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kono
parents:
diff changeset
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kono
parents:
diff changeset
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kono
parents:
diff changeset
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kono
parents:
diff changeset
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
kono
parents:
diff changeset
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
kono
parents:
diff changeset
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kono
parents:
diff changeset
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
kono
parents:
diff changeset
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
kono
parents:
diff changeset
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
kono
parents:
diff changeset
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
kono
parents:
diff changeset
33 * POSSIBILITY OF SUCH DAMAGE.
kono
parents:
diff changeset
34 *
kono
parents:
diff changeset
35 * *********************************************************************
kono
parents:
diff changeset
36 *
kono
parents:
diff changeset
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
kono
parents:
diff changeset
38 * a repository at cilkplus.org. Changes made to this file that are not
kono
parents:
diff changeset
39 * submitted through the contribution process detailed at
kono
parents:
diff changeset
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
kono
parents:
diff changeset
41 * time that a new version is released. Changes only submitted to the
kono
parents:
diff changeset
42 * GNU compiler collection or posted to the git repository at
kono
parents:
diff changeset
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
kono
parents:
diff changeset
44 * not tracked.
kono
parents:
diff changeset
45 *
kono
parents:
diff changeset
46 * We welcome your contributions to this open source project. Thank you
kono
parents:
diff changeset
47 * for your assistance in helping us improve Cilk Plus.
kono
parents:
diff changeset
48 **************************************************************************/
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 #include "stats.h"
kono
parents:
diff changeset
51 #include "bug.h"
kono
parents:
diff changeset
52 #include "os.h"
kono
parents:
diff changeset
53 #include "local_state.h"
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #include <stdio.h>
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 #define INVALID_START (0ULL - 1ULL)
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 #ifdef CILK_PROFILE
kono
parents:
diff changeset
60 /* MSVC does not support designated initializers, grrrr... */
kono
parents:
diff changeset
61 static const char *names[] = {
kono
parents:
diff changeset
62 /*[INTERVAL_IN_SCHEDULER]*/ "in scheduler",
kono
parents:
diff changeset
63 /*[INTERVAL_WORKING]*/ " of which: working",
kono
parents:
diff changeset
64 /*[INTERVAL_IN_RUNTIME]*/ " of which: in runtime",
kono
parents:
diff changeset
65 /*[INTERVAL_IN_SCHED_LOOP]*/ " of which: in sched loop",
kono
parents:
diff changeset
66 /*[INTERVAL_STEALING]*/ " of which: stealing",
kono
parents:
diff changeset
67 /*[INTERVAL_STEAL_SUCCESS]*/ "steal success: detach",
kono
parents:
diff changeset
68 /*[INTERVAL_STEAL_FAIL_EMPTYQ]*/ "steal fail: empty queue",
kono
parents:
diff changeset
69 /*[INTERVAL_STEAL_FAIL_LOCK]*/ "steal fail: victim locked",
kono
parents:
diff changeset
70 /*[INTERVAL_STEAL_FAIL_USER_WORKER]*/ "steal fail: user worker",
kono
parents:
diff changeset
71 /*[INTERVAL_STEAL_FAIL_DEKKER]*/ "steal fail: dekker",
kono
parents:
diff changeset
72 /*[INTERVAL_SYNC_CHECK]*/ "sync check",
kono
parents:
diff changeset
73 /*[INTERVAL_THE_EXCEPTION_CHECK]*/ "THE exception check",
kono
parents:
diff changeset
74 /*[INTERVAL_THE_EXCEPTION_CHECK_USELESS]*/ " of which: useless",
kono
parents:
diff changeset
75 /*[INTERVAL_RETURNING]*/ "returning",
kono
parents:
diff changeset
76 /*[INTERVAL_FINALIZE_CHILD]*/ "finalize child",
kono
parents:
diff changeset
77 /*[INTERVAL_PROVABLY_GOOD_STEAL]*/ "provably good steal",
kono
parents:
diff changeset
78 /*[INTERVAL_UNCONDITIONAL_STEAL]*/ "unconditional steal",
kono
parents:
diff changeset
79 /*[INTERVAL_ALLOC_FULL_FRAME]*/ "alloc full frame",
kono
parents:
diff changeset
80 /*[INTERVAL_FRAME_ALLOC_LARGE]*/ "large frame alloc",
kono
parents:
diff changeset
81 /*[INTERVAL_FRAME_ALLOC]*/ "small frame alloc",
kono
parents:
diff changeset
82 /*[INTERVAL_FRAME_ALLOC_GLOBAL]*/ " of which: to global pool",
kono
parents:
diff changeset
83 /*[INTERVAL_FRAME_FREE_LARGE]*/ "large frame free",
kono
parents:
diff changeset
84 /*[INTERVAL_FRAME_FREE]*/ "small frame free",
kono
parents:
diff changeset
85 /*[INTERVAL_FRAME_FREE_GLOBAL]*/ " of which: to global pool",
kono
parents:
diff changeset
86 /*[INTERVAL_MUTEX_LOCK]*/ "mutex lock",
kono
parents:
diff changeset
87 /*[INTERVAL_MUTEX_LOCK_SPINNING]*/ " spinning",
kono
parents:
diff changeset
88 /*[INTERVAL_MUTEX_LOCK_YIELDING]*/ " yielding",
kono
parents:
diff changeset
89 /*[INTERVAL_MUTEX_TRYLOCK]*/ "mutex trylock",
kono
parents:
diff changeset
90 /*[INTERVAL_FIBER_ALLOCATE]*/ "fiber_allocate",
kono
parents:
diff changeset
91 /*[INTERVAL_FIBER_DEALLOCATE]*/ "fiber_deallocate",
kono
parents:
diff changeset
92 /*[INTERVAL_FIBER_ALLOCATE_FROM_THREAD]*/ "fiber_allocate_from_thread",
kono
parents:
diff changeset
93 /*[INTERVAL_FIBER_DEALLOCATE_FROM_THREAD]*/ "fiber_deallocate (thread)",
kono
parents:
diff changeset
94 /*[INTERVAL_SUSPEND_RESUME_OTHER]*/ "fiber suspend self + resume",
kono
parents:
diff changeset
95 /*[INTERVAL_DEALLOCATE_RESUME_OTHER]*/ "fiber deallocate self + resume",
kono
parents:
diff changeset
96 /*[INTERVAL_INIT_WORKER]*/ "init worker thread",
kono
parents:
diff changeset
97 /*[INTERVAL_SCHEDULE_WAIT]*/ "schedule wait state",
kono
parents:
diff changeset
98 };
kono
parents:
diff changeset
99 #endif
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 void __cilkrts_init_stats(statistics *s)
kono
parents:
diff changeset
102 {
kono
parents:
diff changeset
103 int i;
kono
parents:
diff changeset
104 for (i = 0; i < INTERVAL_N; ++i) {
kono
parents:
diff changeset
105 s->start[i] = INVALID_START;
kono
parents:
diff changeset
106 s->accum[i] = 0;
kono
parents:
diff changeset
107 s->count[i] = 0;
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 s->stack_hwm = 0;
kono
parents:
diff changeset
111 }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 #ifdef CILK_PROFILE
kono
parents:
diff changeset
114 void __cilkrts_accum_stats(statistics *to, statistics *from)
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 int i;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 for (i = 0; i < INTERVAL_N; ++i) {
kono
parents:
diff changeset
119 to->accum[i] += from->accum[i];
kono
parents:
diff changeset
120 to->count[i] += from->count[i];
kono
parents:
diff changeset
121 from->accum[i] = 0;
kono
parents:
diff changeset
122 from->count[i] = 0;
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 if (from->stack_hwm > to->stack_hwm)
kono
parents:
diff changeset
126 to->stack_hwm = from->stack_hwm;
kono
parents:
diff changeset
127 from->stack_hwm = 0;
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 void __cilkrts_note_interval(__cilkrts_worker *w, enum interval i)
kono
parents:
diff changeset
131 {
kono
parents:
diff changeset
132 if (w) {
kono
parents:
diff changeset
133 statistics *s = w->l->stats;
kono
parents:
diff changeset
134 CILK_ASSERT(s->start[i] == INVALID_START);
kono
parents:
diff changeset
135 s->count[i]++;
kono
parents:
diff changeset
136 }
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 void __cilkrts_start_interval(__cilkrts_worker *w, enum interval i)
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 if (w) {
kono
parents:
diff changeset
142 statistics *s = w->l->stats;
kono
parents:
diff changeset
143 CILK_ASSERT(s->start[i] == INVALID_START);
kono
parents:
diff changeset
144 s->start[i] = __cilkrts_getticks();
kono
parents:
diff changeset
145 s->count[i]++;
kono
parents:
diff changeset
146 }
kono
parents:
diff changeset
147 }
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 void __cilkrts_stop_interval(__cilkrts_worker *w, enum interval i)
kono
parents:
diff changeset
150 {
kono
parents:
diff changeset
151 if (w) {
kono
parents:
diff changeset
152 statistics *s = w->l->stats;
kono
parents:
diff changeset
153 CILK_ASSERT(s->start[i] != INVALID_START);
kono
parents:
diff changeset
154 s->accum[i] += __cilkrts_getticks() - s->start[i];
kono
parents:
diff changeset
155 s->start[i] = INVALID_START;
kono
parents:
diff changeset
156 }
kono
parents:
diff changeset
157 }
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 void dump_stats_to_file(FILE *stat_file, statistics *s)
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 // Only print out stats for worker if they are nonzero.
kono
parents:
diff changeset
162 if (s->accum[INTERVAL_IN_SCHEDULER] > 0) {
kono
parents:
diff changeset
163 int i;
kono
parents:
diff changeset
164 fprintf(stat_file, "\nCILK PLUS RUNTIME SYSTEM STATISTICS:\n\n");
kono
parents:
diff changeset
165 fprintf(stat_file,
kono
parents:
diff changeset
166 " %-32s: %15s %10s %12s %10s\n",
kono
parents:
diff changeset
167 "event",
kono
parents:
diff changeset
168 "count",
kono
parents:
diff changeset
169 "ticks",
kono
parents:
diff changeset
170 "ticks/count",
kono
parents:
diff changeset
171 "%total"
kono
parents:
diff changeset
172 );
kono
parents:
diff changeset
173 for (i = 0; i < INTERVAL_N; ++i) {
kono
parents:
diff changeset
174 fprintf(stat_file, " %-32s: %15llu", names[i], s->count[i]);
kono
parents:
diff changeset
175 if (s->accum[i]) {
kono
parents:
diff changeset
176 fprintf(stat_file, " %10.3g %12.3g %10.2f",
kono
parents:
diff changeset
177 (double)s->accum[i],
kono
parents:
diff changeset
178 (double)s->accum[i] / (double)s->count[i],
kono
parents:
diff changeset
179 100.0 * (double)s->accum[i] /
kono
parents:
diff changeset
180 (double)s->accum[INTERVAL_IN_SCHEDULER]);
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182 fprintf(stat_file, "\n");
kono
parents:
diff changeset
183 }
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185 else {
kono
parents:
diff changeset
186 fprintf(stat_file, "empty statistics\n");
kono
parents:
diff changeset
187 }
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189 #endif // CILK_PROFILE
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 /* End stats.c */