2700x + windows 10 scheduling and affinity!

so now i have this 8 core 16 thread cpu. im looking to use the chips resources more effectively.
what i wanna know is, is there a way to setup my programs exe files so they run with a pre determined by me affinity on the cpu?
ie set a -option in the files icon path or some other than going through task manager. (id prefer not to use a bat to launch every file)

im basically looking to do it 1s per app/program then never worry about it again until want to change it.

suggestions?

1 Like

Isn’t affinity setting only needed for legacy software that wasn’t built to run on multi cores or some shit?

Such a modern CPU + OS is there even a need to set it manually?

I think this can be done with process lasso or with some powershell wizardry :smiley:

@Jaycob Not only, W10 seems to favour core 0 which results in higher temperatures on this core.

Yes.
For example Blizzard games run a lot better when you assign them cores and threads of a single CCX. Else you get random stutters.

1 Like

This thread also touches on the subject:

Process Lasso is certainly worth trying out, though I wish there was a slimmed down version of it with less “knobs and switches”. Basically don’t touch anything else than the Affinity settings and you’ll be fine. :slight_smile:

1 Like

I started using Process Lasso a couple weeks ago an a 2700x. I was getting some stutters in Shadow of the Tomb Raider with random cpu spikes. I set the affinity for the game in Project Lasso for real time and enable the Performance mode. I haven’t had any of the random cpu spikes since then.

cool. thanks guys. got the app looking at it now :slight_smile:

Been running a 2700x for a while. Haven’t felt the need to bother with any scheduling stuff, runs fine?

yep mine runs fine 2 till i load up a core or 2. theres stuff i need to run in the background without interference and not have there cpu usage affect the stuff im doing in the foreground.
for instance i may want to watch a live stream while rendering a 3ds max scene.
if i let 3ds max run on all cores the stream im watching will persistently stutter as the cpu maxes out to 100%

but if i schedule the stream player to core 14/15(8) and 3dsmax to 0-13 (1-7) i can watch the stream no issues.
the difference in render time is only a few minutes over an hour or so. so while its working i wanna keep myself entertained. :slight_smile:

Care to elaborate on real time affinity?

Since I’m not a fan of installing lots of specialty programs either, here’s the gawd-awful kludge I came up with after seeing Wendell’s video on NUMA and whatnot; and of course, I severely overcomplicated it by spreading things out among cores – simply because it wouldn’t be like me at all otherwise. (On the plus side, when I open Performance Viewer it actually looks like all of the cores/threads are actually doing something - and isn’t looking cool what it’s all about in the end?)

Affinity values are in decimal and I included a sample worksheet at the bottom; there’s probably a way to do it in hex or binary but I’m always struggling with getting type-type things to work in Powershell.

# AffinityKludge.ps1  (sample version)
# Scheduled to run as SYSTEM at each startup (after a short delay) - highest privileges; no timeout; no auto restart
#  Command:    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
#  Parameters: -nologo -WindowStyle Hidden -file "C:\Windows\System32\config\systemprofile\AffinityKludge.ps1"
# MAKE ABSOLUTELY SURE THAT NO UNAUTHORIZED USERS CAN MODIFY THIS FILE!

# First assign 1, 5 and 8 for EFS only; exclude these for most others.
# Don't include in the loop in case it needs to be set before heavy EFS usage, etc.
Get-Process "*lsass*" | ForEach-Object -process { $_.ProcessorAffinity=33026 }

# Set this Powershell session to a low priority.
# (Figure out how to do it with number to go below Priority 8)
(Get-Process -Id $PID).PriorityClass = "Idle"

# Le loope de infinite...
while (1)
{
Get-Process "*explorer*" | ForEach-Object -process { $_.ProcessorAffinity=65276 }
Get-Process "*cmd*" | ForEach-Object -process { $_.ProcessorAffinity=21844 }
Get-Process "*powershell*" | ForEach-Object -process { $_.ProcessorAffinity=43688 }
# Note that everything started through an Explorer instance, cmd, etc. will initially inherit its affinity.
Get-Process "*conhost*" | ForEach-Object -process { $_.ProcessorAffinity=3598 }
Get-Process "*LockApp*" | ForEach-Object -process { $_.ProcessorAffinity=18724 }
Get-Process "*mmc*" | ForEach-Object -process { $_.ProcessorAffinity=3598 }
Get-Process "*mstsc*" | ForEach-Object -process { $_.ProcessorAffinity=3980 }
Get-Process "*NVDisplay.Container*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*SearchIndexer*" | ForEach-Object -process { $_.ProcessorAffinity=9362 }
Get-Process "*SearchUI*" | ForEach-Object -process { $_.ProcessorAffinity=18724 }
Get-Process "*SystemSettings*" | ForEach-Object -process { $_.ProcessorAffinity=37448 }
Get-Process "*Firefox*" | ForEach-Object -process { $_.ProcessorAffinity=28784 }
Get-Process "*MicrosoftEdge*" | ForEach-Object -process { $_.ProcessorAffinity=4128 }
Get-Process "*MCP*" | ForEach-Object -process { $_.ProcessorAffinity=2 }
Get-Process "*Notepad++*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*NTBackup*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*procexp64*" | ForEach-Object -process { $_.ProcessorAffinity=65534 }
Get-Process "*regedit*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*7zFM*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*EXCEL*" | ForEach-Object -process { $_.ProcessorAffinity=1584 }
Get-Process "*MSACCESS*" | ForEach-Object -process { $_.ProcessorAffinity=3096 }
Get-Process "*POWERPNT*" | ForEach-Object -process { $_.ProcessorAffinity=396 }
Get-Process "*WINWORD*" | ForEach-Object -process { $_.ProcessorAffinity=6336 }
Get-Process "*Paint Shop Pro*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*anim*" | ForEach-Object -process { $_.ProcessorAffinity=3096 }
Get-Process "*SkyNet*" | ForEach-Object -process { $_.ProcessorAffinity=65534 }
Get-Process "*avidemux*" | ForEach-Object -process { $_.ProcessorAffinity=65276 }
Get-Process "*vlc*" | ForEach-Object -process { $_.ProcessorAffinity=32508 }
Get-Process "*winamp*" | ForEach-Object -process { $_.ProcessorAffinity=1032 }
Get-Process "*splwow64*" | ForEach-Object -process { $_.ProcessorAffinity=37448 }
Get-Process "*mIRC*" | ForEach-Object -process { $_.ProcessorAffinity=516 }
Get-Process "*Jenny*" | ForEach-Object -process { $_.ProcessorAffinity=8675309 }
Get-Process "*APPLEWIN*" | ForEach-Object -process { $_.ProcessorAffinity=2064 }
Get-Process "*totally legal downloading program*" | ForEach-Object -process { $_.ProcessorAffinity=33152 }

# Run again in some arbitrary amount of seconds (or milliseconds if you prefer)
Start-Sleep -Seconds 113
}
# Finally, in case Sisyphus audits this script...
Exit

Here’s the basic worksheet to select cores by programs, using Windows Calculator to convert to decimal:

      16 Cores (0-15)              
 111111
 5432109876543210  Hex   Dec   
 ----------------  ----- ------ 
 1111111111111111  FFFF  65535  All cores
 1111111111111110  FFFE  65534  All cores except 0 (likely best)
 1000000100000010  8102  33026  1, 8, and 15 only
 0111111011111100  7EFC  32508  Exclude 0, 1, 8, 15 (default)
...
 0000000000000000  0000      0  Doesn't work, otherwise I'd set Cortana to 0 (even though I already have it locked out af)

ProcessorAffinity should accept up to a quadword, but it is via a pointer.

Name               MemberType  Definition
----               ----------  ----------
ProcessorAffinity  Property    System.IntPtr ProcessorAffinity {get;set;}

Yes, maybe I should have posted this under Tech Cringe instead… :wink: In any case, suggestions for improvements and other critical feedback is absolutely welcome.

4 Likes

Sorry, I meant the “Priority class” in Project Lasso. I didn’t have to change any of the CPU affinity settings. All those can be set per application. I usually leave performance mode on all the time though.

2 Likes

Nice script :slight_smile:

Why the need for the infinty-loop though? Is it in case some programs aren’t running at the n-th iteration?

Am I right to assume that for a 2700X (8-core) CPU all cores would correspond to FF?

1 Like

I have it checking every so often because I’m opening and closing programs, logging in under different accounts, etc. all the time. This way, any program will be assigned its cores within a minute or two of starting; plus there’s no need to set up special shortcuts or whatnot since any named process, regardless of user account, gets assigned.

Yes, 8 cores would max out at 0xFF (255), so assigning user programs to 0xFE (254) would probably be good enough for a start. It does seem that Powershell gets persnickety if you try to assign a core that doesn’t exist. Also, it seems happy enough to accept hexadecimal values with the leading 0x so that may be easier to calculate on the fly.

Again though, my example is probably way overkill for general use, since most programs would be happy enough if they simply didn’t get put on core 0. A super-generic script would get the maximum allowed affinity value, knock away the 1 bit (for core 0), and assign that to user programs. (There’s probably a way to make that generic too.) If I were to do anything critical I’d probably give Lasso a try instead.

1 Like

It’s a pity Powershell isn’t as elegant as a Linux shell - for me probably something like:

Get-Process [Where user equals me] | ForEach-Object -process { $_.ProcessorAffinity=0xFE}

Anyway, why do you exclode processes like explorer, conhost, etc from all cores? Shouldn’t Windows just be doing its thing and these affinities only be applied to user processes?

1 Like

You can do that:

Get-Process -IncludeUserName | Where-Object { ($_.UserName -eq "COMPUTER\Username") } | ForEach-Object -Process { $_.ProcessorAffinity=0xFE }

To me, Explorer, cmd, etc. are pretty much user processes, as I do my best to squeeze as much out of them as I can. (I dream in nested FOR loops full of external CALLs, and find an evil kind of glee in grinding SQL servers to a crawl while still somehow getting the correct results.)

Basically though, since the operating system seems to have a penchant for overusing core 0 I just figure that both it and my processes would be happier just leaving that core to Windows.

1 Like

yeah im only after assigning user processes like the autodesk.exe and vlc.exe not that actual system process like srvchost.

2 Likes

Nice, thanks. Wouldn’t it be best to start your script above with this statement? This way, you’d catch most programs without having to write specific rules for them. Furthermore, any additional changes you might want to make would be overwritten just the same :slight_smile:

A few additional questions though:

Even with commentary, I don’t gete what’s going on here:

Furthermore, you state that everything inherits Explorers affinity (when started through it). Therefore, if I start a game by doubleclicking it’s shortcut, it is started through it, isn’t it?
As a result, for games, giving GoG/Steam an affinity should suffice as well.

1 Like

Yes, and I think that you’re absolutely right – I’ll probably even change my systems to user-based at some point too. (I’m still a real novice at Powershell and only found the user-based solution after you asked about it.) The kludge above is just me messing around, but I don’t seriously believe that the convoluted selections actually do any better than simply keeping user programs off of core 0. And like you said, since most programs will inherit Affinity from their parent there is no need for the script to check very often – maybe just have it run when you log in; perhaps have it wait two or three minutes and do a second pass to catch any late AutoRun stuff too.

LSASS.EXE is the process that handles on-the-fly encryption and decryption for Windows’ Encrypted File System (EFS), which is okay protection for cookies and private documents. Again, giving it its own few separate cores probably doesn’t help performance; but when I’m doing anything EFS intensive I can give it all the cores and let it run without the kludge script changing it back.

1 Like

thanks guys… this has been a great help.

1 Like