-
Notifications
You must be signed in to change notification settings - Fork 4
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
Merge flush-in-batch capability #40
Conversation
The physical test "drive with two trains at the same time" for swtbahn-full seems relatively fragile regarding occupancy detection/misses, especially if the train's wheels are somewhat dirty. As far as I can tell, these issues are not related to the flush-in-batch changes. -> Improve physical tests. |
Issue seems to go deeper - from time to time, the whole application locks up. I don't know if its because of lock contention or something else. If any, the trackstate rwlock seems to be the problem, which is not surprising as it has to be locked extremely often. However, I can't rule out external influences of e.g. the raspberry pi. -> not sure what is actually blocking. |
Trying to analyze it with gdb -> problem doesn't occur when running via gdb. WTF. |
I rewrote the guard mechanism for the trackstate members - now there is one mutex per trackstate member, except for points and signals which are grouped together. Until now, we had one lock for the whole trackstate collection, which is very corse. The change from a read-write lock to a mutex was to keep it a bit simpler - with this more fine grained access control, I don't think we need the parallel read capability anymore for the trackstate. |
I implemented a good part of the trivial requested changes and marked the corresponding conversations as resolved. |
One more change I would like to perform: When I return to the codebase after a longer break, I'm sometimes confused by the naming - |
…pies for state.data.state_id members of various kinds
Tested the memory-related changes with Valgrind, fixed leaks accordingly. |
@BLuedtke What SWTbahn platform did you test the code on? On the SWTbahn Lite, I remember the Linux GUI freezing every so often for a few seconds, but couldn't figure out why. This was happening even when I was only navigation through folders. |
So far, I've always been testing on the swtbahn-full. |
One more thing I could try is to switch to the realtime kernel and see if the freezes still occur. |
…in bidib_state_setter overall
the heartbeat thread/log causes the tests to take a bit longer, as when joining it might be in a sleep(2). Will see how that could be fixed. |
…and order improved
…only on floats/reals)
Heartbeat problem fixed by dividing the long sleep into several 0.1s ones and checking if bidib is still running. The read-write locks I wrote about earlier have been renamed. I think that's all for this pull request. |
Changes look good |
Closes #39
So far, when
bidib_flush
was called (bidib_transmission_send.c), the content of the send buffer would be written byte-by-byte. This results in onewrite
system call per byte (see the bidib_serial_port_write function). However,write
is perfectly capable of writing more than one byte at a time.I therefore added a
write_n
("write n bytes") analogue to thewrite
call we have used so far. However, we cannot simply pass the buffer and the buffer size towrite_n
as-is, because bytes for escaping and the crc (checksum) have to be inserted somewhere in the buffer. Various ways of dealing with this have been benchmarked, see this comment here. One of the solutions turned out to be superior, specifically the one using an auxilliary statically allocated buffer.The old byte-by-byte flushing is still present, in case it is needed as a fallback (e.g., if the auxilliary buffer is too small, though I don't expect this to happen).
In addition to the write-stuff, I also added some logging if received packet processing takes longer than a certain threshold. Not directly related, but it was due to be added anyhow IMO.
I want to re-run the physical tests a few times before merging, but I think the code is ready to review anyway.