Set affinity with start /AFFINITY command on Windows 7
Asked Answered
D

3

29

I am using the start /AFFINITY [n] [.exe] command to start an executable with the specified affinity. I have a system with 8 processors (1,2,3,4,5,6,7,8). I'd like to set the process to use all of the odd processors (1,3,5,7). I cannot figure out how to do this and would like to know if it's possible using the start command. If not, is there an alternate command-line way of doing it?

The help for the start command wasn't particularly useful:

 AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
             The process is restricted to running on these processors.

             The affinity mask is interpreted differently when /AFFINITY and
             /NODE are combined.  Specify the affinity mask as if the NUMA
             node's processor mask is right shifted to begin at bit zero.
             The process is restricted to running on those processors in
             common between the specified affinity mask and the NUMA node.
             If no processors are in common, the process is restricted to
             running on the specified NUMA node.
Defendant answered 13/10, 2011 at 20:17 Comment(0)
W
38

AFFINITY works with a hexidecimal mask that should allow granular control of all of your processors. Note that the rightmost bit specifies the lowest-order CPU (0) (see KB 299641).

For the case in question, 0xAA (10101010) requests that your process run using processors 1, 3, 5 and 7, but not 0, 2, 4 or 6. Be sure to leave out the '0x' on the command line.

 start /affinity AA app.exe

Other examples:

 start /affinity 1 app.exe     (only use CPU 0)
 start /affinity 2 app.exe     (only use CPU 1)
 start /affinity 1F app.exe    (only use CPUs 0, 1, 2, 3, and 4)
Waxen answered 13/10, 2011 at 20:33 Comment(2)
It seems, My PC is same configuration as yours.Could you please give syntax,how you have added it? I'm following this: support.microsoft.com/kb/299641 , But, still confused.Thanks.Sessile
Could you do this with a %1 argument to drag-and-drop programs (or shortcuts to them) for specific processors? To clarify for anyone trying this, you need to use cmd.exe and not just start: cmd.exe /c start "Program Name" /affinity ## "Full path of program" -argumentsMegasporophyll
A
11

To get right HEX number imagine your cores in plane format 8765 4321 (for 8-core CPU) in backward direction (but NOT like 1234 5678)

To get cores 7, 6 and 3 activated, type number 0x64 for affinity:

/AFFINITY 0x64

For better look, match and compare: 0110 0100 - number = 0x64 (8765 4321) - cores

For @ladenedge example: /AFFINITY AA 1010 1010 - number = 0xAA (8765 4321) - cores

See also: Start an Application Assigned to a Specific CPU in Windows 7, 8, or Vista

Amino answered 1/9, 2013 at 17:1 Comment(1)
Just to add, a simple way to do this... once you're thinking of your processor IDs in reverse, just go into calc and switch to programmer mode. Set "Bin" on the left for binary then type in your code for turning each one on and off then hit "Hex". That'll give you the Start code.Nicollenicolson
G
6

More info for your own computation needs:

CPU ID  CPU value (dec)
0       001 (= 2^0)
1       002 (= 2^1)
2       004 (= 2^2)
3       008 (= 2^3)
4       016 (= 2^4)
5       032 (= 2^5)
6       064 (= 2^6)
7       128 (= 2^7)

Consequently:

  • Mask for CPU IDs 0, 1, 2, 3, 4, 5, 6, 7: 255 (sum of individual CPU decimal values), that is the 'FF' mask as hexadecimal
  • Mask for CPU IDs 0, 2, 4, 6 : 85 (sum of individual CPU decimal values), that is the '55' mask as hexadecimal

Reference: search the 'These are affinity mask values for an 8-CPU system' pattern at https://msdn.microsoft.com/en-US/library/ms187104.aspx.

Ganges answered 19/3, 2017 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.