1 /* metacall_impl.c -*-C-*-
2 *
3 *************************************************************************
4 *
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:
13 *
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.
23 *
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 **************************************************************************/
38
39 #include "metacall_impl.h"
40
41 NOINLINE
42 CILK_API_VOID
__cilkrts_metacall(unsigned int tool,unsigned int code,void * data)43 __cilkrts_metacall(unsigned int tool, unsigned int code, void *data)
44 {
45 #ifdef ENABLE_NOTIFY_ZC_INTRINSIC
46 // The metacall type, code and data are packed together into a single
47 // struct which will be interpreted by the tool. This function is the
48 // one and only use of a "cilkscreen_metacall" annotation
49 metacall_data_t d = { tool, code, data };
50
51 // Note that Inspector uses probe mode, and is implementing the metacall
52 // interface to force the runtime to run with a single worker. So
53 // __cilkrts_metacall must use __notify_intrinsic instead of
54 // __notify_zc_intrinsic
55 __notify_intrinsic("cilkscreen_metacall", &d);
56 #endif // ENABLE_NOTIFY_ZC_INTRINSIC
57 }
58
__cilkrts_running_under_sequential_ptool(void)59 int __cilkrts_running_under_sequential_ptool(void)
60 {
61 static int running_under_sequential_ptool = -1;
62 volatile char c = ~0;
63
64 // If we haven't been called before, see if we're running under Cilkscreen
65 // or Cilkview
66 if (-1 == running_under_sequential_ptool)
67 {
68 // metacall #2 writes 0 in C if we are running under
69 // a p-tools that requires serial execution, and is a
70 // no-op otherwise
71 //
72 // Note that removing the volatile is required to prevent the compiler
73 // from assuming that the value has not changed
74 __cilkrts_metacall(METACALL_TOOL_SYSTEM,
75 HYPER_ZERO_IF_SEQUENTIAL_PTOOL, (void *)&c);
76
77 running_under_sequential_ptool = (0 == c);
78 }
79
80 return running_under_sequential_ptool;
81 }
82
83 /*
84 * __cilkrts_cilkscreen_establish_c_stack
85 *
86 * Notify Cilkscreen of the extent of the stack
87 */
88
__cilkrts_cilkscreen_establish_c_stack(char * begin,char * end)89 void __cilkrts_cilkscreen_establish_c_stack(char *begin, char *end)
90 {
91 char *limits[2] = {begin, end};
92
93 __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_ESTABLISH_C_STACK, limits);
94 }
95
96 #ifdef WORKSPAN // Workspan stuff - remove when we're sure what we can drop
97
__cilkview_workspan_start(void)98 void __cilkview_workspan_start(void) {
99 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
100 }
101
__cilkview_workspan_stop(void)102 void __cilkview_workspan_stop(void) {
103 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
104 }
105
__cilkview_workspan_dump(const char * str)106 void __cilkview_workspan_dump(const char *str) {
107 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
108 }
109
110
__cilkview_workspan_reset(void)111 void __cilkview_workspan_reset(void) {
112 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
113 }
114
115
__cilkview_use_default_grain(void)116 void __cilkview_use_default_grain(void) {
117 __cilkrts_metacall(HYPER_USE_DEFAULT_GRAIN, 0);
118 }
119
__cilkview_get_workspan_data(unsigned long long * values,int size)120 void __cilkview_get_workspan_data(unsigned long long *values, int size)
121 {
122 void *data[2];
123
124 /* reset counters to zero in case we are not running under
125 a p-tool */
126
127 values[0] = 0;
128
129 data[0] = (void*) values;
130 data[1] = (void*) &size;
131 __cilkrts_metacall(HYPER_WORKSPAN_QUERY, &data);
132 }
133
__cilkview_workspan_connected(int * flag)134 void __cilkview_workspan_connected (int *flag) {
135 *flag = 0;
136 __cilkrts_metacall(HYPER_WORKSPAN_CONNECTED, (void *)flag);
137 }
138
__cilkview_workspan_suspend()139 void __cilkview_workspan_suspend() {
140 __cilkrts_metacall(HYPER_WORKSPAN_SUSPEND, 0);
141 }
142
__cilkview_workspan_resume()143 void __cilkview_workspan_resume() {
144 __cilkrts_metacall(HYPER_WORKSPAN_RESUME, 0);
145 }
146
147 /* depreciated interfaces */
__cilkometer_workspan_start(void)148 void __cilkometer_workspan_start(void) {
149 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
150 }
151
__cilkometer_workspan_stop(void)152 void __cilkometer_workspan_stop(void) {
153 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
154 }
155
__cilkometer_workspan_dump(const char * str)156 void __cilkometer_workspan_dump(const char *str) {
157 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
158 }
159
160
__cilkometer_workspan_reset(void)161 void __cilkometer_workspan_reset(void) {
162 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
163 }
164
165 #endif // WORKSPAN
166
167 /* End metacall_impl.c */
168