How to debug lag using Bluetooth connected mouse and A2DP headset?

9,931

I've had some luck using USB tracing to solve strange audio problems. Sometimes you can determine something from the content, or the timing of packets. In my case it was an occasional change in the packet length corresponding to noise I was hearing.

Here's a page from Wireshark that provides some information.

You can get a trace simply by doing the following:

  1. sudo modprobe usmon
  2. cd /sys/kernel/debug/usb/usbmon
  3. sudo cat 0u | tee ~/myusbtrace > /dev/null
  4. run your test
  5. kill the process from step 3

Here is information from the linux project about this, including how to narrow down what you are tracing.

The second column appears to contain the time, so you should keep a careful watch on how it increments. If it starts smooth and later gets jumpy the problem may be in the bluetooth section.

If the trace shows irregular packets when there is a problem that could be either USB or bluetooth, but the direction of the irregular packets may indicate whether it is the kernel or driver rather than something on the other side of the USB bus.

Share:
9,931

Related videos on Youtube

gertvdijk
Author by

gertvdijk

FOSS enthousiast, Developer, Debian GNU/Linux (and Ubuntu) user, DevOps with Ansible/Pupppet powers, Coding in C/C++/Python. Keywords: Linux, KVM/Libvirt, Kubernetes, Ansible, Docker, Python, a bit of C/C++/Kotlin, Debian, Ubuntu, Apache, Kopano, Postfix, MySQL, PostgreSQL, Kafka, security, KDE, SSL/TLS. Every now and then I'll write an article on those topics my blog. Other sites I'm active on: Launchpad, Tweakers.net, Twitter, LinkedIn

Updated on September 18, 2022

Comments

  • gertvdijk
    gertvdijk almost 2 years

    I own a Logitech M555b mouse for use with my HP Elitebook 8570w laptop running Kubuntu 12.04. Works fine right after connecting using the KDE Bluetooth control module.

    However, after some time (seemingly random), it starts to lag. Movements are being delayed for roughly 500ms for a short period of time. Usually it recovers after some time too, but it can take minutes. All actions are being delayed: movements, click, scrolls. Additionally, the movements can be choppy during these times.

    A workaround that always works for the same short period of time is to disconnect an re-connect the mouse. This can be done using the same KDE Bluetooth control module.

    What did I try already?

    • Running this at boot time:

      echo on > `readlink -f /sys/class/bluetooth/hci0`/../../../power/level
      

      To disable any power saving features on the Bluetooth hci0 device.

    • Check the mouse's batteries (it's just a week old, other new batteries: same result)

    • Checking logs and kernel messages about Bluetooth-related entries: none aside the expected messages on connect time.
    • I'm running kernel 3.5.0-13-generic as provided in the xorg-edgers PPA. Booting the regular 3.2 Precise kernel results in the same behaviour.

    Some other information that may help:

    • It happens when no other Bluetooth connections are active on the machine.
    • Similar symptoms also occur on my Bluetooth stereo (A2DP) headset, but then it's audio lagging and skipping. Swapping Bluetooth profiles as described here then helps. Conclusion: it's not the mouse that's faulty.
    • The headset always worked fine using my now dead Thinkpad T61p with built-in Bluetooth.
    • The bluetooth module in my laptop is connected via USB and shows up as

      0a5c:21e1 Broadcom Corp. 
      
    • Turning the built-in Bluetooth adapter off and using another one works fine, without lag.

      0a5c:2046 Broadcom Corp. Bluetooth Device
      

    I'm mobile and several people around me are using Bluetooth at work (A2DP mostly). It also occurs at home, where my neighbours are probably using Bluetooth as well. It could just be radio interference, but I think Bluetooth connections should just hop to another channel. And, moreover, it just works properly instantly when re-connecting.

    Therefore I think it's a software driver issue and I'd like to debug it. Is there any way to get more verbose logging on the Bluetooth(-hid) modules?

    • Admin
      Admin almost 12 years
      Until I replaced by motherboard, I had a bad USB port on my computer. Have you tried using a diferent one for plugging in your bluetooth module? You might also try taking your computer for a ride to the country, turn off your car and cell phone, and see if it is still a problem in the absense of RF interference.
    • Admin
      Admin over 11 years
      I've found an older Bluetooth 2.0 USB dongle and this one works like a charm. Seems like a specific 0a5c:21e1 Broadcom Corp. problem in Linux.
    • Admin
      Admin over 11 years
      Another update about the original issue. Ever since I'm on Linux kernel 3.7.x this seems vanished on the internal adapter as well - all works very well. Probably hit a bug here now fixed. Once I have time to figure out some more details I'll report this as a bug.
  • Admin
    Admin almost 12 years
    Thanks! Peculiar about this is that the while running the hcidump the issue does not appear. Also, the moment I start running it, the issue vanishes immediately. This debugging probe seems to make in irreproducible.
  • gertvdijk
    gertvdijk almost 12 years
    Very helpful, thanks. Would have offered a small bounty if that would be possible. :)