-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VHPIDIRECT callback on simulation termination #894
Comments
Hi @vdkeybus! Can you please provide a minimal example of what you are trying to achieve? I believe that the problem you are having is related to the version of VHDL that you are using. The behaviour is very different with With VHDL 93, when the simulator exits cleanly, you can use However, when the simulation is finished with a failure in VHDL 93, you can get an abortion. In this context, SIGABRT can be used as a handler, as shown in https://github.com/VUnit/vunit/blob/36d63f1645ae64b3de86142579433a9c5feaee7a/examples/vhdl/external_buffer/sigabrt.md. This approach is limited, tho. For example, if the GHDL binary is loaded and executed from Python, there seems not to be possible to execute any Python cleanup code after the abortion of GHDL (see VUnit/vunit#469 (comment)). Note that the abortion is not expected. It is being tracked in #803, but the issue has not been updated since april. It might be worth trying with latest |
@1138-4eb I am going to try the atexit() solution you propose. I wasn't aware you could use it. I'll try to catch SIGABRT for good measure too. So the feature already exists. That's good. I'm now wondering, are FAILURE assertions actually implemented using signals ? So, could I also terminate a GHDL run that way from C ? BTW thanks for analyzing my request and compiling the elaborate response. Is there a way we can include this kind of useful information in the foreign language manual section ? |
In practice,
Note that this is likely to be a bug. According to @tgingold, ghdl should not exit with an abortion, not even after a simulation failure. See #800 (comment). So, it is probably not ghdl who is producing the signal, but some other OS logic in-between C main and ghdl_main. Nonetheless, I think you should be able to terminate a GHDL run that way from C. I mean, this is not dependent on ghdl's codebase but on the context/system that loads the function, isn't it?
You are welcome.
Actually, I'm the one who did latest updates to that section: https://github.com/ghdl/ghdl/blob/master/doc/using/Foreign.rst#id4. I'd be glad to review a PR if you are willing to propose it. I have not added it myself yet because I'd like to investigate the abortion issue further. Nevertheless, it is ok to add it with some hint/warning if you think this is useful. |
There is the endofsimulation vpi/vhpi callback for this purpose. That's heavier to use than a vhpidirect function but that's the standard way. |
I need to have a look into these callbacks, since I was under the
impression that they were not intended to be used in entities / as
components. I need something lightweight that provides input to a
simulation on regular time instants.
Thanks,
Op vr 16 aug. 2019 om 09:04 schreef tgingold <notifications@github.com>:
… There is the endofsimulation vpi/vhpi callback for this purpose. That's
heavier to use than a vhpidirect function but that's the standard way.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#894?email_source=notifications&email_token=ABSNXH6WXXRYKVHHUT4HSBDQEZGPJA5CNFSM4IL43DDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4N3HII#issuecomment-521909153>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABSNXH6RJVXK2TZBYZS45M3QEZGPJANCNFSM4IL43DDA>
.
|
Is your feature request related to a problem? Please describe.
When using a foreign language interface (VHPIDIRECT), it is possible to do some initialization e.g. at the beginning of a process. However, there's no easy way to detect that a simulation ends. That would be useful to close files or sockets, free malloc'ed memory or print a final diagnostic message.
Describe the solution you'd like
Could an attribute be added like:
attribute foreign of function : procedure is "VHPIDIRECT_EXIT <function_exit>";
that causes function_exit() to be called before termination ?
Describe alternatives you've considered
You can track 'now' as a variable in your foreign function / procedure. But then you'd have to keep in sync with --stop-time, and be unable to get final foreign function output upon a FAILURE assertion.
Additional context
Get rid of dirty termination of foreign code.
Thanks.
The text was updated successfully, but these errors were encountered: