Skip to content

Commit

Permalink
hipe_unified_loader: only block SMP scheduling when necessary
Browse files Browse the repository at this point in the history
This avoids costly scheduling changes during module loading if native
code is disabled in erts, or not present in the module being loaded.

Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
  • Loading branch information
Mikael Pettersson authored and bjorng committed Feb 9, 2010
1 parent 51bb4c6 commit 4a158f3
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions lib/kernel/src/hipe_unified_loader.erl
Expand Up @@ -96,25 +96,22 @@ load_hipe_modules() ->
%% code:load_file/1) and the atom `no_native' on failure.

load_native_code(Mod, Bin) when is_atom(Mod), is_binary(Bin) ->
erlang:system_flag(multi_scheduling, block),
try
load_native_code_nosmp(Mod, Bin)
after
erlang:system_flag(multi_scheduling, unblock)
end.

load_native_code_nosmp(Mod, Bin) ->
Architecture = erlang:system_info(hipe_architecture),
try chunk_name(Architecture) of
ChunkTag ->
%% patch_to_emu(Mod),
case code:get_chunk(Bin, ChunkTag) of
undefined -> no_native;
NativeCode when is_binary(NativeCode) ->
OldReferencesToPatch = patch_to_emu_step1(Mod),
case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of
bad_crc -> no_native;
Result -> Result
erlang:system_flag(multi_scheduling, block),
try
OldReferencesToPatch = patch_to_emu_step1(Mod),
case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of
bad_crc -> no_native;
Result -> Result
end
after
erlang:system_flag(multi_scheduling, unblock)
end
end
catch
Expand All @@ -128,17 +125,18 @@ load_native_code_nosmp(Mod, Bin) ->
-spec post_beam_load(atom()) -> 'ok'.

post_beam_load(Mod) when is_atom(Mod) ->
erlang:system_flag(multi_scheduling, block),
try
post_beam_load_nosmp(Mod)
after
erlang:system_flag(multi_scheduling, unblock)
end.

post_beam_load_nosmp(Mod) ->
Architecture = erlang:system_info(hipe_architecture),
try chunk_name(Architecture) of _ChunkTag -> patch_to_emu(Mod)
catch _:_ -> ok
try chunk_name(Architecture) of
_ChunkTag ->
erlang:system_flag(multi_scheduling, block),
try
patch_to_emu(Mod)
after
erlang:system_flag(multi_scheduling, unblock)
end
catch
_:_ ->
ok
end.

%%========================================================================
Expand Down

0 comments on commit 4a158f3

Please sign in to comment.