From 301d1a57bc4a14a13f868fb4659f96708d032ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20G=C3=B6thel?= Date: Mon, 18 Nov 2024 08:23:48 +0100 Subject: [PATCH] Apply TaskPriority to KitSocketPoll::kitPoll, help to determine idle-ness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enhancement of [#10183](https://github.com/CollaboraOnline/online/pull/10183) require the [LO TaskPriority patch](https://gerrit.libreoffice.org/c/core/+/176701). Signed-off-by: Sven Göthel Change-Id: I4ee18667cfcab62a4988ca9b0dd11d0fa8d46d19 --- kit/Kit.cpp | 17 ++++++++++------- kit/Kit.hpp | 2 +- test/UnitSyntheticLok.cpp | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 1190d1523140..ba09d7547952 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -2794,7 +2794,7 @@ void KitSocketPoll::wakeupHook() { _pollEnd = std::chrono::steady_clock::now(); // a LOK compatible poll function merging the functions. // returns the number of events signalled -int KitSocketPoll::kitPoll(int timeoutMicroS) +int KitSocketPoll::kitPoll(int timeoutMicroS, int taskPriority) { ProfileZone profileZone("KitSocketPoll::kitPoll"); @@ -2851,8 +2851,11 @@ int KitSocketPoll::kitPoll(int timeoutMicroS) } else { - const bool loIdleDefault = timeoutMicroS==0; // LO-Idle Timer (check) - const bool loIdleLong = timeoutMicroS > 2500000; // LO-IdleHandler's SC_IDLE_MAX = 3s, allowing a 500ms lag + // taskPriority: 100==TaskPriority::DEFAULT, 110==TaskPriority::DEFAULT_IDLE + const bool loIdleDefault = (taskPriority > 100 && taskPriority <= 110) || + (taskPriority == 100 && timeoutMicroS == 0); + const bool loIdleLong = taskPriority > 110 || + (taskPriority == 100 && timeoutMicroS > 2500000); // LO-IdleHandler's SC_IDLE_MAX = 3s, allowing a 500ms lag if (checkForIdle) timeoutMicroS = 0; @@ -2889,7 +2892,7 @@ int KitSocketPoll::kitPoll(int timeoutMicroS) timeoutMicroS = std::chrono::duration_cast(_pollEnd - now).count(); LOG_TRC( "Poll #" << slice << "/" << eventsSignalled << "/" << maxExtraEvents - << " idle[" << isIdle << ", lo[def " << loIdleDefault << ", long " << loIdleLong << "]], qp " << quickPoll + << " idle[" << isIdle << ", lo[prio " << taskPriority << ", def " << loIdleDefault << ", long " << loIdleLong << "]], qp " << quickPoll << ", to[" << timeoutMicroSPre/1000 << "ms, " << realTimeout/1000 << "ms]: rc " << rc << ", t# " << tilesInQueue - getTileQueueSize() << "/" << tilesInQueue << ", dqc " << drainedQueueCalls << ", used " << std::chrono::duration_cast(now - startTime).count() @@ -2974,7 +2977,7 @@ void documentViewCallback(const int type, const char* payload, void* data) } /// Called by LOK main-loop the central location for data processing. -int pollCallback(void* pData, int timeoutUs) +int pollCallback(void* pData, int timeoutUs, int taskPriority) { if (timeoutUs < 0) timeoutUs = SocketPoll::DefaultPollTimeoutMicroS.count(); @@ -2982,7 +2985,7 @@ int pollCallback(void* pData, int timeoutUs) if (!pData) return 0; else - return reinterpret_cast(pData)->kitPoll(timeoutUs); + return reinterpret_cast(pData)->kitPoll(timeoutUs, taskPriority); #else std::unique_lock lock(KitSocketPoll::KSPollsMutex); std::vector> v; @@ -3003,7 +3006,7 @@ int pollCallback(void* pData, int timeoutUs) { lock.unlock(); for (const auto &p : v) - p->kitPoll(timeoutUs); + p->kitPoll(timeoutUs, taskPriority); } // We never want to exit the main loop diff --git a/kit/Kit.hpp b/kit/Kit.hpp index ba4fc25e2e6e..dca6961c3e19 100644 --- a/kit/Kit.hpp +++ b/kit/Kit.hpp @@ -167,7 +167,7 @@ class KitSocketPoll final : public SocketPoll ~ReEntrancyGuard() { _count--; } }; #endif - int kitPoll(int timeoutMicroS); + int kitPoll(int timeoutMicroS, int taskPriority); void setDocument(std::shared_ptr document) { _document = std::move(document); } std::shared_ptr getDocument() const { return _document; } diff --git a/test/UnitSyntheticLok.cpp b/test/UnitSyntheticLok.cpp index 5c1bca1373d0..886633b9960a 100644 --- a/test/UnitSyntheticLok.cpp +++ b/test/UnitSyntheticLok.cpp @@ -163,14 +163,14 @@ class UnitKitSyntheticLok : public UnitKit extern "C" { - int syn_pollCallback(void* /* pData */, int timeoutUs) + int syn_pollCallback(void* /* pData */, int timeoutUs, int taskPriority) { assert(GlobalUnitKit); bool finished = UnitKit::get().isFinished(); if (!finished && timeoutUs > 1000) // post initial setup we hope GlobalUnitKit->doTest(); if (GlobalUnitKit->prePollCallback(timeoutUs)) - return GlobalUnitKit->_pollCallback(GlobalUnitKit->_pollData, timeoutUs); + return GlobalUnitKit->_pollCallback(GlobalUnitKit->_pollData, timeoutUs, taskPriority); return 0; }