-
Notifications
You must be signed in to change notification settings - Fork 9
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
Bootloader very slow when using cpp link #10
Comments
If we try to avoid holding the mutex across From aa226b89b569567ab465324d3ae2f2c408b18958 Mon Sep 17 00:00:00 2001
From: Jonas Danielsson <[email protected]>
Date: Tue, 11 May 2021 09:57:27 +0200
Subject: [PATCH] wip-mutex-foo
---
src/CrazyradioThread.cpp | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/CrazyradioThread.cpp b/src/CrazyradioThread.cpp
index 9a8cad2..d8f840b 100644
--- a/src/CrazyradioThread.cpp
+++ b/src/CrazyradioThread.cpp
@@ -224,21 +224,31 @@ void CrazyradioThread::run()
}
} else {
// no safelink
- const std::lock_guard<std::mutex> lock(con->queue_send_mutex_);
if (!con->queue_send_.empty())
{
- const auto p = con->queue_send_.top();
- ack = radio.sendPacket(p.raw(), p.size());
- ++con->statistics_.sent_count;
- if (ack)
+ Packet p;
{
+ const std::lock_guard<std::mutex> lock(con->queue_send_mutex_);
+ p = con->queue_send_.top();
con->queue_send_.pop();
+ ++con->statistics_.sent_count;
+ }
+
+ ack = radio.sendPacket(p.raw(), p.size());
+
+ if (!ack)
+ {
+ const std::lock_guard<std::mutex> lock(con->queue_send_mutex_);
+ con->queue_send_.push(p);
}
}
else if (con->useAutoPing_)
{
ack = radio.sendPacket(ping, sizeof(ping));
- ++con->statistics_.sent_count;
+ {
+ const std::lock_guard<std::mutex> lock(con->queue_send_mutex_);
+ ++con->statistics_.sent_count;
+ }
}
}
--
2.30.2 Then the difference seem to go away:
Is this a safe change? |
I am still a bit surprised by the very large time difference. Are we sure that the Python bindings are actually build in release mode? |
This is happening with the release build from PyPi which should be release. Furthermore it does seems to be fixed in #11 in debug or release mode. This really behaved like lock contention (ie. random throughput) and not like a slow debug build. |
When using the cpp link, bootloading a Crazyflie is very slow:
The behavior seems to come from send packet that can either take 1 seconds or run in quick bursts of ~30 packets. This looks like mutex contension so I tried commenting this mutex lock:
crazyflie-link-cpp/src/CrazyradioThread.cpp
Line 227 in e6043eb
Why does this mutex exists? I though there was only one thread accessing each radio which means that radio access would not need to be protected by a lock. I will continue investigating, tell me if you have any though @whoenig.
The text was updated successfully, but these errors were encountered: