Skip to content

Commit

Permalink
Try a global lock for all libraries to prevent more than one concurre…
Browse files Browse the repository at this point in the history
…nt vopt operation.

This is a temp fix to try if that resolves identified problems
  • Loading branch information
LarsAsplund committed Sep 9, 2024
1 parent 9c3524b commit bcf53c0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions vunit/sim_if/modelsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self, prefix, output_path, persistent=False, gui=False):
self._optimized_designs = {}
self._optimized_libraries = {}
self._vopt_lock = Lock()
self._library_lock = Lock()

def _create_modelsim_ini(self):
"""
Expand Down Expand Up @@ -330,19 +331,22 @@ def _acquire_library_lock(self, library, config, design_to_optimize):
# Do not completely block to allow for Ctrl+C
while not library_lock.acquire(timeout=0.05):
pass
while (Path(library.directory) / "_lock").exists():
LOGGER.debug("Waiting for %s to be removed", Path(library.directory) / "_lock")
sleep(0.05)

for library in self._libraries:
while (Path(library.directory) / "_lock").exists():
LOGGER.debug("Waiting for %s to be removed", Path(library.directory) / "_lock")
sleep(0.05)
LOGGER.debug("Acquired library lock for %s to optimize %s", config.library_name, design_to_optimize)

def _release_library_lock(self, library, config):
"""
Release library lock and wait for any lock file to be removed.
"""
with self._vopt_lock:
while (Path(library.directory) / "_lock").exists():
LOGGER.debug("Waiting for %s to be removed", Path(library.directory) / "_lock")
sleep(0.05)
for library in self._libraries:
while (Path(library.directory) / "_lock").exists():
LOGGER.debug("Waiting for %s to be removed", Path(library.directory) / "_lock")
sleep(0.05)
self._optimized_libraries[config.library_name].release()

def _optimize(self, config, script_path):
Expand Down Expand Up @@ -370,7 +374,7 @@ def _optimize(self, config, script_path):
optimize = True

if not self._optimized_libraries.get(config.library_name, None):
self._optimized_libraries[config.library_name] = Lock()
self._optimized_libraries[config.library_name] = self._library_lock

simulation_target, vopt_event = self._optimized_designs[design_to_optimize].values()

Expand Down

0 comments on commit bcf53c0

Please sign in to comment.