Skip to content

Run Tcl scripts in a Session, and keep the journal of a session in its worker - #2906

Open
ganeshgore wants to merge 2 commits into
staged-flow-morefrom
session-tcl
Open

ganeshgore wants to merge 2 commits into
staged-flow-morefrom
session-tcl

Conversation

@ganeshgore

Copy link
Copy Markdown
Collaborator

Stacked on #2905 (base staged-flow-more).

What it adds

Tcl in a Session

  • Session.tcl(script) runs a Tcl script in an interpreter that the session keeps. Every shell command is a Tcl command, written as on the command line of the shell, and runs through Session.command(), so the journal has what it changed. A command that answers in JSON returns its answer as a Tcl dict; a command that fails is a Tcl error that catch takes. Variables and procedures stay for the next script.
  • tcl(script, safe=True) runs it in a safe interpreter: no files, no programs, no ext_exec/source/yosys, and paths must stay in the current directory. tcl(script, fixed_width=True) refuses what fixed_width_refusal() refuses.
  • Failures are TclError/TclRefused with the output, the Tcl trace, the commands that ran and the diagnostics of the failed command (tcl_error, tcl_refused). In a RemoteSession the script runs in the worker and the errors cross the pipe as themselves.

Journal and memory of a worker

  • RemoteSession(journal=dir) has the worker write the journal of its session; a worker that starts again goes on with it without writing the restore twice. Session(resume_journal=True) does the same in a process.
  • The script of a yosys command is copied into the journal (scripts/001.ys, ...), so a replay runs the synthesis that ran.
  • RemoteSession(memory_limit_mb=...) limits the address space of the worker (RLIMIT_AS): a command that fills the memory fails with its allocation error and the worker goes on.

Tests

  • New: test_tcl (commands as Tcl commands, dict answers, journal, errors, safe interpreter, worker), test_worker_journal (journal of a worker and its restart, kept Yosys scripts and their replay, memory limit), and the Tcl refusals in test_fixed_width.
  • Full openfpga_flow/tasks/python_binding_tests and the ctest subset pass.

Not included

  • Running earlier stages on demand and opening saved sessions without a checkpoint belonged to the MCP server of the source branch, which is not part of OpenFPGA: they have no core part.

…a worker

RemoteSession(journal=directory) has the worker write the journal of its
session, as Session(journal=...) does. A worker that starts again (restart(),
a session opened again) goes on with the files that are there: the commands
of the restore are not written twice, and a call that ends with the worker
is not in it. Session(resume_journal=True) does the same in a process.

The script of a yosys command is copied into the journal (scripts/001.ys,
...) and the journal names the copy: the maker of a script often writes the
same file again for the next run, and a replay then runs the synthesis that
was run.

RemoteSession(memory_limit_mb=...) limits the address space of the worker
(RLIMIT_AS), for it and the workers that start again, so that a command that
fills the memory fails by itself with the error of its allocation, and the
worker goes on, instead of taking the machine with it.
Session.tcl(script) runs a Tcl script in an interpreter that the session
keeps, so that a loop or a sweep is one call. Every command of the shell is
a Tcl command, written as on the command line of the shell, that runs
through Session.command(): what it changes is in the journal, as if it had
been run from Python. A command that answers in JSON returns its answer as a
Tcl dict, and a command that fails is an error of Tcl, which catch takes.
The variables and procedures stay for the next script.

tcl(script, safe=True) runs the script in a safe interpreter: no files, no
programs, none of the commands that run other programs or scripts (ext_exec,
source, yosys), and the paths in the arguments must stay in the current
directory. tcl(script, fixed_width=True) refuses what
fixed_width_refusal() refuses. A script that fails raises TclError (or
TclRefused) with what it printed, the trace of Tcl, the commands it ran and
the diagnostics of the command that failed. In a RemoteSession the script
runs in the worker, and the errors cross the pipe as themselves.

Tcl comes with tkinter: a Python without it raises TclError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant