Backed out 2 changesets (bug 1862556, bug 1862557) for causing build bustages in nsThreadManager.cpp CLOSED TREE

Backed out changeset 4ef47a21279a (bug 1862557)
Backed out changeset 2573ea9f377b (bug 1862556)
This commit is contained in:
Cristian Tuns 2023-12-06 17:33:12 -05:00
Родитель ed1bdf00c4
Коммит d7a07e4b57
9 изменённых файлов: 33 добавлений и 88 удалений

Просмотреть файл

@ -411,7 +411,8 @@ void StorageDBThread::SetDefaultPriority() {
void StorageDBThread::ThreadFunc(void* aArg) {
{
auto queue = MakeRefPtr<ThreadEventQueue>(MakeUnique<EventQueue>());
Unused << nsThreadManager::get().CreateCurrentThread(queue);
Unused << nsThreadManager::get().CreateCurrentThread(
queue, nsThread::NOT_MAIN_THREAD);
}
AUTO_PROFILER_REGISTER_THREAD("localStorage DB");

Просмотреть файл

@ -152,7 +152,8 @@ void Thread::ThreadMain() {
loopType == MessageLoop::TYPE_MOZILLA_NONMAINUITHREAD) {
auto queue = mozilla::MakeRefPtr<mozilla::ThreadEventQueue>(
mozilla::MakeUnique<mozilla::EventQueue>());
xpcomThread = nsThreadManager::get().CreateCurrentThread(queue);
xpcomThread = nsThreadManager::get().CreateCurrentThread(
queue, nsThread::NOT_MAIN_THREAD);
} else {
xpcomThread = NS_GetCurrentThread();
}

Просмотреть файл

@ -36,8 +36,6 @@
namespace mozilla {
namespace net {
#define SOCKET_THREAD_LONGTASK_MS 3
LazyLogModule gSocketTransportLog("nsSocketTransport");
LazyLogModule gUDPSocketLog("UDPSocket");
LazyLogModule gTCPSocketLog("TCPSocket");
@ -639,7 +637,7 @@ int32_t nsSocketTransportService::Poll(TimeDuration* pollDuration,
SOCKET_LOG((" timeout = %i milliseconds\n",
PR_IntervalToMilliseconds(pollTimeout)));
int32_t n;
int32_t rv;
{
#ifdef MOZ_GECKO_PROFILER
TimeStamp startTime = TimeStamp::Now();
@ -650,7 +648,7 @@ int32_t nsSocketTransportService::Poll(TimeDuration* pollDuration,
}
#endif
n = PR_Poll(firstPollEntry, pollCount, pollTimeout);
rv = PR_Poll(firstPollEntry, pollCount, pollTimeout);
#ifdef MOZ_GECKO_PROFILER
if (pollTimeout != PR_INTERVAL_NO_WAIT) {
@ -679,7 +677,7 @@ int32_t nsSocketTransportService::Poll(TimeDuration* pollDuration,
SOCKET_LOG((" ...returned after %i milliseconds\n",
PR_IntervalToMilliseconds(PR_IntervalNow() - ts)));
return n;
return rv;
}
//-----------------------------------------------------------------------------
@ -744,19 +742,15 @@ nsSocketTransportService::Init() {
if (!XRE_IsContentProcess() ||
StaticPrefs::network_allow_raw_sockets_in_content_processes_AtStartup()) {
// Since we Poll, we can't use normal LongTask support in Main Process
nsresult rv =
NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), this,
{.stackSize = GetThreadStackSize(),
.longTaskLength = Some(SOCKET_THREAD_LONGTASK_MS)});
nsresult rv = NS_NewNamedThread("Socket Thread", getter_AddRefs(thread),
this, {.stackSize = GetThreadStackSize()});
NS_ENSURE_SUCCESS(rv, rv);
} else {
// In the child process, we just want a regular nsThread with no socket
// polling. So we don't want to run the nsSocketTransportService runnable on
// it.
nsresult rv =
NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), nullptr,
{.longTaskLength = Some(SOCKET_THREAD_LONGTASK_MS)});
NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), nullptr);
NS_ENSURE_SUCCESS(rv, rv);
// Set up some of the state that nsSocketTransportService::Run would set.
@ -1373,13 +1367,6 @@ nsresult nsSocketTransportService::DoPollIteration(TimeDuration* pollDuration) {
}
now = PR_IntervalNow();
TimeStamp startTime;
#ifdef MOZ_GECKO_PROFILER
bool profiling = profiler_thread_is_being_profiled_for_markers();
if (profiling) {
startTime = TimeStamp::Now();
}
#endif
if (n < 0) {
SOCKET_LOG((" PR_Poll error [%d] os error [%d]\n", PR_GetError(),
@ -1436,36 +1423,6 @@ nsresult nsSocketTransportService::DoPollIteration(TimeDuration* pollDuration) {
}
}
}
#ifdef MOZ_GECKO_PROFILER
if (profiling) {
TimeStamp endTime = TimeStamp::Now();
if ((endTime - startTime).ToMilliseconds() >= SOCKET_THREAD_LONGTASK_MS) {
struct LongTaskMarker {
static constexpr Span<const char> MarkerTypeName() {
return MakeStringSpan("SocketThreadLongTask");
}
static void StreamJSONMarkerData(
baseprofiler::SpliceableJSONWriter& aWriter) {
aWriter.StringProperty("category", "LongTask");
}
static MarkerSchema MarkerTypeDisplay() {
using MS = MarkerSchema;
MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable};
schema.AddKeyLabelFormatSearchable("category", "Type",
MS::Format::String,
MS::Searchable::Searchable);
return schema;
}
};
profiler_add_marker(ProfilerString8View("LongTaskSocketProcessing"),
geckoprofiler::category::OTHER,
MarkerTiming::Interval(startTime, endTime),
LongTaskMarker{});
}
}
#endif
return NS_OK;
}

Просмотреть файл

@ -381,7 +381,8 @@ void CacheIOThread::ThreadFunc() {
auto queue =
MakeRefPtr<ThreadEventQueue>(MakeUnique<mozilla::EventQueue>());
nsCOMPtr<nsIThread> xpcomThread =
nsThreadManager::get().CreateCurrentThread(queue);
nsThreadManager::get().CreateCurrentThread(queue,
nsThread::NOT_MAIN_THREAD);
threadInternal = do_QueryInterface(xpcomThread);
if (threadInternal) threadInternal->SetObserver(this);

Просмотреть файл

@ -13,10 +13,6 @@ interface nsIEventTarget;
interface nsIRunnable;
interface nsIThread;
%{ C++
#include "mozilla/Maybe.h"
%}
[scriptable, function, uuid(039a227d-0cb7-44a5-a8f9-dbb7071979f2)]
interface nsINestedEventLoopCondition : nsISupports
{
@ -76,11 +72,6 @@ interface nsIThreadManager : nsISupports
// (Windows-only) Whether the thread should have a MessageLoop capable of
// processing native UI events. Defaults to false.
bool isUiThread = false;
// If set, long task markers will be collected for tasks
// longer than longTaskLength ms when profiling is enabled.
// See https://www.w3.org/TR/longtasks
mozilla::Maybe<uint32_t> longTaskLength;
};
%}

Просмотреть файл

@ -550,8 +550,7 @@ nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
#ifdef EARLY_BETA_OR_EARLIER
mLastWakeupCheckTime(TimeStamp::Now()),
#endif
mPerformanceCounterState(mNestedEventLoopDepth, mIsMainThread,
aOptions.longTaskLength) {
mPerformanceCounterState(mNestedEventLoopDepth, mIsMainThread) {
#if !(defined(XP_WIN) || defined(XP_MACOSX))
MOZ_ASSERT(!mIsUiThread,
"Non-main UI threads are only supported on Windows and macOS");
@ -582,7 +581,7 @@ nsThread::nsThread()
#ifdef EARLY_BETA_OR_EARLIER
mLastWakeupCheckTime(TimeStamp::Now()),
#endif
mPerformanceCounterState(mNestedEventLoopDepth) {
mPerformanceCounterState(mNestedEventLoopDepth, mIsMainThread) {
MOZ_ASSERT(!NS_IsMainThread());
}
@ -1459,11 +1458,9 @@ void nsThreadShutdownContext::MarkCompleted() {
namespace mozilla {
PerformanceCounterState::Snapshot PerformanceCounterState::RunnableWillRun(
TimeStamp aNow, bool aIsIdleRunnable) {
if (mIsMainThread && IsNestedRunnable()) {
if (IsNestedRunnable()) {
// Flush out any accumulated time that should be accounted to the
// current runnable before we start running a nested runnable. Don't
// do this for non-mainthread threads that may be running their own
// event loops, like SocketThread.
// current runnable before we start running a nested runnable.
MaybeReportAccumulatedTime("nested runnable"_ns, aNow);
}
@ -1485,10 +1482,10 @@ void PerformanceCounterState::RunnableDidRun(const nsCString& aName,
// We may not need the current timestamp; don't bother computing it if we
// don't.
TimeStamp now;
if (mLongTaskLength.isSome() || IsNestedRunnable()) {
if (mIsMainThread || IsNestedRunnable()) {
now = TimeStamp::Now();
}
if (mLongTaskLength.isSome()) {
if (mIsMainThread) {
MaybeReportAccumulatedTime(aName, now);
}
@ -1508,7 +1505,9 @@ void PerformanceCounterState::MaybeReportAccumulatedTime(const nsCString& aName,
TimeStamp aNow) {
MOZ_ASSERT(mCurrentTimeSliceStart,
"How did we get here if we're not in a timeslice?");
if (!mLongTaskLength.isSome()) {
if (!mIsMainThread) {
// No one cares about this timeslice.
return;
}
@ -1521,7 +1520,7 @@ void PerformanceCounterState::MaybeReportAccumulatedTime(const nsCString& aName,
#endif
// Long tasks only matter on the main thread.
if (duration.ToMilliseconds() >= mLongTaskLength.value()) {
if (mIsMainThread && duration.ToMilliseconds() > LONGTASK_BUSY_WINDOW_MS) {
// Idle events (gc...) don't *really* count here
if (!mCurrentRunnableIsIdleRunnable) {
mLastLongNonIdleTaskEnd = aNow;

Просмотреть файл

@ -46,7 +46,7 @@ class nsIRunnable;
class nsThreadShutdownContext;
// See https://www.w3.org/TR/longtasks
#define W3_LONGTASK_BUSY_WINDOW_MS 50
#define LONGTASK_BUSY_WINDOW_MS 50
// Time a Runnable executes before we accumulate telemetry on it
#define LONGTASK_TELEMETRY_MS 30
@ -55,12 +55,10 @@ class nsThreadShutdownContext;
namespace mozilla {
class PerformanceCounterState {
public:
explicit PerformanceCounterState(
const uint32_t& aNestedEventLoopDepthRef, bool aIsMainThread = false,
const Maybe<uint32_t>& aLongTaskLength = Nothing())
explicit PerformanceCounterState(const uint32_t& aNestedEventLoopDepthRef,
bool aIsMainThread)
: mNestedEventLoopDepth(aNestedEventLoopDepthRef),
mIsMainThread(aIsMainThread),
mLongTaskLength(aLongTaskLength),
// Does it really make sense to initialize these to "now" when we
// haven't run any tasks?
mLastLongTaskEnd(TimeStamp::Now()),
@ -132,9 +130,6 @@ class PerformanceCounterState {
// Whether we're attached to the mainthread nsThread.
const bool mIsMainThread;
// what is considered a LongTask (in ms)
const Maybe<uint32_t> mLongTaskLength;
// The timestamp from which time to be accounted for should be measured. This
// can be the start of a runnable running or the end of a nested runnable
// running.

Просмотреть файл

@ -308,9 +308,8 @@ nsresult nsThreadManager::Init() {
RefPtr<ThreadEventQueue> synchronizedQueue =
new ThreadEventQueue(std::move(queue), true);
mMainThread = new nsThread(
WrapNotNull(synchronizedQueue), nsThread::MAIN_THREAD,
{.stackSize = 0, .longTaskLength = Some(W3_LONGTASK_BUSY_WINDOW_MS)});
mMainThread = new nsThread(WrapNotNull(synchronizedQueue),
nsThread::MAIN_THREAD, {.stackSize = 0});
nsresult rv = mMainThread->InitCurrentThread();
if (NS_FAILED(rv)) {
@ -491,8 +490,8 @@ void nsThreadManager::UnregisterCurrentThread(nsThread& aThread) {
// Ref-count balanced via ReleaseThread
}
// Not to be used for MainThread!
nsThread* nsThreadManager::CreateCurrentThread(SynchronizedEventQueue* aQueue) {
nsThread* nsThreadManager::CreateCurrentThread(
SynchronizedEventQueue* aQueue, nsThread::MainThreadFlag aMainThread) {
// Make sure we don't have an nsThread yet.
MOZ_ASSERT(!PR_GetThreadPrivate(mCurThreadIndex));
@ -500,8 +499,8 @@ nsThread* nsThreadManager::CreateCurrentThread(SynchronizedEventQueue* aQueue) {
return nullptr;
}
RefPtr<nsThread> thread = new nsThread(
WrapNotNull(aQueue), nsThread::NOT_MAIN_THREAD, {.stackSize = 0});
RefPtr<nsThread> thread =
new nsThread(WrapNotNull(aQueue), aMainThread, {.stackSize = 0});
if (NS_FAILED(thread->InitCurrentThread())) {
return nullptr;
}

Просмотреть файл

@ -69,7 +69,8 @@ class nsThreadManager : public nsIThreadManager {
// the thread that was created. GetCurrentThread() will also create a thread
// (lazily), but it doesn't allow the queue or main-thread attributes to be
// specified.
nsThread* CreateCurrentThread(mozilla::SynchronizedEventQueue* aQueue);
nsThread* CreateCurrentThread(mozilla::SynchronizedEventQueue* aQueue,
nsThread::MainThreadFlag aMainThread);
nsresult DispatchToBackgroundThread(nsIRunnable* aEvent,
uint32_t aDispatchFlags);