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

rtio: completion queue event count overflow #81802

Open
JordanYates opened this issue Nov 23, 2024 · 1 comment
Open

rtio: completion queue event count overflow #81802

JordanYates opened this issue Nov 23, 2024 · 1 comment
Assignees
Labels
area: RTIO bug The issue is a bug, or the PR is fixing a bug

Comments

@JordanYates
Copy link
Collaborator

Describe the bug

The internal counter used to keep track of completion queue accounts is only ever incremented, never decreasing.

atomic_inc(&r->cq_count);

This counter is used by rtio_submit to determine when the submission has completed:

uintptr_t cq_count = (uintptr_t)atomic_get(&r->cq_count) + wait_count;

while ((uintptr_t)atomic_get(&r->cq_count) < cq_count) {
Z_SPIN_DELAY(10);
k_yield();
}

A typical RTIO I2C transaction might like the following:

  1. rtio_sqe_prep_tiny_write
  2. rtio_sqe_prep_read
  3. rtio_sqe_prep_callback_no_cqe`

So 2 CQE events per I2C transaction. If there were 50 I2C transactions per second, this counter would overflow in ~250 days (2**31 / 50 / 2 / 86400).

Increasing or decreasing the I2C transaction rate would scale the overflow duration linearly.
At overflow, the second check will pass immediately:

cq_count = INT32_MAX + 1; // INT32_MIN
while(INT32_MAX < INT32_MIN) {
   // Never enters
}

Expected behavior

Internal counter overflow should either be detected and handled, or reset in some way through atomic_dec.

Environment (please complete the following information):

  • Zephyr v4.0
@JordanYates JordanYates added bug The issue is a bug, or the PR is fixing a bug area: RTIO labels Nov 23, 2024
@teburd
Copy link
Collaborator

teburd commented Nov 23, 2024

We need the counter to know when to return, so detecting the rollover is expected and should already work. Agreed a test should show this working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RTIO bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

2 participants