Skip to content

Commit

Permalink
Make VL_LOCK_SPINS configurable and increase default 100x
Browse files Browse the repository at this point in the history
It's unlikely one value fits all use case, so making VL_LOCK_SPINS
configurable at model build time.

Increasing the default is to help reduce the likelihood of threads
having to yield at simulation time in real runs, where we expect to have
thread count matched to the core count.

For testing, we keep the old value to reduce contention.
  • Loading branch information
gezalore committed Oct 21, 2023
1 parent d1c7875 commit 95b8124
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/verilated.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ inline constexpr size_t roundUpToMultipleOf(size_t value) {
// Return current thread ID (or 0), not super fast, cache if needed
extern uint32_t VL_THREAD_ID() VL_MT_SAFE;

#define VL_LOCK_SPINS 50000 /// Number of times to spin for a mutex before yielding
#ifndef VL_LOCK_SPINS
#define VL_LOCK_SPINS 50000000 /// Number of times to spin for a mutex before yielding
#endif

/// Mutex, wrapped to allow -fthread_safety checks
class VL_CAPABILITY("mutex") VerilatedMutex final {
Expand Down
3 changes: 3 additions & 0 deletions test_regress/Makefile_obj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ CPPFLAGS += $(CPPFLAGS_DRIVER)
CPPFLAGS += $(CPPFLAGS_DRIVER2)
CPPFLAGS += $(CPPFLAGS_ADD)

# Reduce spin count for faster testing
CPPFLAGS += -DVL_LOCK_SPINS=50000

ifeq ($(CFG_WITH_LONGTESTS),yes)
ifeq ($(DRIVER_STD),newest)
CPPFLAGS += $(CFG_CXXFLAGS_STD)
Expand Down

0 comments on commit 95b8124

Please sign in to comment.