File 0896-erts-Fix-statistics_SUITE-wall_time-testcase-when-on.patch of Package erlang

From f8668b10133d71cc097a478d07be529c8f42a204 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Fri, 5 Jun 2020 10:12:59 +0200
Subject: [PATCH 12/18] erts: Fix statistics_SUITE wall_time testcase when onl
 < avail

When running tests using docker cpu limiting the number
of online schedulers is reduced. So we need to take that
into consideration when running tests.
---
 erts/emulator/test/statistics_SUITE.erl | 44 +++++++++++++++++++------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/erts/emulator/test/statistics_SUITE.erl b/erts/emulator/test/statistics_SUITE.erl
index 81505902c3..65a675e8d2 100644
--- a/erts/emulator/test/statistics_SUITE.erl
+++ b/erts/emulator/test/statistics_SUITE.erl
@@ -340,7 +340,7 @@ run_scheduler_wall_time_test(Type) ->
                                 scheduler_wall_time ->
                                     Schedulers + DirtyCPUSchedulers
                         end,
-                            
+
         %% Let testserver and everyone else finish their work
         timer:sleep(1500),
         %% Empty load
@@ -377,18 +377,23 @@ run_scheduler_wall_time_test(Type) ->
         HalfDirtyIOHogs = [StartDirtyHog(dirty_io)
                            || _ <- lists:seq(1, lists:max([1,DirtyIOSchedulers div 2]))],
         HalfLoad = lists:sum(get_load(Type)) div TotLoadSchedulers,
-        if Schedulers < 2, HalfLoad > 80 -> ok; %% Ok only one scheduler online and one hog
+        if Schedulers =:= 1, HalfLoad > 80 -> ok; %% Ok only one scheduler online and one hog
            %% We want roughly 50% load
            HalfLoad > 40, HalfLoad < 60 -> ok;
            true -> exit({halfload, HalfLoad})
         end,
 
-        %% 100% load
-        LastHogs = [StartHog() || _ <- lists:seq(1, Schedulers div 2)],
+        %% 100% load. Need to take into consideration an odd number of
+        %% schedulers and also special consideration for when there is
+        %% only 1 scheduler
+        LastHogs = [StartHog() || _ <- lists:seq(1, (Schedulers+1) div 2),
+                                  Schedulers =/= 1],
         LastDirtyCPUHogs = [StartDirtyHog(dirty_cpu)
-                            || _ <- lists:seq(1, DirtyCPUSchedulers div 2)],
+                            || _ <- lists:seq(1, (DirtyCPUSchedulers+1) div 2),
+                                   DirtyCPUSchedulers =/= 1],
         LastDirtyIOHogs = [StartDirtyHog(dirty_io)
-                           || _ <- lists:seq(1, DirtyIOSchedulers div 2)],
+                           || _ <- lists:seq(1, (DirtyIOSchedulers+1) div 2),
+                                   DirtyIOSchedulers =/= 1],
         FullScheds = get_load(Type),
         {false,_} = {lists:any(fun(Load) -> Load < 80 end, FullScheds),FullScheds},
         FullLoad = lists:sum(FullScheds) div TotLoadSchedulers,
@@ -420,7 +425,26 @@ get_load(Type) ->
     Start = erlang:statistics(Type),
     timer:sleep(1500),
     End = erlang:statistics(Type),
-    lists:reverse(lists:sort(load_percentage(lists:sort(Start),lists:sort(End)))).
+
+    lists:reverse(
+      lists:sort(load_percentage(online_statistics(Start),online_statistics(End)))).
+
+%% We are only interested in schedulers that are online to remove all
+%% offline normal and dirty cpu schedulers (dirty io cannot be offline)
+online_statistics(Stats) ->
+    Schedulers = erlang:system_info(schedulers),
+    SchedulersOnline = erlang:system_info(schedulers_online),
+    DirtyCPUSchedulers = erlang:system_info(dirty_cpu_schedulers),
+    DirtyCPUSchedulersOnline = erlang:system_info(dirty_cpu_schedulers_online),
+    DirtyIOSchedulersOnline = erlang:system_info(dirty_io_schedulers),
+    SortedStats = lists:sort(Stats),
+    SchedulersStats =
+        lists:sublist(SortedStats, 1, SchedulersOnline),
+    DirtyCPUSchedulersStats =
+        lists:sublist(SortedStats, Schedulers+1, DirtyCPUSchedulersOnline),
+    DirtyIOSchedulersStats =
+        lists:sublist(SortedStats, Schedulers + DirtyCPUSchedulers+1, DirtyIOSchedulersOnline),
+    SchedulersStats ++ DirtyCPUSchedulersStats ++ DirtyIOSchedulersStats.
 
 load_percentage([{Id, WN, TN}|Ss], [{Id, WP, TP}|Ps]) ->
     [100*(WN-WP) div (TN-TP)|load_percentage(Ss, Ps)];
@@ -693,9 +717,9 @@ msacc_test(TmpFile) ->
     %% Check some IO
     {ok, L} = gen_tcp:listen(0, [{active, true},{reuseaddr,true}]),
     {ok, Port} = inet:port(L),
-    Pid = spawn(fun() ->
-                        {ok, S} = gen_tcp:accept(L),
-                        (fun F() -> receive M -> F() end end)()
+    _Pid = spawn(fun() ->
+                         {ok, _S} = gen_tcp:accept(L),
+                         (fun F() -> receive _M -> F() end end)()
                 end),
     {ok, C} = gen_tcp:connect("localhost", Port, []),
     [begin gen_tcp:send(C,"hello"),timer:sleep(1) end || _ <- lists:seq(1,100)],
-- 
2.26.2

openSUSE Build Service is sponsored by