Skip to content
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

_sim_debug_flush(): Use fsync(). #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bscottm
Copy link
Contributor

@bscottm bscottm commented Mar 17, 2025

Fix race condition in _debug_fwrite_all() where the FILE *f output file can be permanently NULL, causing fwrite() to permanently return zero and resulting in an infinite loop on mulithreaded SIMH. This pathology primarily occurs when main thread calls flush_svc() and one of the Ethernet threads (reader, writer) emits debugging output.

Linux, macOS invoke fsync(). Windows invokes a fsync() wrapper that invokes _commit().

Issue traced to _sim_debug_flush() calling sim_set_deboff(0, NULL) to simulate fsync().

@bscottm
Copy link
Contributor Author

bscottm commented Mar 17, 2025

@pkoning2: Please merge PR #450 so that CI/CD can get past the LTO issue so that this and other builds have some chance at success (barring simulator test failures.)

@pkoning2
Copy link
Member

I'm a bit confused here. You pointed out that the simulated fsync can't be used in multithreaded simh. So why is it still in the code? If it's broken, would it not be more logical to remove it, especially since everyone has fsync?

@bscottm
Copy link
Contributor Author

bscottm commented Mar 17, 2025

I'm a bit confused here. You pointed out that the simulated fsync can't be used in multithreaded simh. So why is it still in the code? If it's broken, would it not be more logical to remove it, especially since everyone has fsync?

It can still be used for single threaded code, i.e., simulators that don't use AIO.

Also, I don't have a good handle on which platforms SIMH is supposed to support (the makefile seems to support a lot more than just Linux, macOS and Windows... Haiku? SunOS variants?) So, I left it in there as CYA.

Very happy to take it out and rewrite code to assume everyone has fsync(), except for Windows, which needs the diaper.

Fix race condition in _debug_fwrite_all() where the FILE *f output
file can be permanently NULL, causing fwrite() to permanently return
zero and resulting in an infinite loop on mulithreaded SIMH. This
pathology primarily occurs when main thread calls flush_svc() and
one of the Ethernet threads (reader, writer) emits debugging output.

Linux and macOS platforms invoke fsync() to synchronize file data to
disk. Windows has a fsync() wrapper calling _commit() providing the
same semantics.

Issue traced to _sim_debug_flush() calling sim_set_deboff(0, NULL) to
simulate fsync().
@bscottm
Copy link
Contributor Author

bscottm commented Mar 18, 2025

I'm a bit confused here. You pointed out that the simulated fsync can't be used in multithreaded simh. So why is it still in the code? If it's broken, would it not be more logical to remove it, especially since everyone has fsync?

@pkoning2: It's all just fsync now. If there's a platform out there that needs to be supported (VMS?), an issue is probably the best way to address it. Now back to the ETH_MAC * discussion...

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.

2 participants