1 /* metacall_impl.h                  -*-C++-*-
2  *
3  *************************************************************************
4  *
5  *  @copyright
6  *  Copyright (C) 2010-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 
40 /**
41  * @file metacall_impl.h
42  *
43  * @brief Meta-function calls to be used within the Cilk runtime system.
44  *
45  * These differ from the macros in cilkscreen.h and cilkview.h because they go
46  * through the __cilkrts_metacall interface, which ensures that the operation
47  * is performed even when instrumentation is disabled.
48  */
49 
50 #ifndef INCLUDED_CILKRTS_METACALL_H
51 #define INCLUDED_CILKRTS_METACALL_H
52 
53 #include "rts-common.h"
54 #include <internal/metacall.h>
55 #include <cilk/common.h>
56 
57 __CILKRTS_BEGIN_EXTERN_C
58 
59 /**
60  * This function is effectively an unconditional call from the runtime into
61  * a tool.  It is used for operations that must be performed by the tool,
62  * even when the tool is not instrumenting.  For example, Cilkscreen always
63  * recognizes the address of this function and performs the action specified
64  * in the contained metadata.
65  *
66  * Note that this function MUST NOT BE INLINED within the runtime.  This must
67  * be the ONLY instance of the cilkscreen_metacall metadata.
68  */
69 CILK_API_VOID
70 __cilkrts_metacall(unsigned int tool, unsigned int code, void *data);
71 
72 /**
73  * Return non-zero if running under Cilkscreen or Cilkview
74  */
75 COMMON_PORTABLE
76 int __cilkrts_running_under_sequential_ptool(void);
77 
78 /**
79  * Disable Cilkscreen implementation
80  */
81 #define __cilkrts_cilkscreen_disable_instrumentation() \
82     __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_DISABLE_INSTRUMENTATION, 0)
83 
84 /**
85  * Enable Cilkscreen implementation
86  */
87 #define __cilkrts_cilkscreen_enable_instrumentation() \
88     __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_ENABLE_INSTRUMENTATION, 0)
89 
90 /**
91  * Set the worker on entering runtime.
92  *
93  * @attention Deprecated in favor of __cilkrts_cilkscreen_ignore_block.  The
94  * begin/enter pairs in the current metadata mean Cilkscreen no longer has to
95  * have improper knowledge of the __cilkrts_worker or __cilkrts_stack_frame
96  * structures.
97  */
98 #define __cilkrts_cilkscreen_establish_worker(w) \
99     __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_ESTABLISH_WORKER, w)
100 
101 /**
102  * Notify Cilkscreen of the extent of the stack.
103  *
104  * @param[in] begin Start (low address) of stack
105  * @param[in] end   One past high address of stack
106  */
107 void __cilkrts_cilkscreen_establish_c_stack(char *begin, char *end);
108 
109 /**
110  * Tell tools to ignore a block of memory - currently the global state and
111  * memory allocated for workers.
112  */
113 #define __cilkrts_cilkscreen_ignore_block(_begin, _end) \
114 {                                                       \
115     void *block[2] = {_begin, _end};                    \
116     __cilkrts_metacall(METACALL_TOOL_SYSTEM,            \
117                        HYPER_IGNORE_MEMORY_BLOCK,       \
118                        block);                          \
119 }
120 
121 __CILKRTS_END_EXTERN_C
122 
123 #endif /* ! defined(INCLUDED_CILKRTS_METACALL_H) */
124