-
Notifications
You must be signed in to change notification settings - Fork 127
_sim_debug_flush(): Use fsync(). #454
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
base: master
Are you sure you want to change the base?
Conversation
7df5086
to
e6a4d44
Compare
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 Very happy to take it out and rewrite code to assume everyone has |
e6a4d44
to
2e6a571
Compare
@pkoning2: It's all just |
* | ||
* f == NULL: fwrite() returns 0 on Linux and Windows. len never gets decremented | ||
* and an infinite loop ensues (cue "Forever NULL" sung to the tune of Alphaville's | ||
* "Forever Young".) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply treat length written == 0 as an error? But in my testing, a NULL file pointer causes a segfault (on recent Linux as well as on Mac OS).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkoning2: I left the "dragon" note as more of a "Don't Do This" warning. I added extra checks deal with the f == NULL
,len_written == 0
and errno != EAGAIN
cases. In each case, SIMH outputs a diagnostic message (the "why") and the buffer's contents that weren't written to the debug output.
af23c88
to
072fe53
Compare
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().
072fe53
to
43407a0
Compare
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().