Skip to content

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

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