annotate libcilkrts/runtime/full_frame.c @ 113:bdf41c9fa0b7

remove RECTYPE
author mir3636
date Fri, 17 Nov 2017 06:33:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* full_frame.c -*-C++-*-
kono
parents:
diff changeset
2 *
kono
parents:
diff changeset
3 *************************************************************************
kono
parents:
diff changeset
4 *
kono
parents:
diff changeset
5 * Copyright (C) 2010-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
kono
parents:
diff changeset
51 #include "full_frame.h"
kono
parents:
diff changeset
52 #include "stats.h"
kono
parents:
diff changeset
53 #include "os.h"
kono
parents:
diff changeset
54 #include "bug.h"
kono
parents:
diff changeset
55 #include "jmpbuf.h"
kono
parents:
diff changeset
56 #include "frame_malloc.h"
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 COMMON_PORTABLE
kono
parents:
diff changeset
59 full_frame *__cilkrts_make_full_frame(__cilkrts_worker *w,
kono
parents:
diff changeset
60 __cilkrts_stack_frame *sf)
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 full_frame *ff;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 START_INTERVAL(w, INTERVAL_ALLOC_FULL_FRAME) {
kono
parents:
diff changeset
65 ff = (full_frame *)__cilkrts_frame_malloc(w, sizeof(*ff));
kono
parents:
diff changeset
66 __cilkrts_mutex_init(&ff->lock);
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 ff->full_frame_magic_0 = FULL_FRAME_MAGIC_0;
kono
parents:
diff changeset
69 ff->join_counter = 0;
kono
parents:
diff changeset
70 ff->parent = 0;
kono
parents:
diff changeset
71 ff->rightmost_child = 0;
kono
parents:
diff changeset
72 ff->left_sibling = ff->right_sibling = 0;
kono
parents:
diff changeset
73 ff->call_stack = sf;
kono
parents:
diff changeset
74 ff->is_call_child = 0;
kono
parents:
diff changeset
75 ff->simulated_stolen = 0;
kono
parents:
diff changeset
76 ff->children_reducer_map = ff->right_reducer_map = 0;
kono
parents:
diff changeset
77 ff->pending_exception =
kono
parents:
diff changeset
78 ff->child_pending_exception =
kono
parents:
diff changeset
79 ff->right_pending_exception = NULL;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 ff->sync_sp = 0;
kono
parents:
diff changeset
82 #ifdef _WIN32
kono
parents:
diff changeset
83 ff->exception_sp = 0;
kono
parents:
diff changeset
84 ff->trylevel = (unsigned long)-1;
kono
parents:
diff changeset
85 ff->registration = 0;
kono
parents:
diff changeset
86 #endif
kono
parents:
diff changeset
87 ff->frame_size = 0;
kono
parents:
diff changeset
88 ff->fiber_self = 0;
kono
parents:
diff changeset
89 ff->fiber_child = 0;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 ff->sync_master = 0;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 /*__cilkrts_init_full_frame_sysdep(w, ff);*/
kono
parents:
diff changeset
94 ff->full_frame_magic_1 = FULL_FRAME_MAGIC_1;
kono
parents:
diff changeset
95 } STOP_INTERVAL(w, INTERVAL_ALLOC_FULL_FRAME);
kono
parents:
diff changeset
96 return ff;
kono
parents:
diff changeset
97 }
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 COMMON_PORTABLE void __cilkrts_put_stack(full_frame *ff,
kono
parents:
diff changeset
100 __cilkrts_stack_frame *sf)
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 /* When suspending frame ff prior to stealing it, __cilkrts_put_stack is
kono
parents:
diff changeset
103 * used to store the stack pointer for eventual sync. When suspending
kono
parents:
diff changeset
104 * frame ff prior to a sync, __cilkrts_put_stack is called to re-establish
kono
parents:
diff changeset
105 * the sync stack pointer, offsetting it by any change in the stack depth
kono
parents:
diff changeset
106 * that occured between the spawn and the sync.
kono
parents:
diff changeset
107 * Although it is not usually meaningful to add two pointers, the value of
kono
parents:
diff changeset
108 * ff->sync_sp at the time of this call is really an integer, not a
kono
parents:
diff changeset
109 * pointer.
kono
parents:
diff changeset
110 */
kono
parents:
diff changeset
111 ptrdiff_t sync_sp_i = (ptrdiff_t) ff->sync_sp;
kono
parents:
diff changeset
112 char* sp = (char*) __cilkrts_get_sp(sf);
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 ff->sync_sp = sp + sync_sp_i;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 DBGPRINTF("%d- __cilkrts_put_stack - adjust (+) sync "
kono
parents:
diff changeset
117 "stack of full frame %p (+sp: %p) to %p\n",
kono
parents:
diff changeset
118 __cilkrts_get_tls_worker()->self, ff, sp, ff->sync_sp);
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 COMMON_PORTABLE void __cilkrts_take_stack(full_frame *ff, void *sp)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 /* When resuming the parent after a steal, __cilkrts_take_stack is used to
kono
parents:
diff changeset
124 * subtract the new stack pointer from the current stack pointer, storing
kono
parents:
diff changeset
125 * the offset in ff->sync_sp. When resuming after a sync,
kono
parents:
diff changeset
126 * __cilkrts_take_stack is used to subtract the new stack pointer from
kono
parents:
diff changeset
127 * itself, leaving ff->sync_sp at zero (null). Although the pointers being
kono
parents:
diff changeset
128 * subtracted are not part of the same contiguous chunk of memory, the
kono
parents:
diff changeset
129 * flat memory model allows us to subtract them and get a useable offset.
kono
parents:
diff changeset
130 */
kono
parents:
diff changeset
131 ptrdiff_t sync_sp_i = ff->sync_sp - (char*) sp;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 ff->sync_sp = (char *) sync_sp_i;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 DBGPRINTF("%d- __cilkrts_take_stack - adjust (-) sync "
kono
parents:
diff changeset
136 "stack of full frame %p to %p (-sp: %p)\n",
kono
parents:
diff changeset
137 __cilkrts_get_tls_worker()->self, ff, ff->sync_sp, sp);
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 COMMON_PORTABLE void __cilkrts_adjust_stack(full_frame *ff, size_t size)
kono
parents:
diff changeset
141 {
kono
parents:
diff changeset
142 /* When resuming the parent after a steal, __cilkrts_take_stack is used to
kono
parents:
diff changeset
143 * subtract the new stack pointer from the current stack pointer, storing
kono
parents:
diff changeset
144 * the offset in ff->sync_sp. When resuming after a sync,
kono
parents:
diff changeset
145 * __cilkrts_take_stack is used to subtract the new stack pointer from
kono
parents:
diff changeset
146 * itself, leaving ff->sync_sp at zero (null). Although the pointers being
kono
parents:
diff changeset
147 * subtracted are not part of the same contiguous chunk of memory, the
kono
parents:
diff changeset
148 * flat memory model allows us to subtract them and get a useable offset.
kono
parents:
diff changeset
149 *
kono
parents:
diff changeset
150 * __cilkrts_adjust_stack() is used to deallocate a Variable Length Array
kono
parents:
diff changeset
151 * by adding it's size to ff->sync_sp.
kono
parents:
diff changeset
152 */
kono
parents:
diff changeset
153 ff->sync_sp = ff->sync_sp + size;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 DBGPRINTF("%d- __cilkrts_adjust_stack - adjust (+) sync "
kono
parents:
diff changeset
156 "stack of full frame %p to %p (+ size: 0x%x)\n",
kono
parents:
diff changeset
157 __cilkrts_get_tls_worker()->self, ff, ff->sync_sp, size);
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 COMMON_PORTABLE
kono
parents:
diff changeset
161 void __cilkrts_destroy_full_frame(__cilkrts_worker *w, full_frame *ff)
kono
parents:
diff changeset
162 {
kono
parents:
diff changeset
163 validate_full_frame(ff);
kono
parents:
diff changeset
164 CILK_ASSERT(ff->children_reducer_map == 0);
kono
parents:
diff changeset
165 CILK_ASSERT(ff->right_reducer_map == 0);
kono
parents:
diff changeset
166 CILK_ASSERT(NULL == ff->pending_exception);
kono
parents:
diff changeset
167 CILK_ASSERT(NULL == ff->child_pending_exception);
kono
parents:
diff changeset
168 CILK_ASSERT(NULL == ff->right_pending_exception);
kono
parents:
diff changeset
169 __cilkrts_mutex_destroy(w, &ff->lock);
kono
parents:
diff changeset
170 __cilkrts_frame_free(w, ff, sizeof(*ff));
kono
parents:
diff changeset
171 }
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 COMMON_PORTABLE void validate_full_frame(full_frame *ff)
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 /* check the magic numbers, for debugging purposes */
kono
parents:
diff changeset
176 if (ff->full_frame_magic_0 != FULL_FRAME_MAGIC_0 ||
kono
parents:
diff changeset
177 ff->full_frame_magic_1 != FULL_FRAME_MAGIC_1)
kono
parents:
diff changeset
178 abort_because_rts_is_corrupted();
kono
parents:
diff changeset
179 }
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 void __cilkrts_frame_lock(__cilkrts_worker *w, full_frame *ff)
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 validate_full_frame(ff);
kono
parents:
diff changeset
184 __cilkrts_mutex_lock(w, &ff->lock);
kono
parents:
diff changeset
185 }
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 void __cilkrts_frame_unlock(__cilkrts_worker *w, full_frame *ff)
kono
parents:
diff changeset
188 {
kono
parents:
diff changeset
189 __cilkrts_mutex_unlock(w, &ff->lock);
kono
parents:
diff changeset
190 }
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 /* End full_frame.c */