Skip to content

interp: let go of the kinematics HAL component at exit - #4891

Open
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:interp-exit-release
Open

grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:interp-exit-release

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

The interpreter attaches a HAL component, interp.<pid>, the first time it evaluates the kinematics (G68.2, the G53.x codes, G43.5, a move checked against the joint limits). It released it only in its destructor, and task exits without destroying the interpreter. The component outlived milltask, so the linuxcnc script's shutdown waited out its 2 s loop for every component to go.

Interp::exit(), which task calls at shutdown, now releases it. A later use loads it again.

I added no test, since the change is in how long shutdown takes. Measured: tests/ptp-robot, which evaluates the kinematics, takes 1.9 s instead of 3.9 s; a test that never evaluates them is unchanged. The suite passes.

The interpreter attaches a HAL component, `interp.<pid>`, the first time
it evaluates the kinematics, and releases it only in its destructor.
Task exits without destroying the interpreter, so the component
outlived milltask and the linuxcnc script's shutdown waited out its
2 s loop for it.  Interp::exit() now releases it; a later use loads it
again.

tests/ptp-robot, which evaluates the kinematics, takes 1.9 s instead of
3.9 s.
@BsAtHome

Copy link
Copy Markdown
Contributor

In kins_release you have:

if (s->kins_comp_id > 0) {
hal_exit(s->kins_comp_id);
s->kins_comp_id = 0;
}
}

The problem is that a component ID of zero (0) is actually a valid component ID. Not likely you'd ever see it, but valid. Normally, this field is initialized with -1 to denote error or no component yet allocated.

HAL component id 0 is valid, so 0 cannot stand for "none". Start kins_comp_id at -1 and release any id >= 0.
@grandixximo

Copy link
Copy Markdown
Contributor Author

Right, thanks. That came in with #4842; 0 was the "none" marker. I pushed a commit on this PR that starts kins_comp_id at -1 and releases any id >= 0.

@BsAtHome

Copy link
Copy Markdown
Contributor

No prob...
However, the use of a HAL component in the kinematics-interpreter interaction has now cemented the use of HAL into the interpreter. It can no longer run without linking to liblinuxcnchal.so. That means that a stand-alone interpreter is no longer a viable option.

@grandixximo

Copy link
Copy Markdown
Contributor Author

The link itself is not new: librs274 has linked liblinuxcnchal since _hal[pin] went in (2011). What is new is that G68.2, the G53.x codes and G43.5 need HAL running to read the kinematics geometry from the module's pins; sai reports identity kinematics and skips that, so plain G-code still runs standalone.

I agree the interpreter should not carry it, though. The cleaner shape is to ask canon for the kinematics, like GET_EXTERNAL_KINEMATICS_IDENTITY() already does, and let task (which loads the same module already) answer. I would do that as a follow-up rather than in this PR, if that works for you.

@BsAtHome

Copy link
Copy Markdown
Contributor

The #<_hal[pinname] dereference can also be solved using the canon interface.
See also #4852 (comment)
Probably best to handle that one too in the same go.

Then we can retry to enable tests/interp/compile and see what is still missing/off.

@grandixximo

grandixximo commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes, but holding canon changes for @rene-dev #4830 ...

@rene-dev

Copy link
Copy Markdown
Member

Thanks, I will fix the outstanding todos on that one tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants