Logo Platform
logo amplifiers simplified

High CPU usage, even in main menu, or when minimized

Reply
Copied to clipboard!
8 years ago
Jan 7, 2017, 11:06:31 PM

Hi,

I'm observing that Endless legend consumes a lot of CPU time, even when in the main menu while that application is minimized.  My GPU seems fine and framerates are ok.  One core seems particularly busy:

 

The game is playable, but my CPU fan is working hard, and it gets more laggy when actually in game play.   I do not observe this behavior with other games on my system.   After quick Google I found that several other people on the Steam forums had complained of high CPU only for EndlessLegend. 


I thought it weird that the game should consume so much even in the main menu, so I used Sysinternals' Process Monitor (https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx)  to see if I could figure out why it was consuming so much CPU.  I observed that EndlessLegend.exe seemed to be making roughly 50  calls to the Windows registry every second:


"Time of Day","Process Name","PID","Operation","Path","Result","Detail"
"5:01:05.9823408 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: HandleTags, HandleTags: 0x0"
"5:01:05.9823931 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: Name"
"5:01:05.9824238 PM","EndlessLegend.exe","7764","RegOpenKey","HKCU\Software\Valve\Steam\ActiveProcess","SUCCESS","Desired Access: Read"
"5:01:05.9824493 PM","EndlessLegend.exe","7764","RegSetInfoKey","HKCU\SOFTWARE\Valve\Steam\ActiveProcess","SUCCESS","KeySetInformationClass: KeySetHandleTagsInformation, Length: 0"
"5:01:05.9824633 PM","EndlessLegend.exe","7764","RegQueryValue","HKCU\SOFTWARE\Valve\Steam\ActiveProcess\pid","SUCCESS","Type: REG_DWORD, Length: 4, Data: 2068"
"5:01:05.9824825 PM","EndlessLegend.exe","7764","RegCloseKey","HKCU\SOFTWARE\Valve\Steam\ActiveProcess","SUCCESS",""
"5:01:05.9828601 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: HandleTags, HandleTags: 0x0"
"5:01:05.9829077 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: Name"
"5:01:05.9829345 PM","EndlessLegend.exe","7764","RegOpenKey","HKCU\Software\Valve\Steam\ActiveProcess","SUCCESS","Desired Access: Read"
"5:01:05.9829536 PM","EndlessLegend.exe","7764","RegSetInfoKey","HKCU\SOFTWARE\Valve\Steam\ActiveProcess","SUCCESS","KeySetInformationClass: KeySetHandleTagsInformation, Length: 0"
"5:01:05.9829661 PM","EndlessLegend.exe","7764","RegQueryValue","HKCU\SOFTWARE\Valve\Steam\ActiveProcess\pid","SUCCESS","Type: REG_DWORD, Length: 4, Data: 2068"
"5:01:05.9830242 PM","EndlessLegend.exe","7764","RegCloseKey","HKCU\SOFTWARE\Valve\Steam\ActiveProcess","SUCCESS",""
"5:01:06.0284618 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: HandleTags, HandleTags: 0x0"
"5:01:06.0284947 PM","EndlessLegend.exe","7764","RegQueryKey","HKCU","SUCCESS","Query: Name"
"5:01:06.0285320 PM","EndlessLegend.exe","7764","RegOpenKey","HKCU\Software\Valve\Steam\ActiveProcess","SUCCESS","Desired Access: Read"


using grep I sampled some one-second intervals, counting the calls to 'RegQueryValue':


grep '5:01:07' procmon.csv  | grep RegQueryValue | wc -l
51


That number looks suspiciously close to my frame rate, which the Steam overlay reported as being between 50-54 frames per second.   Based on this, I'm guessing that there is code in the main render loop that is making a call each frame.   I then used the Sysinternals procmon again to look at the stack for those calls:  


"Frame","Module","Location","Address","Path"
"0","ntoskrnl.exe","ObReferenceObjectByHandle + 0x1ece","0xfffff802488ecdfe","C:\WINDOWS\system32\ntoskrnl.exe"
"1","ntoskrnl.exe","SeQueryInformationToken + 0x288f","0xfffff8024889444f","C:\WINDOWS\system32\ntoskrnl.exe"
"2","ntoskrnl.exe","ObWaitForMultipleObjects + 0x11f1","0xfffff802488ea2e1","C:\WINDOWS\system32\ntoskrnl.exe"
"3","ntoskrnl.exe","ObOpenObjectByNameEx + 0x1dd","0xfffff8024889ccdd","C:\WINDOWS\system32\ntoskrnl.exe"
"4","ntoskrnl.exe","NtQuerySystemInformation + 0x258d","0xfffff8024889c9bd","C:\WINDOWS\system32\ntoskrnl.exe"
"5","ntoskrnl.exe","SeCaptureSubjectContextEx + 0x18f","0xfffff8024889a2ff","C:\WINDOWS\system32\ntoskrnl.exe"
"6","ntoskrnl.exe","setjmpex + 0x3a73","0xfffff8024856c393","C:\WINDOWS\system32\ntoskrnl.exe"
"7","ntdll.dll","NtOpenKeyEx + 0x14","0x7ff8831882e4","C:\WINDOWS\SYSTEM32\ntdll.dll"
"8","KERNELBASE.dll","MapPredefinedHandleInternal + 0xabc","0x7ff87f6db19c","C:\WINDOWS\System32\KERNELBASE.dll"
"9","KERNELBASE.dll","RegOpenKeyExInternalA + 0x12e","0x7ff87f6d7c8e","C:\WINDOWS\System32\KERNELBASE.dll"
"10","KERNELBASE.dll","RegOpenKeyExA + 0x19","0x7ff87f6d7b49","C:\WINDOWS\System32\KERNELBASE.dll"
"11","steam_api64.DLL","SteamAPI_IsSteamRunning + 0x41","0x5ab15341","C:\Program Files (x86)\Steam\steamapps\common\Endless Legend\steam_api64.DLL"
"12","<unknown>","0x3768abc3","0x3768abc3","" 


It looks like that game is calling 'SteamAPI_IsSteamRunning' to check if the Steam client is running....every frame of the game!   I'm not a game programmer or a windows guy, but I'm wondering if this could be the cause of the high CPU usage on my machine?


I'm on Windows 10, running Endless Legend 64 bit version V1.5.7 S3.

12GB RAM

Intel Core i7  at 3.2 GHz

AMD Radeon HD5800 with 4gb, running at 1920x1080. (latest driver installed)


I love this game,  thanks for the help!















Updated 8 years ago.
0Send private message
8 years ago
Jan 8, 2017, 12:57:04 PM

Basically, I can confirm your findings.


My resource monitor says that EL uses an average of 17% CPU (i7-4790K at 4.5-4.8 GHz, although with Endless Legend idling in-game - not in the menus - it sits around 1.6-1.9 GHz):


Like you, I'm seeing a lot of registry checks:


And the callstack points to checking the Steam connection:


What I'd guess:

1. Although the game is multi-threaded (I see 62 threads running in my game - not in the menus), there's one "main" thread which does most of the work, and is probably also used to spawn additional threads.

2. The game checks the connection to Steam e.g. for achievement unlock purposes.

3. Although there's a CPU hit, I'm not sure how big of an impact it causes.


Process Explorer says the same 17% CPU for EL, and a whopping 40% (!) for my GPU (an AMD R9-290 w/ 4 GB, slightly OCed):

 and


The GPU usage has me far more worried than the CPU usage ...

So if I were to invest more resources, I'd have a look at GPU optimization. It seems to use far too much for a turn-based strategy game. Perhaps it renders the whole map instead of only the visible part of it - I have no idea.


0Send private message
8 years ago
Jan 8, 2017, 4:48:23 PM

Thanks for the confirmation, @icarus86 ! Yeah, I believe the 'main' thread is responsible for the game's rendering loop (draw screen, update game, check for input) because the registry calls per sec meet my frame rate.  Ironically, my outdated graphics card may actually help, because if it were more beefy, the increased frame rates would translate to even more calls to the windows registry.  I doubt that the windows registry was designed to be hit at this frequency.  Looking at the stack trace, we can see that the call is transitioning from user space (U) into kernal space (K), which is expensive.  


I also bet that the devs would have a hard time observing this problem because the call to ''SteamAPI_IsSteamRunning' would probably be disabled in their development environments.  


With regard to your GPU usage, do you have vsync enabled?  Having it disabled may cause much higher frame rates and GPU usage.

0Send private message
8 years ago
Jan 9, 2017, 12:41:42 PM

From my experience with Windows-based servers, the registry is indeed designed to handle large amounts of reads and writes.

My systems mainly use 16-core / 32-thread CPUs and 64-128 GB RAM, with lots of IIS application pools, each with hundreds of threads, which also read from the registry a lot.


Yes, the call goes to the kernel because I don't see how you can read the key otherwise :) But this code belongs to Valve anyway (SteamAPI).

I don't contradict your assessment - checking every frame for the Steam connection is way too much - I was just thinking that it shouldn't be that bad. But it's definitely something which can be improved.


You're right about the GPU - I usually disable VSync for my games.

0Send private message
8 years ago
Jan 23, 2017, 1:03:39 AM

Interesting findings. I have always wondered why the game always uses a significant percentage of my cpu resources, even when not a lot is going on (like when I have a menu open or am in one of the subscreens like the diplomacy screen). In my case (having an older cpu and hard disk) I found that turning on vsync and lowering the max frame rate gave me a more stable experience and less stuttering.


Here's hoping Amplitude has noticed and will address this.

0Send private message
0Send private message
?

Click here to login

Reply
Comment