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

Get start timestamp and add it to header #34

Merged
merged 4 commits into from
Mar 3, 2023
Merged

Conversation

EmilioPeJu
Copy link
Contributor

This requires that the readers wait for the start of the acquisition.

struct timespec doesn't match the timespec we get from the kernel module, on top of that, it could have different sizes in 32-bit and 64-bit architecture, a cast between an intermediate structure was used to workaround this.

This fixes #7

Copy link
Contributor

@Araneidae Araneidae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but we'll need to discuss the buffer changes, I don't understand the significance of the change you've made here to buffer.c.

server/sim_hardware.c Outdated Show resolved Hide resolved
Comment on lines 146 to 147
if (!ts_captured)
release_write_block(data_buffer, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. If this is needed it's addressing an outstanding bug, so I'd expect the condition should be count == 0, as a missing release_write_block will happen any time the capture end on a timeout. Also, there is an indentation error here!

Maybe end_write is papering over the cracks here and triggering the missing release_write_block, because we haven't seen a problem with this before ... or have we?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see from the commit message that this is an outstanding bug. Then maybe there should be a guard in end_write against this, either silently (or with a warning) perform the missing release, or just an assert fail.

Comment on lines +306 to +307
while (!buffer->released_once && !buffer->shutdown)
pwait_deadline(&buffer->mutex, &buffer->signal, &deadline);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm. Think we'll need to talk about this, don't understand what this is all about, why it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what is making the reader wait for the start event, otherwise the header will be sent before the start timestamp was captured

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Hmm. Not sure I like this.

So we have two timeouts ticking away, one in the kernel interface, one in the buffer, but we're blocking the buffer timeout until the experiment has triggered.

Guess this is the right way.

driver/panda_stream.c Show resolved Hide resolved
driver/panda_stream.c Outdated Show resolved Hide resolved
@EmilioPeJu EmilioPeJu force-pushed the ts-cap-interrupt branch 4 times, most recently from f453437 to f6fb2ad Compare March 2, 2023 19:40
Copy link
Contributor

@Araneidae Araneidae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver macro can be tidied up a little, but the rest of my comments are mostly me thinking aloud; this is fine.

#define IRQ_STATUS_DMA_ACTIVE(status) ((bool) ((status) & 0x80))
#define IRQ_STATUS_COMPLETION(status) ((size_t) (((status) >> 1) & 0x0F))
#define IRQ_START_EVENT(status) ((bool) (status & 0x100))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot: we need brackets around (status) for macro safety!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for consistency might be better to call this macro IRQ_STATUS_START_EVENT to match the other status register interrogation macros.

@@ -282,6 +290,8 @@ static void start_hardware(struct stream_open *open)
open->isr_block_index = 0;
open->read_block_index = 0;
open->read_offset = 0;
// having a zeroed timestamp means the start event did not happen
open->start_ts = (const struct timespec64){0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this makes sense, and ensures that each time we arm the timestamp is reset.

Comment on lines +146 to +147
if (!ts_captured)
release_write_block(data_buffer, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. On the face of it the condition !ts_captured should be replaced with count == 0, as each call to get_write_block ought to be balanced by a call to release_write_block, and this call will be omitted any time the loop above exits with count equal to 0.

On the other hand, get_write_block doesn't actually have any side effects, and calling release_write_block will trigger an empty update to the reader. Still, I think I'd prefer a form that looks correct locally.

// We are using this to convert to a stardard timespec in a way that we are
// compatible with 32-bit and 64-bit architectures, however, we will not
// need it when we update to a newer glibc (which contains __timespec64)
struct timespec64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to switch on the architecture version and use that version if it exists? This is quite a nasty hack...!

Comment on lines +306 to +307
while (!buffer->released_once && !buffer->shutdown)
pwait_deadline(&buffer->mutex, &buffer->signal, &deadline);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Hmm. Not sure I like this.

So we have two timeouts ticking away, one in the kernel interface, one in the buffer, but we're blocking the buffer timeout until the experiment has triggered.

Guess this is the right way.

@EmilioPeJu
Copy link
Contributor Author

It is worth mentioning that this change comes together with PandABlocks/PandABlocks-FPGA#110

This bug was already present before, but because PCAP timeouts happens
every 100ms, it was hard to reproduce, now that a buffer reader waits for
the start of the capture, it is easier to get this bug.
@EmilioPeJu EmilioPeJu merged commit ab47acb into master Mar 3, 2023
@EmilioPeJu EmilioPeJu deleted the ts-cap-interrupt branch March 3, 2023 12:11
@coretl coretl mentioned this pull request Nov 7, 2023
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.

Add timestamp to header
2 participants