[Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Everything about latency. Tips, testing methods, mouse lag, display lag, game engine lag, network lag, whole input lag chain, VSYNC OFF vs VSYNC ON, and more! Input Lag Articles on Blur Busters.
Aeodyn
Posts: 9
Joined: 19 Feb 2024, 15:42

[Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Aeodyn » 01 Mar 2024, 19:23

I've recently finally got my computer's MouseTester graphs stable with my dav3pro at 8000Hz. When I was digging into the last bits of jitter, I noticed in Windows Performance Aanalyzer that atieclxx.exe, a part of AMD's External Events Utility that is required for FreeSync and other things, calls `GetRawInputData` constantly. Killing that thread in particular fixes the MouseTester graphs, but also breaks FreeSync.

I threw the .exe into Ghidra and found the attached processing loop. Seems that atieclxx does calculations for Radeon Boost/Chill even with those features disabled, like getting the euclidean magnitude of mouse inputs. The `QueryPerformanceCounter` call I believe is needed for FreeSync, and is luckily cheap.

Regardless, turned out to be very easy to just NOP-out the RegisterRawInputDevices and GetRawInputData calls, for FreeSync without mouse input interference. Attached is a python script I made to patch atieclxx.exe automatically; it's also on my gitlab but I'm apparently not allowed to link there?

Note that you may need to use a tool like AdvancedRun to replace the .exe in C:\Windows\System32\DriverStore since it's owned by TrustedInstaller, or use a tool like RadeonSoftwareSlimmer to unpack and clean the installer.


Edit:

To run the script:
1: Install python 3.
2: In a normal cmd/powershell prompt run "pip install pefile" to install pefile, a required dependency of the script.
3: Open Task Manager, go to the Details tab, right-click atieclxx.exe and click Properties to find where it is, then end the task.
4: Extract patch_atieclxx.py from the attached zip and copy atieclxx.exe into the same directory.
5: Go to that directory in a cmd/powershell prompt with cd, or by holding shift and right-clicking in the directory and choosing "Open PowerShell window here".
6: Run "py patch_atieclxx.py" in that prompt to patch the exe.
7: Use a tool like nirsoft's Advanced Run to open any tool that can copy a file (other than explorer.exe) as TrustedInstaller; personally I love Everything search.
8: Copy the patched atieclxx.exe back to its original location.
9: Restart the "AMD External Events Utility" in Services, or restart the computer.

Alternatively after step 3, you can set the INPATH and OUTPATH variables in the script to where your used atieclxx.exe is, then run cmd/powershell as TrustedInstaller, cd do the script's location, and run it from there. Just be very very careful when running anything as TrustedInstaller.
Attachments
patch_atieclxx.zip
(1.06 KiB) Downloaded 96 times
Screenshot 2024-02-22 005532.png
Screenshot 2024-02-22 005532.png (121.24 KiB) Viewed 4786 times
Last edited by Aeodyn on 13 Mar 2024, 19:03, edited 1 time in total.

User avatar
Chief Blur Buster
Site Admin
Posts: 11653
Joined: 05 Dec 2013, 15:44
Location: Toronto / Hamilton, Ontario, Canada
Contact:

[Radeon+MouseHz Interference] Re: atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Chief Blur Buster » 01 Mar 2024, 19:59

Your tweak may be a very interesting improvement for high-Hz mouse users on AMD systems!
Aeodyn wrote:
01 Mar 2024, 19:23
it's also on my gitlab but I'm apparently not allowed to link there?
This is due to spammers that the forum software doesn't let new members post URLs.
As you get more posts, this restriction will get removed (typically after the 3rd post approved).

May you post the URL but replace the periods with spaces? Like www gitlab com/etc/etc
Head of Blur Busters - BlurBusters.com | TestUFO.com | Follow @BlurBusters on Twitter

Image
Forum Rules wrote:  1. Rule #1: Be Nice. This is published forum rule #1. Even To Newbies & People You Disagree With!
  2. Please report rule violations If you see a post that violates forum rules, then report the post.
  3. ALWAYS respect indie testers here. See how indies are bootstrapping Blur Busters research!

Aeodyn
Posts: 9
Joined: 19 Feb 2024, 15:42

[Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Aeodyn » 01 Mar 2024, 20:03

Chief Blur Buster wrote:
01 Mar 2024, 19:59
This is due to spammers that the forum software doesn't let new members post URLs.

May you post the URL but replace the periods with spaces? Like www gitlab com/etc/etc
Ah gotcha, sure! Didn't want to evade a rule or anything.

https://www.gitlab.com/Aeodyn/amdpatch

[Edit by Chief Blur Buster -- Converted to Clicky]

User avatar
Chief Blur Buster
Site Admin
Posts: 11653
Joined: 05 Dec 2013, 15:44
Location: Toronto / Hamilton, Ontario, Canada
Contact:

[Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Chief Blur Buster » 01 Mar 2024, 21:28

Aeodyn wrote:
01 Mar 2024, 20:03
Ah gotcha, sure! Didn't want to evade a rule or anything.

https://www.gitlab.com/Aeodyn/amdpatch
We have discovered that sometimes there's interference between FreeSync and a high-Hz mouse.

I wonder if this is one of the bigger causes of the interference? I'll have to forward this to an AMD engineer.
With a mouse running at 8000Hz, there are some critical loop weak links that needs optimizing on a system.
Head of Blur Busters - BlurBusters.com | TestUFO.com | Follow @BlurBusters on Twitter

Image
Forum Rules wrote:  1. Rule #1: Be Nice. This is published forum rule #1. Even To Newbies & People You Disagree With!
  2. Please report rule violations If you see a post that violates forum rules, then report the post.
  3. ALWAYS respect indie testers here. See how indies are bootstrapping Blur Busters research!

Plyra
Posts: 2
Joined: 17 Aug 2019, 05:00

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Plyra » 02 Mar 2024, 05:27

Bad programming strikes again.

I noticed same behaviour on my setup (Radeon Software 24.2.1, latest version). When you check the stack that calls this subroutine unconditionally, it is possible to follow it until the function that initializes the actual driver. Driver checks the OS, enumerates the GPU version and does more but doesn't check if Radeon Boost or Chill is activated. So this subroutine that calls GetRawInputData() works all the time, in a do...while(true) loop. My educated guess is, it calculates mouse movement delta which is needed for Radeon Boost and Chill. They need to add a condition to check if those are enabled.

User avatar
F1zus
Posts: 134
Joined: 07 Nov 2022, 17:59

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by F1zus » 02 Mar 2024, 10:42

Aeodyn wrote:
01 Mar 2024, 19:23
I've recently finally got my computer's MouseTester graphs stable with my dav3pro at 8000Hz. When I was digging into the last bits of jitter, I noticed in Windows Performance Aanalyzer that atieclxx.exe, a part of AMD's External Events
Hello. I have an AMD system with an AMD processor and a Vega56 video card and a dav3 mouse with a frequency of 8khz and 1600dpi.
I'm using a modified 24.1.1 driver with Radeon Chill, FreeSync and Vsync (in games) enabled. Amd Chill allows you to accurately limit FPS in games, and other functions synchronize the monitor and video card. This way I get perfect image smoothness without breaks or friezes.
Please tell me what is wrong with your graphs in the Mouse Tester program? Is your mouse polling rate inconsistent or what is your problem? Maybe I have it too.

[email protected]
Posts: 35
Joined: 22 Dec 2022, 15:50

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by [email protected] » 03 Mar 2024, 12:26

Aeodyn wrote:
01 Mar 2024, 19:23

Note that you may need to use a tool like AdvancedRun to replace the .exe in C:\Windows\System32\DriverStore since it's owned by TrustedInstaller, or use a tool like RadeonSoftwareSlimmer to unpack and clean the installer.
Could someone please explain what to do?

RealTweaker
Posts: 27
Joined: 11 Jan 2024, 03:42

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by RealTweaker » 05 Mar 2024, 10:22

How can i tell the script worked? When i run .py script the console flashes for a moment, does it mean it worked?

Aeodyn
Posts: 9
Joined: 19 Feb 2024, 15:42

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by Aeodyn » 09 Mar 2024, 15:01

F1zus wrote:
02 Mar 2024, 10:42
Hello. I have an AMD system with an AMD processor and a Vega56 video card and a dav3 mouse with a frequency of 8khz and 1600dpi.
I'm using a modified 24.1.1 driver with Radeon Chill, FreeSync and Vsync (in games) enabled. Amd Chill allows you to accurately limit FPS in games, and other functions synchronize the monitor and video card. This way I get perfect image smoothness without breaks or friezes.
Please tell me what is wrong with your graphs in the Mouse Tester program? Is your mouse polling rate inconsistent or what is your problem? Maybe I have it too.
I don't actually use Boost or Chill, but my understanding is that Boost varies your resolution depending on mouse movement, and Chill varies framerate depending on mouse movement (and is more a power-saving feature than anything else). atieclxx.exe seems to be a way for the driver to get that mouse movement data, but it does so unecessarily even when these features are disabled. Two different programs constantly calling GetRawInputData means both get a bunch of extra variance in polling timings.
ISR-GetRawInputData latencies (in nanoseconds) before and after the patch:
Screenshot 2024-03-09 144113.png
Screenshot 2024-03-09 144113.png (437.99 KiB) Viewed 2660 times
Screenshot 2024-03-09 144711.png
Screenshot 2024-03-09 144711.png (135.04 KiB) Viewed 2660 times
Plyra wrote:
02 Mar 2024, 05:27
Bad programming strikes again.

I noticed same behaviour on my setup (Radeon Software 24.2.1, latest version). When you check the stack that calls this subroutine unconditionally, it is possible to follow it until the function that initializes the actual driver. Driver checks the OS, enumerates the GPU version and does more but doesn't check if Radeon Boost or Chill is activated. So this subroutine that calls GetRawInputData() works all the time, in a do...while(true) loop. My educated guess is, it calculates mouse movement delta which is needed for Radeon Boost and Chill. They need to add a condition to check if those are enabled.
Pretty much. The weird bitwise lines calculate absolute value of x, y, and scrolling inputs, and it takes those, combines them into euclidean magnitude and a couple diffent orderings of max() and abs(), and stores them all along with the QPC result into a memory-mapped shared object/file.
punxen wrote:
03 Mar 2024, 12:26
Could someone please explain what to do?
RealTweaker wrote:
05 Mar 2024, 10:22
How can i tell the script worked? When i run .py script the console flashes for a moment, does it mean it worked?
Put atieclxx.exe in the same folder as the script or vice-versa and run the script, then put atieclxx.exe back in its original location if you moved it. You can see where exactly it is by finding it in the Details page of Task Manager, right-click→properties. Again though, you may need to use a tool like AdvancedRun to move atieclxx.exe as the TrustedInstaller "user".
You can tell if it worked by comparing hashes of the exe before/after running the patcher, or comparing graphs, or using xperf+WPA to see if atieclxx.exe is making any NtUserGetRawInputDataCalls.

User avatar
F1zus
Posts: 134
Joined: 07 Nov 2022, 17:59

Re: [Radeon+MouseHz Interference] atieclxx calls GetRawInputData causing mouse jitter - patched w/ python!

Post by F1zus » 10 Mar 2024, 14:48

Aeodyn wrote:
09 Mar 2024, 15:01
I don't actually use Boost or Chill, but my understanding is that Boost varies your resolution depending on mouse movement, and Chill varies framerate depending on mouse movement (and is more a power-saving feature than anything else). atieclxx.exe seems to be a way for the driver to get that mouse movement data, but it does so unecessarily even when these features are disabled. Two different programs constantly calling GetRawInputData means both get a bunch of extra variance in polling timings.
ISR-GetRawInputData latencies (in nanoseconds) before and after the patch:
Screenshot 2024-03-09 144113.pngScreenshot 2024-03-09 144711.png
Okay, thanks for the answer. I downloaded python 3 on win10 and tried to run your script. It throws an error on the first line.
PS: I would like to add that if you set min fps = max fps, then AMD chill will work like a regular fps limiter.
But it limits it more correctly than the in-game limiter.
And also, after using your script with AMD chill enabled, will there be problems with the mouse?
Attachments
error.PNG
error.PNG (14.39 KiB) Viewed 2509 times

Post Reply