Skip to content

Commit 590efb4

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Move compile worker stats to ModuleState
Summary: Move g_compile_workers_attempted and g_compile_workers_retries from pyjit.cpp global variables into ModuleState members, continuing the effort to encapsulate JIT mutable state in the ModuleState singleton. These are only read by `multithreaded_compile_test`, they're not critical. Reviewed By: yoney Differential Revision: D96138617 fbshipit-source-id: 590d8e8c07b2ff666299e5d9b3ed5982ba64d532
1 parent 5662ceb commit 590efb4

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

cinderx/Jit/pyjit.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ CompilerContext<Compiler>* jitCtx() {
9696
using UnitDeletedCallback = std::function<void(PyObject*)>;
9797
UnitDeletedCallback handle_unit_deleted_during_preload = nullptr;
9898

99-
std::atomic<int> g_compile_workers_attempted;
100-
std::atomic<int> g_compile_workers_retries;
101-
10299
// Don't care flags: CO_NOFREE, CO_FUTURE_* (the only still-relevant future is
103100
// "annotations" which doesn't impact bytecode execution.)
104101
constexpr int required_code_flags = CO_OPTIMIZED | CO_NEWLOCALS;
@@ -947,8 +944,8 @@ Result tryCompilePreloaded(BorrowedRef<> unit) {
947944
void compile_worker_thread() {
948945
JIT_DLOG("Started compile worker in thread {}", std::this_thread::get_id());
949946

950-
size_t attempts = 0;
951-
size_t retries = 0;
947+
int attempts = 0;
948+
int retries = 0;
952949

953950
while (BorrowedRef<> unit = getThreadedCompileContext().nextUnit()) {
954951
attempts++;
@@ -963,8 +960,8 @@ void compile_worker_thread() {
963960
unitFullname(unit));
964961
}
965962

966-
g_compile_workers_attempted.fetch_add(attempts);
967-
g_compile_workers_retries.fetch_add(retries);
963+
cinderx::getModuleState()->compileWorkersAttempted().fetch_add(attempts);
964+
cinderx::getModuleState()->compileWorkersRetries().fetch_add(retries);
968965

969966
JIT_DLOG(
970967
"Finished compile worker in thread {}. Compile attempts: {}, scheduled "
@@ -1253,8 +1250,8 @@ PyObject* multithreaded_compile_test(PyObject*, PyObject*) {
12531250
PyExc_NotImplementedError, "multithreaded_compile_test not enabled");
12541251
return nullptr;
12551252
}
1256-
g_compile_workers_attempted = 0;
1257-
g_compile_workers_retries = 0;
1253+
cinderx::getModuleState()->compileWorkersAttempted() = 0;
1254+
cinderx::getModuleState()->compileWorkersRetries() = 0;
12581255
auto& jit_reg_units = cinderx::getModuleState()->registeredCompilationUnits();
12591256
JIT_LOG("(Re)compiling {} units", jit_reg_units.size());
12601257
jitCtx()->clearCache();
@@ -1270,8 +1267,8 @@ PyObject* multithreaded_compile_test(PyObject*, PyObject*) {
12701267
JIT_LOG(
12711268
"Took {} ms, compiles attempted: {}, compiles retried: {}",
12721269
batch_compilation_time.count(),
1273-
g_compile_workers_attempted,
1274-
g_compile_workers_retries);
1270+
cinderx::getModuleState()->compileWorkersAttempted().load(),
1271+
cinderx::getModuleState()->compileWorkersRetries().load());
12751272
Py_RETURN_NONE;
12761273
}
12771274

cinderx/module_state.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ class ModuleState {
197197

198198
jit::UnorderedSet<BorrowedRef<>>& registeredCompilationUnits();
199199

200+
std::atomic<int>& compileWorkersAttempted() {
201+
return compile_workers_attempted_;
202+
}
203+
204+
std::atomic<int>& compileWorkersRetries() {
205+
return compile_workers_retries_;
206+
}
207+
200208
private:
201209
WatcherState watcher_state_;
202210

@@ -225,6 +233,9 @@ class ModuleState {
225233
jit::UnorderedSet<BorrowedRef<PyFunctionObject>> perf_trampoline_worklist_;
226234

227235
BorrowedRef<> cinderx_module_;
236+
237+
std::atomic<int> compile_workers_attempted_{0};
238+
std::atomic<int> compile_workers_retries_{0};
228239
};
229240

230241
// Get the global ModuleState singleton.

0 commit comments

Comments
 (0)