From f52ba8acbe9020a043a7dab7f6b3a59c9ab06d89 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Wed, 5 Jun 2019 16:09:40 -0700 Subject: [PATCH 1/4] Add timestamp twiddling logic --- fault/system_verilog_target.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fault/system_verilog_target.py b/fault/system_verilog_target.py index 2e25f517..8e867ad4 100644 --- a/fault/system_verilog_target.py +++ b/fault/system_verilog_target.py @@ -8,6 +8,7 @@ import subprocess from fault.wrapper import PortWrapper import fault +import os src_tpl = """\ @@ -269,8 +270,25 @@ def run(self, actions, power_args={}): # Write the verilator driver to file. src = self.generate_code(actions, power_args) - with open(self.directory / test_bench_file, "w") as f: + tb_file = self.directory / test_bench_file + # If there's an old test bench file, ncsim might not recompile based on + # the timestamp (1s granularity), see + # https://github.com/StanfordAHA/lassen/issues/111 + # so we check if the new/old file have the same timestamp and edit them + # to force an ncsim recompile + check_timestamp = os.path.isfile(tb_file) + if check_timestamp: + check_timestamp = True + old_stat_result = os.stat(tb_file) + old_times = (old_stat_result.st_atime, old_stat_result.st_mtime) + with open(tb_file, "w") as f: f.write(src) + if check_timestamp: + new_stat_result = os.stat(tb_file) + new_times = (new_stat_result.st_atime, new_stat_result.st_mtime) + if new_times[1] - old_times[1] == 0: + new_times = (new_times[0], new_times[1] + 1) + os.utime(tb_file, times=new_times) verilog_libraries = " ".join(str(x) for x in self.include_verilog_libraries) cmd_file = Path(f"{self.circuit_name}_cmd.tcl") From b084cd40424e03e318a3a86ad2b82e3ccbd9df20 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Wed, 5 Jun 2019 16:22:49 -0700 Subject: [PATCH 2/4] Try incrementing atime as well --- fault/system_verilog_target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fault/system_verilog_target.py b/fault/system_verilog_target.py index 8e867ad4..f8fe75da 100644 --- a/fault/system_verilog_target.py +++ b/fault/system_verilog_target.py @@ -287,7 +287,7 @@ def run(self, actions, power_args={}): new_stat_result = os.stat(tb_file) new_times = (new_stat_result.st_atime, new_stat_result.st_mtime) if new_times[1] - old_times[1] == 0: - new_times = (new_times[0], new_times[1] + 1) + new_times = (new_times[0] + 1, new_times[1] + 1) os.utime(tb_file, times=new_times) verilog_libraries = " ".join(str(x) for x in self.include_verilog_libraries) From 7d2a5607bf8b637f6c567be1298a91aa18fbb7e6 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Wed, 5 Jun 2019 16:23:46 -0700 Subject: [PATCH 3/4] handle case when the timestamp just keeps increasing --- fault/system_verilog_target.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fault/system_verilog_target.py b/fault/system_verilog_target.py index f8fe75da..fd49fea7 100644 --- a/fault/system_verilog_target.py +++ b/fault/system_verilog_target.py @@ -286,8 +286,8 @@ def run(self, actions, power_args={}): if check_timestamp: new_stat_result = os.stat(tb_file) new_times = (new_stat_result.st_atime, new_stat_result.st_mtime) - if new_times[1] - old_times[1] == 0: - new_times = (new_times[0] + 1, new_times[1] + 1) + if new_times[1] <= old_times[1]: + new_times = (new_times[0], old_times[1] + 1) os.utime(tb_file, times=new_times) verilog_libraries = " ".join(str(x) for x in self.include_verilog_libraries) From 494c06074d08b7f02cfd9b5eaaff6195751cebce Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Wed, 5 Jun 2019 16:28:17 -0700 Subject: [PATCH 4/4] Fixup logic --- fault/system_verilog_target.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fault/system_verilog_target.py b/fault/system_verilog_target.py index fd49fea7..d2c451f6 100644 --- a/fault/system_verilog_target.py +++ b/fault/system_verilog_target.py @@ -286,8 +286,8 @@ def run(self, actions, power_args={}): if check_timestamp: new_stat_result = os.stat(tb_file) new_times = (new_stat_result.st_atime, new_stat_result.st_mtime) - if new_times[1] <= old_times[1]: - new_times = (new_times[0], old_times[1] + 1) + if old_times[0] <= new_times[0] or new_times[1] <= old_times[1]: + new_times = (old_times[0] + 1, old_times[1] + 1) os.utime(tb_file, times=new_times) verilog_libraries = " ".join(str(x) for x in self.include_verilog_libraries)