Agere: 8 bulk transfers in flight each way; the IN round trips timed in the log

The device starts its next IN packet only once the last has gone; with
Agere's driver's 2 in flight an app's round trip through libusb seems to
leave it waiting (2459 samples a second, at every ARM clock). The log's
transfer counts now say how long the IN transfers take to come back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
Claude committed 2026-10-26 07:07:09 +00:00
1 parent 3e705c6e73
commit 75cd6b0370
4 files changed
+43 -6

No files matched your search

+1 -1
View File
@@ -113,7 +113,7 @@ int UsbModem::run()
u64 now = dcore::monotonic_ms();
if (now >= next_say) {
u64 wall = now - t0, clock = line_->now_ms();
char stats[256];
char stats[384];
usb_transfer_stats(stats, sizeof(stats));
if (!warned && clock < wall / 2) {
ERR("usb: the modem's samples %s: its clock %llu ms "
+37 -2
View File
@@ -10,6 +10,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <time.h>
#include <unordered_map>
@@ -24,6 +25,18 @@ struct Way {
int last_status = 0;
};
Way in_, out_;
/* the IN transfers' round trips (sent to back) and the longest gap
between two coming back, since the last usb_transfer_stats() */
std::unordered_map<libusb_transfer *, uint64_t> sent_at_;
uint64_t trips_ = 0, trip_us_ = 0, trip_max_us_ = 0, gap_max_us_ = 0, last_back_us_ = 0;
uint64_t now_us()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return static_cast<uint64_t>(ts.tv_sec) * 1000000u +
static_cast<uint64_t>(ts.tv_nsec) / 1000u;
}
/* the first IN transfers back: logged, their octets' head */
const int IN_SAID = 3;
int in_said_ = 0;
@@ -39,6 +52,20 @@ void LIBUSB_CALL counted(libusb_transfer *t)
{
Way &w = is_in(t) ? in_ : out_;
w.done++;
if (is_in(t)) {
uint64_t now = now_us();
auto s = sent_at_.find(t);
if (s != sent_at_.end()) {
uint64_t trip = now - s->second;
trips_++;
trip_us_ += trip;
if (trip > trip_max_us_)
trip_max_us_ = trip;
}
if (last_back_us_ && now - last_back_us_ > gap_max_us_)
gap_max_us_ = now - last_back_us_;
last_back_us_ = now;
}
if (t->status == LIBUSB_TRANSFER_COMPLETED) {
w.octets += static_cast<uint64_t>(t->actual_length);
/* (an isochronous one's are its packets') */
@@ -74,6 +101,8 @@ void usb_transfers_reset()
out_ = Way();
in_said_ = 0;
callbacks_.clear();
sent_at_.clear();
trips_ = trip_us_ = trip_max_us_ = gap_max_us_ = last_back_us_ = 0;
}
void usb_transfer_stats(char *buf, size_t len)
@@ -82,11 +111,15 @@ void usb_transfer_stats(char *buf, size_t len)
"IN %" PRIu64 " sent, %" PRIu64 " back (%" PRIu64
" octets, %" PRIu64 " failed, last %d)%s; "
"OUT %" PRIu64 " sent, %" PRIu64 " back (%" PRIu64
" failed, last %d)%s",
" failed, last %d)%s; IN round trips %.1f ms, at most %.1f, "
"the longest wait %.1f",
in_.sent, in_.done, in_.octets, in_.failed, in_.last_status,
in_.refused ? ", some refused" : "",
out_.sent, out_.done, out_.failed, out_.last_status,
out_.refused ? ", some refused" : "");
out_.refused ? ", some refused" : "",
trips_ ? trip_us_ / 1000.0 / static_cast<double>(trips_) : 0.0,
trip_max_us_ / 1000.0, gap_max_us_ / 1000.0);
trips_ = trip_us_ = trip_max_us_ = gap_max_us_ = 0;
}
} // namespace dmodem_android
@@ -99,6 +132,8 @@ int dmodem_libusb_submit_transfer(struct libusb_transfer *t)
callbacks_[t] = t->callback;
t->callback = counted;
}
if (is_in(t))
sent_at_[t] = now_us();
int err = libusb_submit_transfer(t);
Way &w = is_in(t) ? in_ : out_;
if (err == 0)
@@ -73,8 +73,10 @@ object UsbModems {
if (!out.exists() || !out.readBytes().contentEquals(bytes)) out.writeBytes(bytes)
}
android.system.Os.setenv("DMODEM_AGERE_FIRMWARE", dir.path, true)
// (while the Agere is brought up: its samples' rate at each ARM clock, logged at start, ~13 s)
android.system.Os.setenv("DMODEM_AGERE_CLOCK_SWEEP", "1", true)
// (8 bulk transfers in flight each way, not Agere's driver's 2: a packet is 6 ms, and the
// device starts the next only once the last has gone, so an app's round trip through libusb
// must not leave it waiting)
android.system.Os.setenv("DMODEM_AGERE_TRANSFERS", "8", true)
return dir
}