aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorRickard Green <[email protected]>2017-04-11 18:05:52 +0200
committerRickard Green <[email protected]>2017-04-11 18:05:52 +0200
commit16634948ce01359c58a4f92234e915864d40d2a8 (patch)
treedf9a97d878456cd7e23aa84c9433c16a1b55f58d /erts/emulator
parentd37bcb84be7c16dcb1c8637c1c3777a6d02932e7 (diff)
parenta6ccff7ba9659cfac6d94f49b2aa39faf13e7e7d (diff)
downloadotp-16634948ce01359c58a4f92234e915864d40d2a8.tar.gz
otp-16634948ce01359c58a4f92234e915864d40d2a8.tar.bz2
otp-16634948ce01359c58a4f92234e915864d40d2a8.zip
Merge branch 'rickard/test-fix'
* rickard/test-fix: Fix scheduler_SUITE:update_cpu_info test-case
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/test/scheduler_SUITE.erl78
1 files changed, 62 insertions, 16 deletions
diff --git a/erts/emulator/test/scheduler_SUITE.erl b/erts/emulator/test/scheduler_SUITE.erl
index b178dede5b..885298ce34 100644
--- a/erts/emulator/test/scheduler_SUITE.erl
+++ b/erts/emulator/test/scheduler_SUITE.erl
@@ -807,21 +807,31 @@ update_cpu_info(Config) when is_list(Config) ->
%% Nothing much to test; just a smoke test
ok;
Onln0 ->
- %% unset least significant bit
- Aff = (OldAff band (OldAff - 1)),
- set_affinity_mask(Aff),
- Onln1 = Avail - 1,
- case adjust_schedulers_online() of
- {Onln0, Onln1} ->
- Onln1 = erlang:system_info(schedulers_online),
- receive after 500 -> ok end,
- io:format("TEST - Affinity mask: ~p - Schedulers online: ~p - Scheduler bindings: ~p~n",
- [Aff, Onln1, erlang:system_info(scheduler_bindings)]),
- unchanged = adjust_schedulers_online(),
- ok;
- Fail ->
- ct:fail(Fail)
- end
+ Cpus = bits_in_mask(OldAff),
+ RmCpus = case Cpus > Onln0 of
+ true -> Cpus - Onln0 + 1;
+ false -> Onln0 - Cpus + 1
+ end,
+ Onln1 = Cpus - RmCpus,
+ case Onln1 > 0 of
+ false ->
+ %% Nothing much to test; just a smoke test
+ ok;
+ true ->
+ Aff = restrict_affinity_mask(OldAff, RmCpus),
+ set_affinity_mask(Aff),
+ case adjust_schedulers_online() of
+ {Onln0, Onln1} ->
+ Onln1 = erlang:system_info(schedulers_online),
+ receive after 500 -> ok end,
+ io:format("TEST - Affinity mask: ~p - Schedulers online: ~p - Scheduler bindings: ~p~n",
+ [Aff, Onln1, erlang:system_info(scheduler_bindings)]),
+ unchanged = adjust_schedulers_online(),
+ ok;
+ Fail ->
+ ct:fail(Fail)
+ end
+ end
end
after
set_affinity_mask(OldAff),
@@ -835,13 +845,49 @@ update_cpu_info(Config) when is_list(Config) ->
end
end.
+bits_in_mask(Mask) ->
+ bits_in_mask(Mask, 0, 0).
+
+bits_in_mask(0, Shift, N) ->
+ N;
+bits_in_mask(Mask, Shift, N) ->
+ case Mask band (1 bsl Shift) of
+ 0 -> bits_in_mask(Mask, Shift+1, N);
+ _ -> bits_in_mask(Mask band (bnot (1 bsl Shift)),
+ Shift+1, N+1)
+ end.
+
+restrict_affinity_mask(Mask, N) ->
+ try
+ restrict_affinity_mask(Mask, 0, N)
+ catch
+ throw : Reason ->
+ exit({Reason, Mask, N})
+ end.
+
+restrict_affinity_mask(Mask, _Shift, 0) ->
+ Mask;
+restrict_affinity_mask(0, _Shift, _N) ->
+ throw(overresticted_affinity_mask);
+restrict_affinity_mask(Mask, Shift, N) ->
+ case Mask band (1 bsl Shift) of
+ 0 -> restrict_affinity_mask(Mask, Shift+1, N);
+ _ -> restrict_affinity_mask(Mask band (bnot (1 bsl Shift)),
+ Shift+1, N-1)
+ end.
+
adjust_schedulers_online() ->
case erlang:system_info(update_cpu_info) of
unchanged ->
unchanged;
changed ->
Avail = erlang:system_info(logical_processors_available),
- {erlang:system_flag(schedulers_online, Avail), Avail}
+ Scheds = erlang:system_info(schedulers),
+ SOnln = case Avail > Scheds of
+ true -> Scheds;
+ false -> Avail
+ end,
+ {erlang:system_flag(schedulers_online, SOnln), SOnln}
end.
read_affinity(Data) ->