From 3cabfb6a85ac0e1665ed1593bab0a2d341682bc1 Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Mon, 12 Jul 2021 12:27:05 +0000 Subject: [PATCH] [K/N][New MM] Rare GC calls to optimize swiftinterop benchmarks --- kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp | 5 +++++ .../runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.cpp | 4 +++- .../runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.hpp | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp b/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp index 1fab6ce305a..4e4cfef2cfe 100644 --- a/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp +++ b/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp @@ -9,6 +9,7 @@ #include #include "Utils.hpp" +#include "Types.h" namespace kotlin { @@ -52,12 +53,16 @@ public: void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; } size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; } + void SetCooldownThresholdUs(uint64_t value) noexcept { cooldownThresholdUs_ = value; } + uint64_t GetCooldownThresholdUs() noexcept { return cooldownThresholdUs_; } + void SetAutoTune(bool value) noexcept { autoTune_ = value; } bool GetAutoTune() noexcept { return autoTune_; } private: size_t threshold_ = 0; size_t allocationThresholdBytes_ = 0; + uint64_t cooldownThresholdUs_ = 0; bool autoTune_ = false; }; diff --git a/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.cpp b/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.cpp index 2c4e33f04e1..fae85762638 100644 --- a/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.cpp +++ b/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.cpp @@ -102,7 +102,8 @@ void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noe size_t counterOverhead = gc_.GetThreshold() == 0 ? safePointsCounter_ : safePointsCounter_ % gc_.GetThreshold(); if (threadData_.suspensionData().suspendIfRequested()) { safePointsCounter_ = 0; - } else if (counterOverhead + weight >= gc_.GetThreshold()) { + } else if (counterOverhead + weight >= gc_.GetThreshold() && konan::getTimeMicros() - timeOfLastGcUs_ >= gc_.GetCooldownThresholdUs()) { + timeOfLastGcUs_ = konan::getTimeMicros(); safePointsCounter_ = 0; PerformFullGC(); } @@ -114,6 +115,7 @@ gc::SameThreadMarkAndSweep::SameThreadMarkAndSweep() noexcept { // TODO: Make it even more aggressive and run on a subset of backend.native tests. threshold_ = 1000; allocationThresholdBytes_ = 10000; + cooldownThresholdUs_ = 0; } } diff --git a/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.hpp b/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.hpp index 92163082779..7af6898523d 100644 --- a/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.hpp +++ b/kotlin-native/runtime/src/gc/stms/cpp/SameThreadMarkAndSweep.hpp @@ -61,6 +61,7 @@ public: mm::ThreadData& threadData_; size_t allocatedBytes_ = 0; size_t safePointsCounter_ = 0; + uint64_t timeOfLastGcUs_ = konan::getTimeMicros(); }; SameThreadMarkAndSweep() noexcept; @@ -72,6 +73,9 @@ public: void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; } size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; } + void SetCooldownThresholdUs(uint64_t value) noexcept { cooldownThresholdUs_ = value; } + uint64_t GetCooldownThresholdUs() noexcept { return cooldownThresholdUs_; } + void SetAutoTune(bool value) noexcept { autoTune_ = value; } bool GetAutoTune() noexcept { return autoTune_; } @@ -80,6 +84,7 @@ private: size_t threshold_ = 100000; // Roughly 1 safepoint per 10ms (on a subset of examples on one particular machine). size_t allocationThresholdBytes_ = 10 * 1024 * 1024; // 10MiB by default. + uint64_t cooldownThresholdUs_ = 200 * 1000; // 200 milliseconds by default. bool autoTune_ = false; };