Jump to content
Sign in to follow this  
Maximilian

Setting Game.exe CPU affinity from start.bat

Recommended Posts

I am wondering if it is possible to edit the start.bat in such a way that every new Game.exe client opened is automatically set to have an affinity with the least busy CPU core.

I realized while playing with many clients open that while the game lagged considerably with both CPU and RAM being under 50% usage , on further investigation i realized that one single core (the 0th) was doing all the work , processing for all the eleven clients i opened.

Now , the fix was fairly trivial , going on task manager and setting the affinity for every game.exe to a different CPU core. Once i did so the lag completely disappeared.
Doing so manually is a bit of a chore , and more importantly i often forget to do so.

Is there a way to set the start.bat to recognize the affinities of the other game.exes and automatically setting the new process affine to the Core that has the least number of processes affine to it?

Thank you in advance.


And example : I have a 4 core CPU , 1st game, exe would be affine to CPU 0 , 2nd to CPU 1 , 3rd to CPU 2 , 4rth to CPU 3 , and then start repeating.

Share this post


Link to post
Share on other sites
10 minutes ago, Billy said:

 

 

Thanks , however in my preliminary search I had arleadly found that method and didn't find it satisfactory.

The main problem is that it would require a different shortcut for every affinity i wanted , so four shortcuts in my case (unless i misunderstood something), i would like one single start.bat that automatically determined which Core has the least number of game.exes running on it and it executed the new game.exe with that particular affinity.

I hope i'm being clear enough , if i need to rephrase just ask :)

Share this post


Link to post
Share on other sites
@ECHO OFF
:: Declare amount of cores
SET /A maxcores=4
:: Declare path to game.exe
SET gamepath="system/game.exe" 
:: Declare game.exe name
SET game="game.exe"
::Count current instances of game.exe
::Write number to tmp file.
tasklist | find /I /C %game%>tmp
::Read in number from tmp file.
SET /p count= <tmp
::Get modulous of count and maxcore.
::We use this to decide which core to run on.
SET /A core=(%count% %% %maxcores%)
SET coreparam=1
::If there are no other clients open,
::Always run on core 0 (coreparam = 1)
IF %core%==0 GOTO run
::Loop for exponent
SET loop=0
:multiply
SET /a coreparam=coreparam*2
SET /a loop=loop+1
IF %loop% LSS %core% GOTO multiply
:run
::Run game.exe and set affinity.
cmd.exe /c start "Process Monitor" /affinity %coreparam% %gamepath% startgame

Can try something like this.

  • Like 3

Share this post


Link to post
Share on other sites

Yes , it works as intented.

The only thing you have to be careful about is that if you close clients , the order continues to be the same, it doesn't fill the "hole".

So if you have 4 open on 0 1 2 3 , close the last two 2 3 , and open two more , they will be on 0 1  as the first two.

However it works really well. 

Note : if you want to use it too , check how many cores your CPU has , and edit the "4" to be your number.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...