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

msgq: connect immediately #588

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

msgq: connect immediately #588

wants to merge 4 commits into from

Conversation

sshane
Copy link
Contributor

@sshane sshane commented Feb 15, 2024

When the publisher is created, it calls msgq_init_publisher which resets the reader count. If you send data (in msgq_msg_send) before the subcriber connects, you will have no readers to signal to here:

https://github.com/commaai/cereal/blob/bd31b25aacc5b39f36cedcb0dabd05db471da59f/messaging/msgq.cc#L295-L299

This PR finds all current readers and sends a SIGUSR2 signal. Verified that the subscriber polling doesn't finish early when a publisher is created.


Subscriber
from cereal.messaging import SubMaster, PubMaster, new_message, sub_sock
from cereal import log
import time

sock = sub_sock('sendcan')
sock.setTimeout(100)

t = time.time()
while True:
  print('recv', sock.receive())
  print(time.time() - t)
  print()
Publisher
from cereal.messaging import PubMaster, new_message
from cereal import log
import time

times = []

for _ in range(1000):
  pm = PubMaster(['sendcan'])
  t = time.monotonic()
  while 1:
    if pm.sock['sendcan'].all_readers_updated():
      times.append(time.monotonic() - t)
      break

print(times)
print(sum(times) / len(times))

Time for all readers to connect (should be half of subscriber dt on average):

0.05434682522984804 mean, 0.049833057644082523 std

After change:

2.469095983542502e-06 mean, 7.680831147408531e-07 std

messaging/impl_msgq.cc Outdated Show resolved Hide resolved
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.

1 participant