Skip to content

Commit

Permalink
Apply TaskPriority to KitSocketPoll::kitPoll, help to determine idle-…
Browse files Browse the repository at this point in the history
…ness

This enhancement of [#10183](#10183)
require the [LO TaskPriority patch](https://gerrit.libreoffice.org/c/core/+/176701).

Signed-off-by: Sven Göthel <sven.gothel@collabora.com>
Change-Id: I4ee18667cfcab62a4988ca9b0dd11d0fa8d46d19
  • Loading branch information
Sven Göthel committed Nov 18, 2024
1 parent 3f94473 commit 301d1a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -2889,7 +2892,7 @@ int KitSocketPoll::kitPoll(int timeoutMicroS)
timeoutMicroS = std::chrono::duration_cast<std::chrono::microseconds>(_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<std::chrono::milliseconds>(now - startTime).count()
Expand Down Expand Up @@ -2974,15 +2977,15 @@ 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();
#ifndef IOS
if (!pData)
return 0;
else
return reinterpret_cast<KitSocketPoll*>(pData)->kitPoll(timeoutUs);
return reinterpret_cast<KitSocketPoll*>(pData)->kitPoll(timeoutUs, taskPriority);
#else
std::unique_lock<std::mutex> lock(KitSocketPoll::KSPollsMutex);
std::vector<std::shared_ptr<KitSocketPoll>> v;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kit/Kit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) { _document = std::move(document); }
std::shared_ptr<Document> getDocument() const { return _document; }

Expand Down
4 changes: 2 additions & 2 deletions test/UnitSyntheticLok.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 301d1a5

Please sign in to comment.