mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-07-03 12:29:46 +00:00
#463: rework idle callbacks to use max timeout; try to fix stalls; pref off by default for FPR9
This commit is contained in:
parent
05241abca1
commit
12cdb0cd25
|
@ -264,8 +264,8 @@ class nsIScriptTimeoutHandler;
|
||||||
// which also uses Mach factor analysis to determine load, because most
|
// which also uses Mach factor analysis to determine load, because most
|
||||||
// calls will have a max timeout and thus the function is likely to run at
|
// calls will have a max timeout and thus the function is likely to run at
|
||||||
// *some* point.
|
// *some* point.
|
||||||
static const int32_t MACH_FACTOR_MIN = 700;
|
static const int32_t MACH_FACTOR_MIN = 900;
|
||||||
static const int32_t MACH_CHECK_INTERVAL = 2000;
|
static const int32_t MACH_CHECK_INTERVAL = 1000;
|
||||||
// This number is actually in the W3C standard, but we allow it to be
|
// This number is actually in the W3C standard, but we allow it to be
|
||||||
// adjusted.
|
// adjusted.
|
||||||
static const int32_t CALLBACK_IDLE_INTERVAL = 50;
|
static const int32_t CALLBACK_IDLE_INTERVAL = 50;
|
||||||
|
@ -275,7 +275,10 @@ static int32_t sIdleCallbackIdleInterval = CALLBACK_IDLE_INTERVAL;
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <mach/mach_error.h>
|
#include <mach/mach_error.h>
|
||||||
#include <mach/bootstrap.h>
|
#include <mach/bootstrap.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
static processor_set_name_port_t sMachDefaultPset;
|
static processor_set_name_port_t sMachDefaultPset;
|
||||||
|
static uint32_t sNumCPUs;
|
||||||
static struct processor_set_load_info sMachLoadInfo;
|
static struct processor_set_load_info sMachLoadInfo;
|
||||||
static host_name_port_t sMachHost;
|
static host_name_port_t sMachHost;
|
||||||
|
|
||||||
|
@ -1245,10 +1248,18 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
|
||||||
CALLBACK_IDLE_INTERVAL);
|
CALLBACK_IDLE_INTERVAL);
|
||||||
sMachHost = mach_host_self();
|
sMachHost = mach_host_self();
|
||||||
kern_return_t ret = processor_set_default(sMachHost, &sMachDefaultPset);
|
kern_return_t ret = processor_set_default(sMachHost, &sMachDefaultPset);
|
||||||
|
sNumCPUs = 1;
|
||||||
if (ret != KERN_SUCCESS) {
|
if (ret != KERN_SUCCESS) {
|
||||||
fprintf(stderr, "TenFourFox: Unable to initialize Mach idle monitoring: %i\n", (uint32_t)ret);
|
fprintf(stderr, "TenFourFox: Unable to initialize Mach idle monitoring: %i\n", (uint32_t)ret);
|
||||||
sMachFactorMin = 0;
|
sMachFactorMin = 0;
|
||||||
}
|
}
|
||||||
|
int mib[2] = { CTL_HW, HW_NCPU };
|
||||||
|
size_t len = sizeof(sNumCPUs);
|
||||||
|
if (sysctl(mib, 2, &sNumCPUs, &len, NULL, 0) == -1)
|
||||||
|
sNumCPUs = 1;
|
||||||
|
#if DEBUG
|
||||||
|
fprintf(stderr, "GlobalWindow: %i CPUs\n", sNumCPUs);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gDumpFile == nullptr) {
|
if (gDumpFile == nullptr) {
|
||||||
|
@ -11591,7 +11602,13 @@ SystemIsIdle()
|
||||||
(processor_set_info_t)&sMachLoadInfo, &count);
|
(processor_set_info_t)&sMachLoadInfo, &count);
|
||||||
if (kr != KERN_SUCCESS) return true;
|
if (kr != KERN_SUCCESS) return true;
|
||||||
|
|
||||||
return (sMachLoadInfo.mach_factor > sMachFactorMin);
|
#if DEBUG
|
||||||
|
fprintf(stderr, "SystemIsIdle(%i/%i: %s)\n",
|
||||||
|
sMachLoadInfo.mach_factor,
|
||||||
|
sMachFactorMin * sNumCPUs,
|
||||||
|
(sMachLoadInfo.mach_factor > (sMachFactorMin * sNumCPUs)) ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
return (sMachLoadInfo.mach_factor > (sMachFactorMin * sNumCPUs));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -11640,6 +11657,9 @@ nsGlobalWindow::SetTimeoutOrIntervalOrIdleCallback(nsIScriptTimeoutHandler *aHan
|
||||||
timeout->mDeadline = interval;
|
timeout->mDeadline = interval;
|
||||||
timeout->mScriptHandler = nullptr;
|
timeout->mScriptHandler = nullptr;
|
||||||
|
|
||||||
|
// XXX: Current logic short circuits this and simply makes idle callbacks
|
||||||
|
// into fixed timeouts.
|
||||||
|
#if(0)
|
||||||
// If RequestIdleCallback says this is not an interval, then it must
|
// If RequestIdleCallback says this is not an interval, then it must
|
||||||
// want it to run right away. Otherwise schedule the idle checks.
|
// want it to run right away. Otherwise schedule the idle checks.
|
||||||
if (aIsInterval) {
|
if (aIsInterval) {
|
||||||
|
@ -11647,6 +11667,9 @@ nsGlobalWindow::SetTimeoutOrIntervalOrIdleCallback(nsIScriptTimeoutHandler *aHan
|
||||||
} else
|
} else
|
||||||
interval = 0;
|
interval = 0;
|
||||||
timeout->mInterval = interval;
|
timeout->mInterval = interval;
|
||||||
|
#else
|
||||||
|
// Leave interval as it is
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
timeout->mInterval = interval;
|
timeout->mInterval = interval;
|
||||||
timeout->mCallback = nullptr;
|
timeout->mCallback = nullptr;
|
||||||
|
@ -12145,7 +12168,12 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
||||||
timeout->mElapsed += timeout->mInterval;
|
timeout->mElapsed += timeout->mInterval;
|
||||||
if (!timeout->mInterval || timeout->mElapsed >= timeout->mDeadline || SystemIsIdle()) {
|
if (!timeout->mInterval || timeout->mElapsed >= timeout->mDeadline || SystemIsIdle()) {
|
||||||
rescheduleOk = false;
|
rescheduleOk = false;
|
||||||
|
timeout->mIsInterval = false; // don't reschedule
|
||||||
timeout_was_cleared = RunTimeoutHandler(timeout, scx);
|
timeout_was_cleared = RunTimeoutHandler(timeout, scx);
|
||||||
|
if (timeout->mTimer) {
|
||||||
|
timeout->mTimer->Cancel();
|
||||||
|
timeout->mTimer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
timeout_was_cleared = RunTimeoutHandler(timeout, scx);
|
timeout_was_cleared = RunTimeoutHandler(timeout, scx);
|
||||||
|
@ -14004,13 +14032,20 @@ nsGlobalWindow::RequestIdleCallback(JSContext* aCx,
|
||||||
{
|
{
|
||||||
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||||
AssertIsOnMainThread();
|
AssertIsOnMainThread();
|
||||||
int32_t handle = -1, timeout = 3600000; /* default 60 minutes */
|
int32_t handle = -1, timeout = 5000; /* default 5 seconds */
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
if (aOptions.mTimeout.WasPassed())
|
if (aOptions.mTimeout.WasPassed())
|
||||||
timeout = aOptions.mTimeout.Value();
|
timeout = aOptions.mTimeout.Value();
|
||||||
|
|
||||||
if (SystemIsIdle()) {
|
// XXX: Deferring initial run of the callback beyond the timeout period
|
||||||
|
// invariably causes problems. But if a timeout was specified, we can
|
||||||
|
// generally assume it's safe to hit that.
|
||||||
|
|
||||||
|
if (1) { // SystemIsIdle()) {
|
||||||
|
#if DEBUG
|
||||||
|
fprintf(stderr, "Idle callback initialized, timeout %d ms\n", timeout);
|
||||||
|
#endif
|
||||||
// The computer is already idle, so we will run the callback now.
|
// The computer is already idle, so we will run the callback now.
|
||||||
rv = SetTimeoutOrIntervalOrIdleCallback(nullptr, timeout, false, &handle,
|
rv = SetTimeoutOrIntervalOrIdleCallback(nullptr, timeout, false, &handle,
|
||||||
&aCallback);
|
&aCallback);
|
||||||
|
@ -14019,6 +14054,7 @@ nsGlobalWindow::RequestIdleCallback(JSContext* aCx,
|
||||||
rv = SetTimeoutOrIntervalOrIdleCallback(nullptr, timeout, true, &handle,
|
rv = SetTimeoutOrIntervalOrIdleCallback(nullptr, timeout, true, &handle,
|
||||||
&aCallback);
|
&aCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
|
@ -14033,7 +14069,7 @@ nsGlobalWindow::CancelIdleCallback(uint32_t aHandle)
|
||||||
ErrorResult ignored;
|
ErrorResult ignored;
|
||||||
|
|
||||||
// XXX: As written, this is just an alias for clearTimeout(), so
|
// XXX: As written, this is just an alias for clearTimeout(), so
|
||||||
// web scripts could call either to clear any time of timeout
|
// web scripts could call either to clear any type of timeout
|
||||||
// or interval. Do we care?
|
// or interval. Do we care?
|
||||||
|
|
||||||
if (aHandle > 0) {
|
if (aHandle > 0) {
|
||||||
|
|
|
@ -1043,7 +1043,7 @@ pref("dom.disable_window_open_feature.status", true);
|
||||||
pref("dom.allow_scripts_to_close_windows", false);
|
pref("dom.allow_scripts_to_close_windows", false);
|
||||||
|
|
||||||
// TenFourFox issue 463
|
// TenFourFox issue 463
|
||||||
pref("tenfourfox.dom.requestIdleCallback.enabled", true);
|
pref("tenfourfox.dom.requestIdleCallback.enabled", false);
|
||||||
|
|
||||||
pref("dom.require_user_interaction_for_beforeunload", true);
|
pref("dom.require_user_interaction_for_beforeunload", true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user