TechEnclave
Register Now

Registration is free.
Join us today.

CPU Affinity Made Easy

This is a discussion on CPU Affinity Made Easy within the Guides and Tutorials forums, part of the TechEnclave Gateway category; Source : Messa Hi guys, This guide should help you easily setup automatic CPU affinity assignments. Even if you dont own ...

TechEnclave > TechEnclave Gateway > Guides and Tutorials


Comment
 
LinkBack (2) Article Tools Display Modes
<!-- google_ad_section_start -->CPU Affinity Made Easy<!-- google_ad_section_end -->
CPU Affinity Made Easy
Published by KiD0M4N
19 Feb 06
Briggin CPU Affinity Made Easy

Source: Messa

Hi guys,

This guide should help you easily setup automatic CPU affinity assignments. Even if you dont own a dual core CPU, this is a must read as it uses some of the most basic commands available to all Windows users to achieve this.

Presenting to you a TE and Kidoman original (atleast I did this myself, dunno if was published earlier):
  1. Reference screen shots below for any silly doubts......
  2. Now, create a shortcut to the program you want to assign CPU affinities to.
  3. After the shortcut has been created, open the Properties page.
  4. You can see the full path of the executable in the Target box.
  5. Add "C:\WINDOWS\system32\cmd.exe " (the path to your command prompt interpretor) before the target path (see attached images for clarifications.)
  6. The command interpretor has a inbuilt subcommand known as "start" It allows the end users to set various options to the started executables by passing command line arguments. A short synopsis of the options is:



    Use Start > Run > cmd > start /? to see a exhaustive list of options.
  7. Now add a "/C start " after the previously added command. This instructs the command interpretor to consider everything after the /C as a command. The start keyword causes it to invoke the "start" sub command.
  8. Then add whatever options you want to pass to "start" In our case, it will be "/AFFINITY 1 " to set the affinity of the started process to Core 0 (remember 1 corresponds to core 0, 2 to core 1, and A (hex) to core 9 (if that were the case))
  9. Save the short-cut and Apply/Ok the settings. Run the app and fire up taskmanager to see that the desired effect is being achieved.

I have made exhaustive screenshots so as to remove any doubts. However, as always, the inquisitiveness of the human mind shall prevail and thus doubts will arise. So fire any questions you want. Also, I am in dire needs of Rep points, so those would be welcome too

Regards,

Karan

PS: Mods I tried putting the images in the GAR, but instead of the GAR wrapping the images around inside it, it tiled them horizontally and most of them went outside the screen. So i have posted the images in the post directly. Hope thats okay.

Zip File containing all the images for easier download and viewing.





Article Tools
Show Printable Version  Email this Page 


  #1  
By 4mer on 19 Feb 06, 12:32 PM
Default

nice post karan but images not working
Reply With Quote
  #2  
By KiD0M4N on 19 Feb 06, 01:36 PM
Briggin

Originally Posted by Dr. 3vil
nice post karan but images not working
eh? i can see all the images right in front of me...... whts up?
Reply With Quote
  #3  
By Aditya on 19 Feb 06, 02:10 PM
Default

Repped!
This will help Dual Core users a lot!

Thought with the /PMTimer it doesnt matter...

Im still gonna use to set Priority...
Last edited by Aditya : 19 Feb 06 at 02:18 PM.
Reply With Quote
  #4  
By KiD0M4N on 20 Feb 06, 12:39 PM
Default

thnx man........
Reply With Quote
  #5  
By DasFox on 4 Apr 06, 12:17 PM
Default

I did this, here is my Target:

C:\WINDOWS\system32\cmd.exe /C start /AFFINITY 1 D:\Games\Oblivion\OblivionLauncher.exe

When I click the game icon nothing happens, all it looks like it's trying to do is just lauch the cmd prompt.

What am I doing wrong?

THANKS
Reply With Quote
  #6  
By LocoValue on 5 Apr 06, 10:38 AM
Default

Originally Posted by DasFox
I did this, here is my Target:

C:\WINDOWS\system32\cmd.exe /C start /AFFINITY 1 D:\Games\Oblivion\OblivionLauncher.exe

When I click the game icon nothing happens, all it looks like it's trying to do is just lauch the cmd prompt.

What am I doing wrong?

THANKS
I'm having the exact same problem for Warcraft III. I've tried without quotes around the game location, with quotes, with quotes around the location and the start commands, everything. All of them have the exact same problem, which you described.

It might be related to the fact that I do indeed have a dual core processor, but when I go into a cmd prompt and type "start /?", there's one option missing, the /AFFINITY option; it has all of the others that are shown in the screenshot of the cmd prompt in the original post.

Does anyone have any ideas why /AFFINITY isn't showing up in the list of possible start parameters, and why we're having the problem of the cmd window coming up but then not launching the program?
Reply With Quote
  #7  
By Sandy on 5 Apr 06, 10:55 AM
Default

Originally Posted by LocoValue
I'm having the exact same problem for Warcraft III. I've tried without quotes around the game location, with quotes, with quotes around the location and the start commands, everything. All of them have the exact same problem, which you described.

It might be related to the fact that I do indeed have a dual core processor, but when I go into a cmd prompt and type "start /?", there's one option missing, the /AFFINITY option; it has all of the others that are shown in the screenshot of the cmd prompt in the original post.

Does anyone have any ideas why /AFFINITY isn't showing up in the list of possible start parameters, and why we're having the problem of the cmd window coming up but then not launching the program?
use this much easier
http://www.geocities.com/edgemeal_so.../LnS/Index.htm
Reply With Quote
  #8  
By Systemic Anamoly on 5 Apr 06, 11:00 AM
Default

nice guide there karan although u people can try this as well

Force Core
Reply With Quote
  #9  
By Faile on 29 Nov 07, 10:42 PM
Error Re: CPU Affinity Made Easy

short addition to this guide. the numeric parameter after /affinity is a hexadecimal parameter like stated earlier, but it's not as straightforward as 1,2,3,4,5...

if you know how ownership modes (chmod) codes work then this will be a breeze:

1st core = 1
2nd core = 2
3rd core = 4
4th core = 8
5th core = H ( hexadecimal 16 )
6th core = 1H ( hexadecimal 32 )

now if you want something to run on just one core, you pick the right number like this, just multiply by 2 until you get to the core you want.

if you want something to run on two cores, you ADD their values:

1st and 2nd core = 1 + 2 = 3
1st and 3rd core = 1 + 4 = 5
2nd and 3rd core = 2 + 4 = 6
2nd and 4th core = 2 + 8 = 10

Same thing if you want more than two cores, just add each core numerical value up and use the sum as the /affinity parameter

Tested and retested on a 8 core system.

HTH
Reply With Quote
  #10  
By Faile on 29 Nov 07, 10:45 PM
Default Re: CPU Affinity Made Easy

ok, sorry.. im tired, correction:

1st core = 1
2nd core = 2
3rd core = 4
4th core = 8
5th core = 10 ( hexadecimal 16 )
6th core = 20 ( hexadecimal 32 )
Reply With Quote
  #11  
By jmaster51984 on 12 Jan 08, 10:06 PM
Default Re: CPU Affinity Made Easy

I had been banging my head against a wall with this for some time. I finally got it mostly figured out, here are some tips to make your life easier.

Firstly, if you are having the issue where it looks like it's just attempting to open a cmd prompt. It might be because your either not pointing to the working directory or your working directory requires "quotes".

To get around this do a search on your system for "cmd". It should be in C:\Windows\System32. Copy the cmd.exe to the directory with the executable you want to run in affinity or priority. You can do it from the GUI or from a command line. In this example I'll use virtual pc 2007.

copy c:\windows\system32\cmd.exe c:\program files\microsoft virtual pc\

Second, now that a copy of cmd.exe is in your working directory with your executable, right click on your newly added cmd.exe and create a shotcut.
You can now move the shortcut to wherever you want (Desktop, Start Menu, wherever.)

Third, if you fire up your shortcut now you'll notice that it automatically starts you in the directory where your copied cmd is sitting. It would show up like this. (Note: this test is being done on Vista Ultimate 64-bit for reference)

Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Program Files\Microsoft Virtual PC>

Third, now right click on your shortcut and go to properties. Where you see "Target" you should see something like this.

"C:\Program Files\Microsoft Virtual PC\cmd.exe"

This is where you add your start command, throwing the /c tells it to execute a command and then terminate. Then you can add your priority switches and affinity switches with the Start command. Add this right into your shortcut target Like so.

"C:\Program Files\Microsoft Virtual PC\cmd.exe" /c start /realtime /affinity 3 vpc.exe

The /realtime is the priority I chose for my program, by choosing affinity 3 I'm telling the program to only use processors 0 and 1. This example is being done on a 4 processor system, I would not recommend using /realtime unless you have remaining processors to handle the load, If this system only had 2 processors I would not exceed /high for my priority.

(Note, the virtual pc 2007 executable is normally named "Virtual PC.exe" I have renamed it "vpc.exe" to avoid having to use "" quotes which causes the command to fail. As best I can tell I think it's because windows doesn't like playing with 2 sets of "" quotes in the same command, just my guess here.)

Here comes a complicated part, choosing the value for affinity, notice below there are some letters, thats not a typo, the /affinity switch is looking for a Hexadecimal value. This should be fairly accurate, math was never my best subject though.

1 does processor 0
2 does processor 1
3 does processors 0 and 1
4 does processor 2
5 does processors 0 and 2
6 does processors 1 and 2
7 does processors 0, 1, and 2
8 does processor 3
9 does processor 0 and 3
D does processor 0, 2, and 3
F does processors 0, 1, 2, and 3


This Microsoft technet chart may help.
Microsoft Corporation

Also note, some programs are setup to force a specific affinity, I have run into some programs using this technique that will not take affinity settings past a certain number of CPU's. So for example, if you set /affinity F and the application is still not using all 4 cpus, this does not necessarily mean you did the command wrong, the program may just be enforcing it's affinity.

Now that you have your shortcut setup you can change the name, the icon, if your using Vista you can right click on the shortcut, change icon, and browse to the original .exe to use the same icon file.

This was driving me nuts for some time I hope this helps somebody out!
Reply With Quote
  #12  
By ..:: Free Radical ::.. on 13 Jan 08, 06:43 AM
Default Re: CPU Affinity Made Easy

manually setting affinity was needed in the days of the dual cores.
C2Ds, quads and modern AM2s don't need that due to recent optimizations and drivers.
I was also intrigued by affinity settings when I bought my am2. But my queries were answered by some old timers at amd forums.
Your boot.ini wud have the switche /usepmtimer if you have the optimal dual core drivers.
Last edited by ..:: Free Radical ::.. : 14 Jan 08 at 06:25 AM. Reason: Not threading instructions but drivers. My bad. Thats what gave me away :D
Reply With Quote
  #13  
By KingKrool on 13 Jan 08, 07:01 AM
Default Re: CPU Affinity Made Easy

View Post
Originally Posted by ..:: Free Radical ::..
C2Ds, quads and modern AM2s don't need that due to recent optimizations and threading instructions.
You really don't know what you are talking about, do you? Do you even know why there is a need (ever) for CPU affinity? Sorry for being argumentative, but multicore systems happen to be my bread and butter...
I am willing to accept that the Operating system can handle these issues, but not that the processors can (the current lot can't at any rate).
Certainly, perhaps with the newer drivers you can get around the bugs that sometimes occur on running some single threaded programs on multicore computers (Thief 3 comes to mind..), but there are many other issues involved. I do think however, that setting an affinity is at least conceptually a bad idea, but at least with Linux, it may some times be required (I haven't performed the same tests on Windows)
Last edited by KingKrool : 13 Jan 08 at 07:07 AM.
Reply With Quote
  #14  
By ..:: Free Radical ::.. on 14 Jan 08, 03:44 AM
Default Re: CPU Affinity Made Easy

View Post
Originally Posted by KingKrool
You really don't know what you are talking about, do you? Do you even know why there is a need (ever) for CPU affinity? Sorry for being argumentative, but multicore systems happen to be my bread and butter...
I do understand every word what I am talking about, and frankly can churn out a better automated script to do this on a per PID basis on Windows.
You can do on the fly affinity settings as soon as a particular application class/process is discovered, but you'd need a script in the background to run continuously to achieve that.

View Post
Originally Posted by KingKrool
but there are many other issues involved. I do think however, that setting an affinity is at least conceptually a bad idea, but at least with Linux, it may some times be required (I haven't performed the same tests on Windows)
I am on Windows. Some of you guys think you are the Crème de la Crème, with the right to preassume right.
btw, i don't need to show my credentials to assert that I am smarter (or pathetic).

On Topic:
Affinity setting may or may not be beneficial for those on quaddies or greater but its absolutely supefluous if you do it on a dual core with current drivers for windows.

Sorry for being argumentative
Last edited by ..:: Free Radical ::.. : 14 Jan 08 at 05:53 AM.
Reply With Quote
Comment


LinkBacks (?)
LinkBack to this Thread: http://www.techenclave.com/guides-and-tutorials/cpu-affinity-made-easy-67317.html
Posted By For Type Date
*Clix This thread Refback 19 Mar 08 04:15 PM
wiljacket's bookmarks on del.icio.us This thread Refback 14 Mar 08 10:59 AM
Article Tools
Display Modes


Welcome, Unregistered.

  
Search
Advertisement


From FunEnclave
Quick Navigation

All times are GMT +5.5. The time now is 06:12 PM.


Style by Safin, exclusive for TechEnclave
Copyright ©2005 - 2008 TechEnclave.com, All Rights Reserved.
Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0