1
/* ``The contents of this file are subject to the Erlang Public License,
4
* Copyright Ericsson AB 1996-2009. All Rights Reserved.
6
* The contents of this file are subject to the Erlang Public License,
2
7
* Version 1.1, (the "License"); you may not use this file except in
3
8
* compliance with the License. You should have received a copy of the
4
9
* Erlang Public License along with this software. If not, it can be
5
* retrieved via the world wide web at http://www.erlang.org/.
10
* retrieved online at http://www.erlang.org/.
7
12
* Software distributed under the License is distributed on an "AS IS"
8
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
14
* the License for the specific language governing rights and limitations
10
15
* under the License.
12
* The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
* Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
* AB. All Rights Reserved.''
23
extern Export* erts_format_cpu_topology_trap;
21
25
#define BIF_RETTYPE Eterm
32
36
#define BIF_ARG_3 A_3
34
38
#define BUMP_ALL_REDS(p) do { \
35
if ((p)->ct == NULL) \
39
if (!ERTS_PROC_GET_SAVED_CALLS_BUF((p))) \
38
42
(p)->fcalls = -CONTEXT_REDS; \
46
#define ERTS_VBUMP_ALL_REDS(p) \
48
if (!ERTS_PROC_GET_SAVED_CALLS_BUF((p))) { \
49
if ((p)->fcalls > 0) \
50
ERTS_PROC_GET_SCHDATA((p))->virtual_reds += (p)->fcalls; \
54
if ((p)->fcalls > -CONTEXT_REDS) \
55
ERTS_PROC_GET_SCHDATA((p))->virtual_reds \
56
+= ((p)->fcalls - (-CONTEXT_REDS)); \
57
(p)->fcalls = -CONTEXT_REDS; \
41
61
#define BUMP_REDS(p, gc) do { \
42
62
(p)->fcalls -= (gc); \
43
63
if ((p)->fcalls < 0) { \
44
if ((p)->ct == NULL) \
64
if (!ERTS_PROC_GET_SAVED_CALLS_BUF((p))) \
46
66
else if ((p)->fcalls < -CONTEXT_REDS) \
47
67
(p)->fcalls = -CONTEXT_REDS; \
72
#define ERTS_VBUMP_REDS(p, reds) \
74
if (!ERTS_PROC_GET_SAVED_CALLS_BUF((p))) { \
75
if ((p)->fcalls >= reds) { \
76
(p)->fcalls -= reds; \
77
ERTS_PROC_GET_SCHDATA((p))->virtual_reds += reds; \
80
if ((p)->fcalls > 0) \
81
ERTS_PROC_GET_SCHDATA((p))->virtual_reds += (p)->fcalls;\
86
if ((p)->fcalls >= reds - CONTEXT_REDS) { \
87
(p)->fcalls -= reds; \
88
ERTS_PROC_GET_SCHDATA((p))->virtual_reds += reds; \
91
if ((p)->fcalls > -CONTEXT_REDS) \
92
ERTS_PROC_GET_SCHDATA((p))->virtual_reds \
93
+= (p)->fcalls - (-CONTEXT_REDS); \
94
(p)->fcalls = -CONTEXT_REDS; \
51
99
#define ERTS_BIF_REDS_LEFT(p) \
100
(ERTS_PROC_GET_SAVED_CALLS_BUF((p)) \
53
101
? ((p)->fcalls > -CONTEXT_REDS ? ((p)->fcalls - (-CONTEXT_REDS)) : 0)\
54
102
: ((p)->fcalls > 0 ? (p)->fcalls : 0))
146
194
return THE_NON_VALUE; \
149
#define ERTS_BIF_YIELD_BUMP_REDS__(P) \
150
ERTS_GET_SCHEDULER_DATA_FROM_PROC((P))->yield_reduction_bump \
151
= ERTS_BIF_REDS_LEFT((P)); \
197
extern Export bif_return_trap_export;
199
#define ERTS_BIF_YIELD_RETURN(P, VAL, DEBUG_VAL) \
201
ERTS_VBUMP_ALL_REDS(P); \
202
BIF_TRAP2(&bif_return_trap_export, (P), (VAL), (DEBUG_VAL)); \
205
#define ERTS_BIF_YIELD_RETURN(P, VAL, DEBUG_VAL) \
207
ERTS_VBUMP_ALL_REDS(P); \
208
BIF_TRAP1(&bif_return_trap_export, (P), (VAL)); \
154
213
#define ERTS_BIF_PREP_YIELD0(RET, TRP, P) \
156
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
215
ERTS_VBUMP_ALL_REDS((P)); \
157
216
ERTS_BIF_PREP_TRAP0(RET, (TRP), (P)); \
160
219
#define ERTS_BIF_PREP_YIELD1(RET, TRP, P, A0) \
162
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
221
ERTS_VBUMP_ALL_REDS((P)); \
163
222
ERTS_BIF_PREP_TRAP1(RET, (TRP), (P), (A0)); \
166
225
#define ERTS_BIF_PREP_YIELD2(RET, TRP, P, A0, A1) \
168
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
227
ERTS_VBUMP_ALL_REDS((P)); \
169
228
ERTS_BIF_PREP_TRAP2(RET, (TRP), (P), (A0), (A1)); \
172
231
#define ERTS_BIF_PREP_YIELD3(RET, TRP, P, A0, A1, A2) \
174
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
233
ERTS_VBUMP_ALL_REDS((P)); \
175
234
ERTS_BIF_PREP_TRAP3(RET, (TRP), (P), (A0), (A1), (A2)); \
178
237
#define ERTS_BIF_YIELD0(TRP, P) \
180
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
239
ERTS_VBUMP_ALL_REDS((P)); \
181
240
BIF_TRAP0((TRP), (P)); \
184
243
#define ERTS_BIF_YIELD1(TRP, P, A0) \
186
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
245
ERTS_VBUMP_ALL_REDS((P)); \
187
246
BIF_TRAP1((TRP), (P), (A0)); \
190
249
#define ERTS_BIF_YIELD2(TRP, P, A0, A1) \
192
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
251
ERTS_VBUMP_ALL_REDS((P)); \
193
252
BIF_TRAP2((TRP), (P), (A0), (A1)); \
196
255
#define ERTS_BIF_YIELD3(TRP, P, A0, A1, A2) \
198
ERTS_BIF_YIELD_BUMP_REDS__((P)); \
257
ERTS_VBUMP_ALL_REDS((P)); \
199
258
BIF_TRAP3((TRP), (P), (A0), (A1), (A2)); \