From ba16304298c1ece1600a63193f29d6e00946ea82 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Fri, 13 Nov 2020 22:10:18 +0000 Subject: [PATCH] Bug 1676984 - Make IdleScheduler to use CollectProcessInfo to access cpucount, r=emalysz Differential Revision: https://phabricator.services.mozilla.com/D96947 --- ipc/glue/IdleSchedulerParent.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ipc/glue/IdleSchedulerParent.cpp b/ipc/glue/IdleSchedulerParent.cpp index 4202c02b20bc..6748164d6917 100644 --- a/ipc/glue/IdleSchedulerParent.cpp +++ b/ipc/glue/IdleSchedulerParent.cpp @@ -8,7 +8,6 @@ #include "mozilla/StaticPrefs_page_load.h" #include "mozilla/Unused.h" #include "mozilla/ipc/IdleSchedulerParent.h" -#include "nsIPropertyBag2.h" #include "nsSystemInfo.h" #include "nsThreadUtils.h" #include "nsITimer.h" @@ -42,16 +41,10 @@ IdleSchedulerParent::IdleSchedulerParent() { // Always pretend that there is at least one core for child processes. // If there are multiple logical cores, reserve one for the parent // process and for the non-main threads. - nsCOMPtr infoService = - do_GetService(NS_SYSTEMINFO_CONTRACTID); - if (infoService) { - int32_t cpus; - nsresult rv = - infoService->GetPropertyAsInt32(u"cpucount"_ns, &cpus); - if (NS_SUCCEEDED(rv) && cpus > 1) { - sCPUsForChildProcesses = cpus - 1; - } - + ProcessInfo processInfo = {}; + if (NS_SUCCEEDED(CollectProcessInfo(processInfo)) && + processInfo.cpuCount > 1) { + sCPUsForChildProcesses = processInfo.cpuCount - 1; // We have a new cpu count, reschedule idle scheduler. nsCOMPtr runnable = NS_NewRunnableFunction("IdleSchedulerParent::Schedule", []() { @@ -65,7 +58,7 @@ IdleSchedulerParent::IdleSchedulerParent() { thread->Dispatch(runnable, NS_DISPATCH_NORMAL); } }); - NS_DispatchToMainThread(runnable); + NS_DispatchBackgroundTask(runnable.forget(), NS_DISPATCH_EVENT_MAY_BLOCK); } }