File 3792-runtime_tools-Fix-bug-in-scheduler-utilization-Secon.patch of Package erlang
From a883b8c4ec397a15cba712283163419e0821cfdf Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Tue, 23 Nov 2021 13:20:55 +0100
Subject: [PATCH 2/3] runtime_tools: Fix bug in scheduler:utilization(Seconds)
The returned OldFlag is the old node global state. That should
not prevent us from decreasing our process local logical ref counter
for scheduler_wall_time.
---
lib/runtime_tools/src/scheduler.erl | 9 ++-------
lib/runtime_tools/test/scheduler_SUITE.erl | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/runtime_tools/src/scheduler.erl b/lib/runtime_tools/src/scheduler.erl
index c896b671ac..cc4f26111a 100644
--- a/lib/runtime_tools/src/scheduler.erl
+++ b/lib/runtime_tools/src/scheduler.erl
@@ -70,16 +70,11 @@ sample(Stats) ->
(Sample) -> sched_util_result() when
Sample :: sched_sample().
utilization(Seconds) when is_integer(Seconds), Seconds > 0 ->
- OldFlag = erlang:system_flag(scheduler_wall_time, true),
+ _ = erlang:system_flag(scheduler_wall_time, true),
T0 = sample(),
receive after Seconds*1000 -> ok end,
T1 = sample(),
- case OldFlag of
- false ->
- erlang:system_flag(scheduler_wall_time, OldFlag);
- true ->
- ok
- end,
+ _ = erlang:system_flag(scheduler_wall_time, false),
utilization(T0,T1);
utilization({Stats, _}=T0) when Stats =:= scheduler_wall_time;
diff --git a/lib/runtime_tools/test/scheduler_SUITE.erl b/lib/runtime_tools/test/scheduler_SUITE.erl
index 1c80253371..4f000c381b 100644
--- a/lib/runtime_tools/test/scheduler_SUITE.erl
+++ b/lib/runtime_tools/test/scheduler_SUITE.erl
@@ -23,9 +23,11 @@
-export([suite/0, all/0]).
%% Test cases
--export([basic/1]).
+-export([basic/1,
+ utilization_disable/1]).
-all() -> [basic].
+all() -> [basic,
+ utilization_disable].
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -56,6 +58,16 @@ basic(_Config) ->
ok.
+%% OTP-17800: Test that utilization(Seconds) restores scheduler_wall_time flag
+%% even when it already was globally enabled.
+utilization_disable(_Config) ->
+ false = erlang:system_flag(scheduler_wall_time, true),
+ check(scheduler:utilization(1)),
+ true = erlang:system_flag(scheduler_wall_time, false),
+
+ undefined = scheduler:get_sample(),
+ ok.
+
check([{total, Tf, Ts} | List]=U) ->
io:format("\nU = ~p\n", [U]),
--
2.31.1