From 5ace51c1cd5a581b94a5613a256413fd66c0f9e6 Mon Sep 17 00:00:00 2001 From: Harris Hancock Date: Mon, 10 Oct 2022 11:37:57 +0100 Subject: [PATCH] Add LockTiming::waitingForOtherIsolate() --- src/workerd/io/observer.h | 4 ++++ src/workerd/io/worker.c++ | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/workerd/io/observer.h b/src/workerd/io/observer.h index 9b439fd6a49..e71a561f3b4 100644 --- a/src/workerd/io/observer.h +++ b/src/workerd/io/observer.h @@ -109,6 +109,10 @@ class IsolateObserver: public kj::AtomicRefcounted { class LockTiming { public: + virtual void waitingForOtherIsolate(kj::StringPtr id) {} + // Called by `Isolate::takeAsyncLock()` when it is blocked by a different isolate lock on the + // same thread. + virtual void reportAsyncInfo(uint currentLoad, bool threadWaitingSameLock, uint threadWaitingDifferentLockCount) {} // Call if this is an async lock attempt, before constructing LockRecord. diff --git a/src/workerd/io/worker.c++ b/src/workerd/io/worker.c++ index 054469fc550..fd7952ebd55 100644 --- a/src/workerd/io/worker.c++ +++ b/src/workerd/io/worker.c++ @@ -1780,6 +1780,9 @@ kj::Promise Worker::Isolate::takeAsyncLockImpl( // be released before we try to lock a different isolate. // TODO(perf): Use of ForkedPromise leads to thundering herd here. Should be minor in practice, // but we could consider creating another linked list instead... + KJ_IF_MAYBE(lt, lockTiming) { + lt->get()->waitingForOtherIsolate(waiter->isolate->getId()); + } co_await waiter->releasePromise.addBranch(); } }