From 9e82453c2d5e075ee2eed8330f5b710e4a7a6df7 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 14 Feb 2025 14:20:21 +0100 Subject: cool#11064 vcl lok: expose info about the scheduler A LOK client can interrupt the vcl main loop in its 'any input' callback. When making that decision, it's useful in case it can know what's the priority of the most urgent job, for example it may want core to still finish high priority tasks, but not idle ones. Add a LOK API to expose this info. Keep it minimal, so it's realistic to call this frequently from a LOK client. Change-Id: Id51668eb8156067e60d6fd0f33606c65858008a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181761 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- vcl/source/app/scheduler.cxx | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'vcl') diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx index 6234e6355117..eb3acf65c8a4 100644 --- a/vcl/source/app/scheduler.cxx +++ b/vcl/source/app/scheduler.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #include namespace { @@ -301,6 +302,49 @@ Scheduler::IdlesLockGuard::~IdlesLockGuard() osl_atomic_decrement(&rSchedCtx.mnIdlesLockCount); } +void Scheduler::dumpAsJSON(tools::JsonWriter& rJsonWriter) +{ + // Similar to Scheduler::CallbackTaskScheduling(), figure out the most urgent priority, but + // don't actually invoke any task. + int nMostUrgentPriority = -1; + ImplSVData* pSVData = ImplGetSVData(); + ImplSchedulerContext& rSchedCtx = pSVData->maSchedCtx; + if (!rSchedCtx.mbActive || rSchedCtx.mnTimerPeriod == InfiniteTimeoutMs) + { + rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority); + return; + } + + sal_uInt64 nTime = tools::Time::GetSystemTicks(); + if (nTime < rSchedCtx.mnTimerStart + rSchedCtx.mnTimerPeriod - 1) + { + rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority); + return; + } + + for (int nTaskPriority = 0; nTaskPriority < PRIO_COUNT; ++nTaskPriority) + { + ImplSchedulerData* pSchedulerData = rSchedCtx.mpFirstSchedulerData[nTaskPriority]; + while (pSchedulerData) + { + Task* pTask = pSchedulerData->mpTask; + if (pTask && pTask->IsActive()) + { + // Const, doesn't modify the task. + sal_uInt64 nReadyPeriod = pTask->UpdateMinPeriod(nTime); + if (nReadyPeriod == ImmediateTimeoutMs) + { + nMostUrgentPriority = nTaskPriority; + rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority); + return; + } + } + pSchedulerData = pSchedulerData->mpNext; + } + } + rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority); +} + inline void Scheduler::UpdateSystemTimer( ImplSchedulerContext &rSchedCtx, const sal_uInt64 nMinPeriod, const bool bForce, const sal_uInt64 nTime ) -- cgit