I'm using the Raspberry Pi Zero 2 W and I have one of the 4 cores dedicated to running the thread.
Currently the thread looks like this:I added some GPIO toggling and it looks like it is getting stuck on this part:
bytes_read = read(fd, buffer, RX_BUFFER_SIZE);
Normally it gets stuck here for a few ms, maybe 10 or sometimes close to 20 ms, but when I tried to run the program with this command:
sudo chrt 1 sudo -u $USER program
it got stuck at the same point routinely for like 800 ms.
I decided enough screwing around with this, I'm going to implement hardware flow-control now and hope that works for me. I've set aside a 100,000 byte buffer on the sender side, so that should give me about 40 ms of delay that it can handle. Thank you all for your help.
Currently the thread looks like this:
Code:
void *read_thread(void *arg) { int fd = *(int *)arg; unsigned char buffer[RX_BUFFER_SIZE]; int bytes_read; cpu_set_t cpuset; // Code to cause this thread to be run on CPU_ZERO(&cpuset); // a particular core. CPU_SET(3,&cpuset); // Add this to your thread functions with suitable parameter adjustments. sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); // while (1) { bytes_read = read(fd, buffer, RX_BUFFER_SIZE); if (bytes_read > 0) { // Lock the ring buffer pthread_mutex_lock(&ring_buffer.lock); // Write data to the ring buffer for (int i = 0; i < bytes_read; i++) { ring_buffer.buffer[ring_buffer.head] = buffer[i]; ring_buffer.head = (ring_buffer.head + 1) % RING_BUFFER_SIZE; ring_buffer.count++; // Check if the ring buffer is full if (ring_buffer.count == RING_BUFFER_SIZE) { // Overwrite the oldest data ring_buffer.tail = (ring_buffer.tail + 1) % RING_BUFFER_SIZE; } } if (ring_buffer.count > ringmax) ringmax = ring_buffer.count; // Unlock the ring buffer pthread_mutex_unlock(&ring_buffer.lock); } } return NULL;}
bytes_read = read(fd, buffer, RX_BUFFER_SIZE);
Normally it gets stuck here for a few ms, maybe 10 or sometimes close to 20 ms, but when I tried to run the program with this command:
sudo chrt 1 sudo -u $USER program
it got stuck at the same point routinely for like 800 ms.
I decided enough screwing around with this, I'm going to implement hardware flow-control now and hope that works for me. I've set aside a 100,000 byte buffer on the sender side, so that should give me about 40 ms of delay that it can handle. Thank you all for your help.
Statistics: Posted by KingJoffrey — Wed Apr 24, 2024 5:43 pm