-
Notifications
You must be signed in to change notification settings - Fork 130
Implemented erlang:bump_reductions nif. #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
16474a7
ea67be3
5e050c8
9b551c3
74cc3b7
8a0b137
a739d7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1767,7 +1767,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| Module *prev_mod; | ||
| term *x_regs; | ||
| const uint8_t *pc; | ||
| int remaining_reductions; | ||
| int max_reductions; | ||
|
|
||
| Context *ctx = scheduler_run(glb); | ||
|
|
||
|
|
@@ -1780,7 +1780,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| code = mod->code->code; | ||
| x_regs = ctx->x; | ||
| pc = (ctx->saved_ip); | ||
| remaining_reductions = DEFAULT_REDUCTIONS_AMOUNT; | ||
| max_reductions = ctx->reductions + DEFAULT_REDUCTIONS_AMOUNT; | ||
|
|
||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wpedantic" | ||
|
|
@@ -1864,8 +1864,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| #ifdef IMPL_EXECUTE_LOOP | ||
| ctx->cp = module_address(mod->module_index, pc - code); | ||
|
|
||
| remaining_reductions--; | ||
| if (LIKELY(remaining_reductions)) { | ||
| ++ctx->reductions; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to slow us down as opposed to keeping the value in a local variable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Local variable from opcodesswitch is unobtainable in nif. Also every context should have its own reductions counter if we want the reductions to work exactly like the OTP version. |
||
| if (LIKELY(ctx->reductions < max_reductions)) { | ||
| TRACE_CALL(ctx, mod, "call", label, arity); | ||
| JUMP_TO_ADDRESS(mod->labels[label]); | ||
| } else { | ||
|
|
@@ -1895,8 +1895,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
|
|
||
| DEBUG_DUMP_STACK(ctx); | ||
|
|
||
| remaining_reductions--; | ||
| if (LIKELY(remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (LIKELY(ctx->reductions < max_reductions)) { | ||
| TRACE_CALL(ctx, mod, "call_last", label, arity); | ||
| JUMP_TO_ADDRESS(mod->labels[label]); | ||
| } else { | ||
|
|
@@ -1917,8 +1917,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| USED_BY_TRACE(label); | ||
|
|
||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (LIKELY(remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (LIKELY(ctx->reductions < max_reductions)) { | ||
| TRACE_CALL(ctx, mod, "call_only", label, arity); | ||
| JUMP_TO_ADDRESS(mod->labels[label]); | ||
| } else { | ||
|
|
@@ -1933,8 +1933,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| // save pc in case of error | ||
| const uint8_t *orig_pc = pc - 1; | ||
|
|
||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, orig_pc); | ||
| } | ||
| #endif | ||
|
|
@@ -2041,8 +2041,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| // save pc in case of error | ||
| const uint8_t *orig_pc = pc - 1; | ||
|
|
||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, orig_pc); | ||
| } | ||
| #endif | ||
|
|
@@ -3240,8 +3240,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| USED_BY_TRACE(label); | ||
|
|
||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (LIKELY(remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (LIKELY(ctx->reductions < max_reductions)) { | ||
| JUMP_TO_ADDRESS(mod->labels[label]); | ||
| } else { | ||
| SCHEDULE_NEXT(mod, mod->labels[label]); | ||
|
|
@@ -3475,8 +3475,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
|
|
||
| case OP_CALL_FUN: { | ||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, pc - 1); | ||
| } | ||
| #endif | ||
|
|
@@ -3531,8 +3531,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
|
|
||
| case OP_CALL_EXT_ONLY: { | ||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, pc - 1); | ||
| } | ||
| #endif | ||
|
|
@@ -5228,8 +5228,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
| // save pc in case of error | ||
| const uint8_t *orig_pc = pc - 1; | ||
|
|
||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, orig_pc); | ||
| } | ||
| #endif | ||
|
|
@@ -5281,8 +5281,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
|
|
||
| case OP_APPLY_LAST: { | ||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, pc - 1); | ||
| } | ||
| #endif | ||
|
|
@@ -6788,8 +6788,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) | |
|
|
||
| case OP_CALL_FUN2: { | ||
| #ifdef IMPL_EXECUTE_LOOP | ||
| remaining_reductions--; | ||
| if (UNLIKELY(!remaining_reductions)) { | ||
| ++ctx->reductions; | ||
| if (UNLIKELY(ctx->reductions >= max_reductions)) { | ||
| SCHEDULE_NEXT(mod, pc - 1); | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| % | ||
| % This file is part of AtomVM. | ||
| % | ||
| % Copyright 2025 Franciszek Kubis <[email protected]> | ||
| % | ||
| % Licensed under the Apache License, Version 2.0 (the "License"); | ||
| % you may not use this file except in compliance with the License. | ||
| % You may obtain a copy of the License at | ||
| % | ||
| % http://www.apache.org/licenses/LICENSE-2.0 | ||
| % | ||
| % Unless required by applicable law or agreed to in writing, software | ||
| % distributed under the License is distributed on an "AS IS" BASIS, | ||
| % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| % See the License for the specific language governing permissions and | ||
| % limitations under the License. | ||
| % | ||
| % SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
| % | ||
|
|
||
| -module(test_bump_reductions). | ||
|
|
||
| -export([start/0, process_test/0]). | ||
|
|
||
| start() -> | ||
| {reductions, InitialReductions0} = erlang:process_info(self(), reductions), | ||
| erlang:bump_reductions(1), | ||
| InitialReductions1 = InitialReductions0 + 2, | ||
| {reductions, InitialReductions1} = erlang:process_info(self(), reductions), | ||
| Pid = erlang:spawn_opt(fun() -> process_test() end, [link]), | ||
| Pid ! {ready, self()}, | ||
| ReceivedReductions = | ||
| receive | ||
| {r1, {reductions, Reductions}} -> Reductions | ||
| end, | ||
|
|
||
| receive | ||
| {r2, {reductions, Reductions2}} -> | ||
| Reductions2 = ReceivedReductions + 1027 | ||
| end, | ||
| erlang:bump_reductions(2000), | ||
| FinalReductions = InitialReductions1 + 2003, | ||
| {reductions, FinalReductions} = erlang:process_info(self(), reductions), | ||
| 0. | ||
|
|
||
| process_test() -> | ||
| receive | ||
| {ready, Pid} -> | ||
| Pid ! {r1, erlang:process_info(self(), reductions)}, | ||
| erlang:bump_reductions(1025), | ||
| Pid ! {r2, erlang:process_info(self(), reductions)} | ||
| end. |
Uh oh!
There was an error while loading. Please reload this page.