Input Lag Issue - USB xHCI Driver Inner Workings

Discussion in 'Operating Systems' started by ZeeMonning, Apr 15, 2023.

  1. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    So I'm been having this input lag issue, and I think I've traced it to the xHCI - theoretically the driver, it shouldn't be a hardware issue based on my experiments.

    The symptom seems to be input lag on an initial mouse action after a (can be very brief) pause. For example, if you're playing an FPS game and you are holding a corner, not moving or clicking the mouse, a dude peaks and you either click or flick, there seems to be a brief (possibly inconsistent?) delay, which ruins reaction time and throws off aim.

    I know this is an issue because I've been able to remove it before (e.g. on the initial install of the mouse or modifying the xHCI parameters in the registry), but it isn't permanent.

    I can't say if it affects any other aspect of the mouse, if I continuously move the mouse things seem to be fine, but obviously it is near impossible to gauge an opponents vector while making circles with the mouse, let alone get the dot on him as fast as possible.

    My best guess as to what is the root cause is some sort of power saving feature. Like the link gets put into some from of 'idle' state (from the xHCI's side, probably a feature that doesn't require support from the endpoint device) when the mouse isn't doing anything.

    I probably need someone with a good knowledge of how the xHCI driver works, what states a device can be put into, what states a device supports, 'hidden' power saving features, register layout, etc.

    My main source (It's not a document on one of my xHCIs, but it's the only one I could find online).
    Intel eXtensible Host Controler Interface USB xHCI

    I use RW-Everything to read/write registers.

    Specs and such:
    OS: Windows 10 Pro - Current Version: 10.0.19045
    xHCI 1 (VIA): VEN_1106&DEV_3484 - Driver: Microsoft 10.0.19041.2546
    xHCI 2 (ASMedia): VEN_1B21&DEV_1343 - Driver: ASMedia 1.16.28.1
    xHCI 3 (AMD): VEN_1022&DEV_149C - Driver: Mocrosoft 10.0.19041.2546
    Mouse: HyperX Pulsefire Core - Driver: 10.0.19041.1 (It looks like this mouse doesn't support USB 2 LPM-L1)
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
  3. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    Tried all these already. I have tried every 'obvious' USB related power option, I am at the point where I need to modify USB controller registers, the issue is finding the correct ones. There is the smallest chance there is a setting I missed but it will almost definitely appear to be unrelated to USB.

    I will check this out but I'm 70% sure the 3+ other programs I've downloaded to try and check this out will have covered everything this software covers.
    I've tried almost all the ports on my PC and PCIe cards already, no difference, this is not a port issue, it is an xHCI issue.
     
  4. Astyanax

    Astyanax Ancient Guru

    Messages:
    17,011
    Likes Received:
    7,351
    GPU:
    GTX 1080ti
    get rid of the asmedia driver, nobody should be using them anymore.
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
  6. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    Source?
    I'm using their driver because that was the only non-Microsoft USB driver that would install (funny enough, I'm pretty sure it is technically a Windows 7 driver). I need a variety of drivers to be the most efficient at finding a solution to my problem.

    I have, they will not install. I had been on Google for hours trying to find a way to manually install a driver with the .inf, but nothing worked, Windows will not accept it over their own driver. If you know how, please enlighten me.

    This shouldn't be a driver problem, but even if it is I need to figure out the root cause. If I can't trust one driver developer, I probably shouldn't trust any.
     
  7. Astyanax

    Astyanax Ancient Guru

    Messages:
    17,011
    Likes Received:
    7,351
    GPU:
    GTX 1080ti
    the only driver you need is the microsoft driver
     
  8. rflair

    rflair Don Coleus Staff Member

    Messages:
    4,854
    Likes Received:
    1,725
    GPU:
    5700XT
    You could try DriveStoreExplorer to force install a driver.

    https://github.com/lostindark/DriverStoreExplorer

    It may or may not work, it will at least let you install the driver, if Windows will let you switch to it I don't know.

    Its a good program none the less, will get rid of multiple driver entries that Windows may trip over.
     
  9. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Installing (upgrading) driver through Device Manager looks more safe - it can refuse in case of total incompatibility.
     
  10. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    Well, Device Manager has been the one that's letting me down. I try to manually install the other driver and it says, 'The best drivers for your device are already installed', so that obviously won't work.

    I'll check out DriverStoreExplorer, and I will make sure to proceed with caution.

    What are multiple driver entries? Is it like two drivers on the system that are both being used on the same device?

    I don't know if I will risk installing an 'unknown' driver quite yet, I'm not at all convinced this is an issue with a specific driver, Microsoft and ASMedia drivers are doing the same thing for one, and most if not all (really good) gamers I know use Microsoft's with no issues at all.

    I did find out some interesting things though. It looks like none of my USB devices ever go into a state other than the active state U0 (or L0 for USB 2). The xHCI seems to always be running (run bit always true), tried to test this by plugging my headset into the same controller, no difference.

    Where it gets interesting is I noticed the ASMedia xHCI seemed like it worked better than the others, but only occasionally, enough to notice but little enough I thought it was placebo. I was looking through the registers on the ASMedia and I noticed the interrupter registers for the Event Ring Segment Table were changing about every second when the mouse is not being used. On the other controllers this value doesn't change when the mouse is not in use. When the mouse is being used, those registers are constantly changing, it seems like they are somehow related to events being sent/received. If anyone can confirm or correct that assumption, that would be great.

    That made me wonder if I was actually seeing improved performance on the ASMedia, not placebo. Maybe it had a one second heartbeat that helps prevent the link from idling all the time or something like that. So I opened NGenuity (HyperX's peripheral software) and just let it run in the background. Now the Event Ring Segment Table registers are always changing, at a pretty fast rate, too. No idea how fast, but I'd guess less than every 10ms. I tested it out, and weirdly enough, it did feel a bit better, but it also felt a lot rougher (and inconsistent), like my framerate was around 100 instead of the 200+ my counter was showing. I'm wondering if NGenuity's constant communication was causing that, like some form of bottleneck.

    I did some research to see if USB has some form of heartbeat, and it appears it does. It looks like all USB devices have to support a suspend (as I understand it, this is completely different form selective suspend, which I have disabled). The suspend will activate if no activity is seen in 3ms. There is also a heartbeat (keep alive), SOF (Start of Frame). It looks like the typical rate for that is 1ms, but it also looks like it is possible to disable it, or even change the rate. The problem is, I can't find any xHCI registers that control/monitor the SOF. It is possible it is on the USB device itself.

    Does anyone have any info on the SOF, like register locations or just a good knowledge of it in general?
     

  11. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Windows keeps current version of device driver along with previous versions of device driver in so called driver store. DriverStoreExplorer lets select and remove old versions of driver.

    Also DriverStoreExplorer lets to put driver into driver store, IIRC.
     
    ZeeMonning likes this.
  12. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    I was wrong, after extensive research, that 'suspend' is the same as selective suspend, and I determined, to the best of my abilities, that the devices are not suspending.

    I do have another question, however. I was looking through USB devices in Device Manager and noticed the power states supported for xHCI are just D0 and D3. But if I look at a USB device, it supports D0, D1, D2, and D3.
    Does Windows (or PCIe, not sure which this relates to, if someone could enlighten me) see each USB device as a separate device, each with it's own D state, instead of just seeing the xHCI?
     
  13. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Of course Windows sees each USB device as a separate device - do you see them in Device Manager?
    As for PCIe, I doubt it needs to interact with USB devices directly, also there is no PCIe fabric past USB controller.
     
    Last edited: Apr 26, 2023
  14. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    I'm sorry, I didn't make my question nearly as clear as it should have been, but unfortunately I don't think I'll be able to make it crystal clear, so bear with me.

    I guess my question is, terms of Windows power management, does a USB device have a D state isolated from the xHCI D state? And is the D state part of the PCIe communication (protocal?), or is it a Windows implemented power saving feature?

    A device's power state (the D states) are usually referenced in terms of PCIe in most documents i've read. But seeing as the xHCI and a USB device don't support the same D states (USB device supporting more), this doesn't make sense, because I also thought PCIe is only interfacing with the xHCI and doesn't care if there are devices connected.
     
  15. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    I would use word "independent" instead of "isolated". To me each device having independent D-states is more logical. For example, we have USB storage device - while it writes a portion of data sent to it USB controller can have a nap until storage device notifies controller about completed write operation.

    PS
    Plus, D-state is an abstraction. For each device the level of power saving - depth of D-state - means something unique/intrinsic for device. But for outer world it just means more energy saved or less.
     
    ZeeMonning likes this.

  16. ZeeMonning

    ZeeMonning Member

    Messages:
    40
    Likes Received:
    0
    GPU:
    RTX 3060 Ti 8gb
    I would've too, but I couldn't for the life of me figure out the right word, so I used 'isolated' as I figured you'd get the idea.

    That makes sense. I am fairly convinced all the devices are staying in D0 at all times, since that is what the Device Manager is claiming (aside from disabled devices, which show in D3), I'm just trying to figure out where I need to start looking next. I came up with nothing after going through an xHCI register list for a couple hours.

    As far as I can tell at the moment, there is actually nothing power-saving/throttling going on in the xHCI. It shouldn't be the problem.
    As I understand it, the xHCI polls the device at the device's defined frequency, whether the device is doing something or not. I did notice the xHCI interrupt count is proportional to how much I move the mouse (only USB device on that controller). I don't think the xHCI delays the interrupts to the system (outside of it's interrupt moderation). I also don't think the system delays handling the interrupts (especially not just on the first interrupt in a string of constant interrupts), this also doesn't make sense because the issue seems to happen per USB device on the same controller. So this leaves the process the interrupts use to get to the processor (which doesn't make sense), or the process to get the new data to the application (which, if I understand it, also doesn't make sense), if I'm not mistaken. I seem to be missing something. Something seems to be going into some form of idle state and takes a good bit of time to get out of that state, but it will usually stay active when the events continue. That's my analysis, anyway, if anyone has any info/input, let me know.
     
    Last edited: Apr 26, 2023
  17. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,536
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    You need expertise from real USB device driver developer.

    Upd.: Maybe you can download Windows DDK and find there examples of USB device drivers and maybe you will find mysterious idles there.
     

Share This Page