USB Bulk Transfer inside native PostFrame Callback reduces latency and jitter #2168
Replies: 3 comments 1 reply
-
|
I'm not really sure what to do with this. If you want to report a bug in system behavior, go to https://b.android.com and file against the OS, probably the Framework component, or maybe System? The NDK only describes the interfaces of the OS, it doesn't define any of the behavior. Or is this just an observation and you're not looking for any help from me? |
Beta Was this translation helpful? Give feedback.
-
|
I found a phone where bulk transfer doesn't improve the latency. So the issue is probably on the system side — maybe related to the SoC hardware, USB driver, or OS-level behavior. |
Beta Was this translation helpful? Give feedback.
-
|
yeah, this is not unexpected ... it's common for usb activity to clock the cpu higher for reduced irq latency (for better usb performance). this, obviously, has side-effects for other code. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Observation:
Calling usb_device_bulk_transfer() inside AChoreographer_postFrameCallback_ (executed in a native, detached thread) significantly reduces both the delay and jitter of the frame callback itself.
This was measured by comparing the timestamp of the frame event (frameTimeNanos) and the actual execution time (clock_gettime(CLOCK_MONOTONIC)), with and without the USB transfer.
Setup:
NDK version "28.2.13676358"
From Java (JNI), I start a native thread (not UI) using pthread_create.
If USB bulk transfer IS NOT called - delay and jitter are higher. Values in nano seconds, second parameter callback_delay ~ 0.6 - 0.7ms
Here is log:
If USB bulk transfer IS called - delay and jitter are lower. Values in nano seconds, second parameter callback_delay ~ 0.2 - 0.3ms
Here is log:
In an isolated thread using AChoreographer_postFrameCallback_, I measured callback delay (how late the callback runs relative to vsync). The results are:
This is counterintuitive. One would expect a blocking USB call to increase delay, but it significantly improves timing instead. Possibly due to thread/CPU warm-up, cache effects, or internal scheduler behavior triggered by I/O. Further insights are welcome.
Additional Info:
usleep()(same duration) had no timing improvement. The effect appears specific to the USB bulk operation, not just timing delay.Beta Was this translation helpful? Give feedback.
All reactions