Skip to content

Commit 5293145

Browse files
benvanikclaude
andcommitted
Completes migration of iree/base/threading and adds comprehensive tests.
Finishes the threading module migration by removing backward-compatibility shim headers and updating all consumers to use direct includes. This makes dependencies explicit and removes the indirection that was masking the true module structure. Adds a full test and benchmark suite: - Mutex: correctness under contention, try_lock semantics, performance characteristics of slim vs fat mutex across thread counts - Notification: producer/consumer patterns, timeout behavior, spurious wakeup handling, throughput under varying contention - Thread: creation/join lifecycle, thread-local storage, affinity, priority inheritance behavior - Call-once: concurrent initialization races, exception safety Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6e986b6 commit 5293145

File tree

92 files changed

+1359
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1359
-386
lines changed

runtime/bindings/python/loop.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <vector>
1111

1212
#include "./hal.h"
13-
#include "iree/base/internal/synchronization.h"
13+
#include "iree/base/threading/mutex.h"
1414

1515
namespace iree::python {
1616

runtime/bindings/tflite/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ iree_runtime_cc_library(
4141
deps = [
4242
"//runtime/src/iree/base",
4343
"//runtime/src/iree/base/internal",
44-
"//runtime/src/iree/base/internal:synchronization",
4544
"//runtime/src/iree/base/threading",
4645
"//runtime/src/iree/hal",
4746
"//runtime/src/iree/hal/drivers",

runtime/bindings/tflite/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ iree_cc_library(
3131
DEPS
3232
iree::base
3333
iree::base::internal
34-
iree::base::internal::synchronization
34+
iree::base::threading
3535
iree::hal
3636
iree::hal::drivers
3737
iree::modules::hal

runtime/src/iree/base/internal/BUILD.bazel

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ iree_runtime_cc_library(
7575
deps = [
7676
":atomic_slist",
7777
":internal",
78-
":synchronization",
7978
"//runtime/src/iree/base",
8079
],
8180
)
@@ -86,8 +85,8 @@ iree_runtime_cc_library(
8685
hdrs = ["atomic_slist.h"],
8786
deps = [
8887
":internal",
89-
":synchronization",
9088
"//runtime/src/iree/base:core_headers",
89+
"//runtime/src/iree/base/threading",
9190
],
9291
)
9392

@@ -133,7 +132,6 @@ cc_binary_benchmark(
133132
],
134133
)
135134

136-
137135
iree_runtime_cc_library(
138136
name = "cpu",
139137
srcs = ["cpu.c"],
@@ -155,7 +153,6 @@ iree_runtime_cc_library(
155153
deps = [
156154
":internal",
157155
":path",
158-
":synchronization",
159156
"//build_tools:dl",
160157
"//build_tools:pthreads",
161158
"//runtime/src/iree/base",
@@ -305,33 +302,6 @@ iree_runtime_cc_library(
305302
hdrs = ["span.h"],
306303
)
307304

308-
iree_runtime_cc_library(
309-
name = "synchronization",
310-
hdrs = ["synchronization.h"],
311-
deps = ["//runtime/src/iree/base/threading"],
312-
)
313-
314-
cc_binary_benchmark(
315-
name = "synchronization_benchmark",
316-
testonly = True,
317-
srcs = ["synchronization_benchmark.cc"],
318-
deps = [
319-
":synchronization",
320-
"//runtime/src/iree/testing:benchmark_main",
321-
"@com_google_benchmark//:benchmark",
322-
],
323-
)
324-
325-
iree_runtime_cc_test(
326-
name = "synchronization_test",
327-
srcs = ["synchronization_test.cc"],
328-
deps = [
329-
":synchronization",
330-
"//runtime/src/iree/testing:gtest",
331-
"//runtime/src/iree/testing:gtest_main",
332-
],
333-
)
334-
335305
iree_runtime_cc_library(
336306
name = "time",
337307
srcs = [
@@ -392,7 +362,6 @@ iree_runtime_cc_library(
392362
],
393363
hdrs = ["wait_handle.h"],
394364
deps = [
395-
":synchronization",
396365
"//runtime/src/iree/base",
397366
"//runtime/src/iree/base:core_headers",
398367
"//runtime/src/iree/base/threading",
@@ -428,30 +397,9 @@ iree_runtime_cc_library(
428397
hdrs = ["event_pool.h"],
429398
deps = [
430399
":internal",
431-
":synchronization",
432400
":wait_handle",
433401
"//runtime/src/iree/base",
434402
"//runtime/src/iree/base:core_headers",
435-
],
436-
)
437-
438-
iree_runtime_cc_library(
439-
name = "threading",
440-
hdrs = [
441-
"threading.h",
442-
"threading_impl.h",
443-
],
444-
deps = ["//runtime/src/iree/base/threading:thread"],
445-
)
446-
447-
iree_runtime_cc_test(
448-
name = "threading_test",
449-
srcs = ["threading_test.cc"],
450-
deps = [
451-
":internal",
452-
":synchronization",
453-
":threading",
454-
"//runtime/src/iree/testing:gtest",
455-
"//runtime/src/iree/testing:gtest_main",
403+
"//runtime/src/iree/base/threading",
456404
],
457405
)

runtime/src/iree/base/internal/CMakeLists.txt

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ iree_cc_library(
6161
DEPS
6262
::atomic_slist
6363
::internal
64-
::synchronization
6564
iree::base
6665
PUBLIC
6766
)
@@ -75,8 +74,8 @@ iree_cc_library(
7574
"atomic_slist.c"
7675
DEPS
7776
::internal
78-
::synchronization
7977
iree::base::core_headers
78+
iree::base::threading
8079
PUBLIC
8180
)
8281

@@ -154,7 +153,6 @@ iree_cc_library(
154153
${CMAKE_DL_LIBS}
155154
::internal
156155
::path
157-
::synchronization
158156
iree::base
159157
iree::base::threading
160158
PUBLIC
@@ -331,39 +329,6 @@ iree_cc_library(
331329
PUBLIC
332330
)
333331

334-
iree_cc_library(
335-
NAME
336-
synchronization
337-
HDRS
338-
"synchronization.h"
339-
DEPS
340-
iree::base::threading
341-
PUBLIC
342-
)
343-
344-
iree_cc_binary_benchmark(
345-
NAME
346-
synchronization_benchmark
347-
SRCS
348-
"synchronization_benchmark.cc"
349-
DEPS
350-
::synchronization
351-
benchmark
352-
iree::testing::benchmark_main
353-
TESTONLY
354-
)
355-
356-
iree_cc_test(
357-
NAME
358-
synchronization_test
359-
SRCS
360-
"synchronization_test.cc"
361-
DEPS
362-
::synchronization
363-
iree::testing::gtest
364-
iree::testing::gtest_main
365-
)
366-
367332
iree_cc_library(
368333
NAME
369334
time
@@ -427,7 +392,6 @@ iree_cc_library(
427392
"wait_handle_posix.h"
428393
"wait_handle_win32.c"
429394
DEPS
430-
::synchronization
431395
iree::base
432396
iree::base::core_headers
433397
iree::base::threading
@@ -458,37 +422,13 @@ iree_cc_library(
458422
"event_pool.c"
459423
DEPS
460424
::internal
461-
::synchronization
462425
::wait_handle
463426
iree::base
464427
iree::base::core_headers
428+
iree::base::threading
465429
PUBLIC
466430
)
467431

468-
iree_cc_library(
469-
NAME
470-
threading
471-
HDRS
472-
"threading.h"
473-
"threading_impl.h"
474-
DEPS
475-
iree::base::threading::thread
476-
PUBLIC
477-
)
478-
479-
iree_cc_test(
480-
NAME
481-
threading_test
482-
SRCS
483-
"threading_test.cc"
484-
DEPS
485-
::internal
486-
::synchronization
487-
::threading
488-
iree::testing::gtest
489-
iree::testing::gtest_main
490-
)
491-
492432
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
493433

494434
if(EMSCRIPTEN)

runtime/src/iree/base/internal/atomic_slist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "iree/base/alignment.h"
1919
#include "iree/base/internal/atomics.h"
20-
#include "iree/base/internal/synchronization.h"
20+
#include "iree/base/threading/mutex.h"
2121

2222
#ifdef __cplusplus
2323
extern "C" {

runtime/src/iree/base/internal/event_pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <stddef.h>
1111
#include <string.h>
1212

13-
#include "iree/base/internal/synchronization.h"
13+
#include "iree/base/threading/mutex.h"
1414

1515
struct iree_event_pool_t {
1616
// Allocator used to create the event pool.

runtime/src/iree/base/internal/memory.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ void iree_memory_flush_icache(void* base_address, iree_host_size_t length);
7272
// C11 aligned_alloc shim
7373
//===----------------------------------------------------------------------===//
7474

75+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76+
// WARNING: DO NOT USE THIS FUNCTION FOR NORMAL ALLOCATIONS.
77+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78+
//
79+
// This function BYPASSES the iree_allocator_t infrastructure entirely. Using it
80+
// means:
81+
// - No integration with custom allocators (arena, pool, tracking, etc)
82+
// - No ability to use iree_allocator_free() - must use iree_aligned_free()
83+
// - Memory accounting and debugging tools cannot track these allocations
84+
// - Breaks the allocator abstraction that enables embedded/custom deployments
85+
//
86+
// VALID USES (require explicit approval):
87+
// - NUMA allocation fallback (numa_*.c) - special physical placement needs
88+
// - Status storage (status.c internal) - bootstrapping before allocators
89+
// exist and that allocators use for handling when they fail
90+
// - Test/benchmark code where allocator integration is irrelevant
91+
//
92+
// FOR ALIGNED ALLOCATIONS IN NORMAL CODE:
93+
// - Embed aligned data within a larger struct that is normally allocated
94+
// - Use iree_allocator_malloc with extra padding and manual alignment
95+
// - Reconsider whether 64-byte alignment is actually necessary
96+
//
97+
// If you think you need this function, you are almost certainly wrong.
98+
// Ask for guidance before using it.
99+
75100
// Allocates |size| bytes of uninitialized storage whose alignment is specified
76101
// by |alignment|. The |size| parameter must be an integral multiple of
77102
// |alignment|. The returned pointer must be freed using iree_aligned_free.

runtime/src/iree/base/internal/synchronization.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

runtime/src/iree/base/internal/threading.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)