Quad Core Affinity May Reduce Crashing

Post » Wed Mar 30, 2011 8:14 am

My quad core q6600 seems to crash a lot with New Vegas. So, I thought I might try setting the CPU affinity to force the game to run on two cores instead of 4. Having done this manually it seemed to reduce the crashing but it is difficult and annoying to have to set CPU affinity manually using the Task Manager. Whether this really reduces crashing may or may not be true but it's worth trying. Here is a way to set the affinity automatically by starting the game with a batch file.

In Windows XP, Vista and Win 7 the command processor has some useful commands. One of them is the 'start' command which has a number of options. One of those options is to automatically set CPU affinity by use of a switch.

A batch file must be used, instead of the official launcher, because of the need to start the game itself with the affinity setting. Steam MUST be running before the batch file is run, so start Steam then run the batch file.

CPU affinity means that you can force a program to run on selected cores rather than running on all cores. The Windows command-line processor includes a number of useful commands. The affinity switch can be used with the 'start' start command to select which cores a program is allowed to use.

The affinity syntax is: start /affinity <##>

Replace with the name of the program (without the brackets).
Replace <##> with the hexadecimal value representing the cores to be used (without the brackets).

The affinity value is a binary value with a bit set ON to indicate that core should be used. This value is then written as a hexadecimal value in the command line. Cores are numbered 0, 1, 2, and 3 for a quad core CPU.

The hexadecimal affinity value:
core3 core2 core1 core0  affinityOFF   OFF   OFF   ON  = 1OFF   OFF   ON    OFF = 2OFF   OFF   ON    ON  = 3OFF   ON    OFF   OFF = 4OFF   ON    OFF   ON  = 5OFF   ON    ON    OFF = 6OFF   ON    ON    ON  = 7ON    OFF   OFF   OFF = 8ON    OFF   OFF   ON  = 9ON    OFF   ON    OFF = AON    OFF   ON    ON  = BON    ON    OFF   OFF = CON    ON    OFF   ON  = DON    ON    ON    OFF = EON    ON    ON    ON  = F

So to run a program on core 2 and 3 (the last two cores) on a quad core processor the affinity value is "C" (without the quotes).

You should never use an affinity value for which you do not actually have cores. It probably just won't work or will ignore the affinity setting and just use all the available cores. I don't think it can damage your CPU - you have been warned.

An eight core CPU would use an affinity value having two hexadecimal digits, the first digit mapping "core7 core6 core5 core4" similarly to a quad CPU. So to run a program on an eight core CPU using only the last two cores the affinity value would be "C0" (without the quotes). In fact, on a hyperthreaded 4 core CPU, to prevent a program from using the hyperthreaded cores you would use an affinity value of "0F". To force a program to use ONLY the hyperthreaded cores you would use an affinity value of "F0".

The batch file for running FNV on core 2 and 3 (on a quad core processor):
set SteamAppID=22380start /affinity C FalloutNV.exe

Copy and paste this into a plain text file, save it with a name like "run_NewVegas. cmd" (without the quotes). Put the file in the main New Vegas folder. Make a shortcut to the file, put the shortcut on the Desktop. Start Steam then double-click the shortcut.

Your SteamAppID may be different than above, find the official number in the properties for the official FNV launcher shortcut. For example: "steam://rungameid/22380".

Only use the official launcher when you need to change options.

Choosing which two cores to use:
The q6600 is really two e6600 dualcores placed in the same chip. The q6600 has two separate 2Mb caches, one dedicated to core 0 and 1 the other dedicated to core 2 and 3. A multithreaded program will run fastest if it does not split it's hardware resources. Running on core 2 and 3 prevents the program from expensive context switching which happens when a thread needs to cooperate with another thread which is not on the same CPU hardware. Therefore, ensuring that the program runs on the same hardware is important for the q6600. Newer quadcores (like i5, i7 and i9) do not have this limitation since all four cores and caches are fully integrated.

If you use the affinity switch it is best to not choose core 0 because that core is best left to the Windows operating system which in some cases is required. You might however want to run something on core 0, 1 and 2 and NOT core 3, then run something else on core 3 and NOT core 0, 1 and 2.

By the way, you can use the start command with the affinity switch for almost ANY program. You cannot use it for any Windows system program and certain programs specifically designed to run on all cores.
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Post » Wed Mar 30, 2011 12:22 am

My quad core q6600 seems to crash a lot with New Vegas. So, I thought I might try setting the CPU affinity to force the game to run on two cores instead of 4. Having done this manually it seemed to reduce the crashing but it is difficult and annoying to have to set CPU affinity manually using the Task Manager. Whether this really reduces crashing may or may not be true but it's worth trying. Here is a way to set the affinity automatically by starting the game with a batch file.

In Windows XP, Vista and Win 7 the command processor has some useful commands. One of them is the 'start' command which has a number of options. One of those options is to automatically set CPU affinity by use of a switch.

A batch file must be used, instead of the official launcher, because of the need to start the game itself with the affinity setting. Steam MUST be running before the batch file is run, so start Steam then run the batch file.

CPU affinity means that you can force a program to run on selected cores rather than running on all cores. The Windows command-line processor includes a number of useful commands. The affinity switch can be used with the 'start' start command to select which cores a program is allowed to use.

The affinity syntax is: start /affinity <##>

Replace with the name of the program (without the brackets).
Replace <##> with the hexadecimal value representing the cores to be used (without the brackets).

The affinity value is a binary value with a bit set ON to indicate that core should be used. This value is then written as a hexadecimal value in the command line. Cores are numbered 0, 1, 2, and 3 for a quad core CPU.

The hexadecimal affinity value:
core3 core2 core1 core0  affinityOFF   OFF   OFF   ON   = 1OFF   OFF   ON     OFF = 2OFF   OFF   ON     ON   = 3OFF   ON     OFF   OFF = 4OFF   ON     OFF   ON   = 5OFF   ON     ON     OFF = 6OFF   ON     ON     ON   = 7ON     OFF   OFF   OFF = 8ON     OFF   OFF   ON   = 9ON     OFF   ON     OFF = AON     OFF   ON     ON   = BON     ON     OFF   OFF = CON     ON     OFF   ON   = DON     ON     ON     OFF = EON     ON     ON     ON   = F

So to run a program on core 2 and 3 (the last two cores) on a quad core processor the affinity value is "C" (without the quotes).

An eight core CPU would use an affinity value having two hexadecimal digits, the first digit mapping "core7 core6 core5 core4" similarly to a quad CPU. So to run a program on an eight core CPU using only the last two cores the affinity value would be "C0" (without the quotes).

The batch file for running FNV on core 2 and 3 (on a quad core processor):
set SteamAppID=22380start /affinity C FalloutNV.exe

Copy and paste this into a plain text file, save it with a name like "run_NewVegas. cmd" (without the quotes). Put the file in the main New Vegas folder. Make a shortcut to the file, put the shortcut on the Desktop. Start Steam then double-click the shortcut.

Your SteamAppID may be different than above, find the official number in the properties for the official FNV launcher shortcut. For example: "steam://rungameid/22380".

Only use the official launcher when you need to change options.

By the way, you can use the start command with the affinity switch for almost ANY program. You cannot use it for any Windows system program and certain programs specifically designed to run on all cores.


good to know, i never knew the shortcut to those commands, only knew of the ctrl-alt-delete and setting it that way

P.S. Im on a Q6600 as well and havn't had one crash due to NV, i hope it continues but will most definitely remember this
User avatar
BlackaneseB
 
Posts: 3431
Joined: Sat Sep 23, 2006 1:21 am

Post » Tue Mar 29, 2011 10:19 pm

Bad advice, this has an immediately noticeable decreased performance impact. Before changing affinity, turn in a circle and notice the frame rate. Now change affinity to two cores and do the same. Choppy, choppy, choppy. Not wise to gimp your CPU, it won't prevent crashing. I read this same thing in the fallout 3 forum which is why I wanted to post here. The game will still crash they said, it isn't related to your cores. In both games performance will decrease so anybody that says the game isn't multithreaded is wrong
User avatar
Gen Daley
 
Posts: 3315
Joined: Sat Jul 08, 2006 3:36 pm

Post » Wed Mar 30, 2011 3:40 am

The title does say 'May Reduce', the key word is 'May' meaning your experience may vary. I did not say that this modification was a certified fix for anything. I NEVER suggested that FNV might not be multithreaded. I NEVER said anything about Fo3 which in my case runs flawlessly on the same hardware - without the crashing.

Obviously performance with this modification will be completely dependent on your CPU speed. On a high end quad core you will not see a great decrease in performance.

Sadly, I have not seen a great decrease in FNV's crashing as a result of using this modification.

I have recently been using core 1, 2 and 3 for the game leaving core 0 exclusively for Windows' use, this seems reasonable to me.

Command for causing FNV to NOT use just core 0:
start /affinity E FalloutNV.exe

The point of this modification has as its premise that something IS wrong with the multithreading. The theory is that some thread or threads are getting out of sync thereby causing a crash. No, I do not have positive evidence that that is what is happening, it's just a theory. The hope is that by restricting the core use that the threads may be better behaved. After some days of using this modification I've come to the conclusion that it does not help much or perhaps does not help at all.

Even after having said all that, I still think the "/affinity" command is a useful tool (if not for FNV) and I thought I might document it here.
User avatar
Danny Warner
 
Posts: 3400
Joined: Fri Jun 01, 2007 3:26 am


Return to Fallout: New Vegas