Skip to content

Commit

Permalink
[topgen] Do not use hardcoded temporary file names
Browse files Browse the repository at this point in the history
When iterating on the top configuration, the code uses a fixed
path under `/tmp/`. This can cause permission problems in multi
user systems. Change the code to keep the file dump in memory,
hence solving the problem.

Signed-off-by: Amaury Pouly <[email protected]>
  • Loading branch information
pamaury committed Feb 21, 2025
1 parent a0e8654 commit 4c9cd1a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions util/topgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,13 +947,6 @@ def amend_reset_connections(topcfg: Dict[str, object]):
_amend_block_reset_connections(xbar, default_power_domain)


def _dump_cfg(path: Path, cfg: Dict[str, object]):
text = hjson.dumps(cfg, for_json=True, default=vars) + '\n'
text_length = len(text)
log.info(f'will dump {path} with {text_length} bytes')
path.write_text(text)


def create_generic_ip_blocks(topcfg: Dict[str, object],
alias_cfgs: Dict[str,
Dict[str,
Expand Down Expand Up @@ -1532,6 +1525,7 @@ def main():

topname = topcfg["name"]
cfg_copy = deepcopy(topcfg)
cfg_last_dump = None
for pass_idx in range(maximum_passes):
log.info("Generation pass {}".format(pass_idx + 1))
# Use the same seed for each pass to have stable random constants.
Expand All @@ -1543,15 +1537,13 @@ def main():
cfg_copy, args, cfg_path, out_path_gen, alias_cfgs)
# Delete config path before dumping, not needed
del completecfg["cfg_path"]
dump_path = Path(f"/tmp/top{topname}cfg_{pass_idx}.hjson")
_dump_cfg(dump_path, completecfg)
if pass_idx > 0 and filecmp.cmp(
f"/tmp/top{topname}cfg_{pass_idx}.hjson",
"/tmp/top{}cfg_{}.hjson".format(topname, pass_idx),
shallow=False):
cfg_dump = hjson.dumps(completecfg, for_json=True, default=vars)
if pass_idx > 0 and cfg_dump == cfg_last_dump:
log.info("process_top converged after {} passes".format(pass_idx +
1))
break
else:
cfg_last_dump = cfg_dump
cfg_copy = completecfg
else:
log.error("Too many process_top passes without convergence")
Expand Down

0 comments on commit 4c9cd1a

Please sign in to comment.