HOW TO: Process/File Affinity, Imagecfg Control

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

HOW TO: Process/File Affinity, Imagecfg Control

Post by YARDofSTUF »

With HyperThreading and Dual Core CPUs being common in all kinds of systems there may be alot of people interested in controlling which processes use which CPU. This would work for Dual CPU systems to.

The program to use for this is Imagecfg.exe. You can google it to find a download, or get it off of a Windows 2000 or Windows XP Server Resource Kit.


Imagecfg.exe will work with Windows XP(32 bit and 64 bit), Windows 2000, Windows 2003, and hopefully Windows Vista. It is a permanent change to the file, so make a backup before testing.


Imagecfg.exe has a bunch of uses, use the "/?" switch to see all of your choices.


To set a process's affinity use "imagecfg -a 0xn [File Path] [File Name]

Replace n with the CPU you want the process to use.

1 = CPU0
2 = CPU1
4 = CPU2
8 = CPU3

So if you wanted to set C:\Test\Dummy.exe to use the second CPU(CPU1) ir would look like this:

imagecfg -a 0x2 C:\Test\Dummy.exe

For dual core or dual CPU users both CPUs will perform equally, but with HyperThreading enabled systems the first CPU (CPU0) is faster, because the 2nd CPU is just a virtual CPU recycling unused cycles from the first CPU.

By moving processes around it can allow you maximize the performance of CPU intensive programs and games by assigning all necessary processes to 1 CPU, freeing the other CPU for the intensive application.

I've just started messing around with this so I don't have any benchmarks or proof that this does anything, theoretically it should help, most likely in a very small ammount though.


Flaws:
Imagecfg does not seem to recognize folders with spaces in it like "C:\Program Files". To get by this copy the Imagecfg.exe file to that directory and exclude the directory /path.


I'll update this with more information as I get it. Mark and Scott on here, Robpol86.com, and PlanetAMD64 Helped me get all this info.
Scott
Senior Member
Posts: 3846
Joined: Thu Feb 14, 2002 12:00 pm

Post by Scott »

Well, not all of it. ;)
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

[quote="Scott"]Well, not all of it. ]


My bad, I left you out!

I'm not even sure how to benchmark this effectively.
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

are you still using this YoS ?

might try it myself i guess.
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:are you still using this YoS ?

might try it myself i guess.

Yup, use it for folding, run the games off the 2nd core, split EAC and LAME.

Works out good.
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

*bump*

just wanted to thank ya YoS, i was having to reset the affinity on each new
work unit, just tried setting this up with F@H and it works just fine.

:thumb:
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:*bump*

just wanted to thank ya YoS, i was having to reset the affinity on each new
work unit, just tried setting this up with F@H and it works just fine.

:thumb:

Cool, glad it works for ya too. Do remember that each new core you download will start off trying to use both.
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

YARDofSTUF wrote:Cool, glad it works for ya too. Do remember that each new core you download will start off trying to use both.
so does that mean i have to start it and then restart it to have the affinity set with that comand ?
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:so does that mean i have to start it and then restart it to have the affinity set with that comand ?

I usually stop F@H, then run imagecfg then reload F@H
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

mine seems to be saving the affinity setting on new work units according to the task manager.
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:mine seems to be saving the affinity setting on new work units according to the task manager.

New units yes, new cores are what I mean. the other *.exe files.
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

ah i see, i set the imagecfg to the console.exe, did you set yours to the individual cores ?

i wonder if i did this right :rotfl:

i followed the instructions here and used "imagecfg -a 0x1 c:\path\to\file.exe", where file.exe is the console.exe
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:ah i see, i set the imagecfg to the console.exe, did you set yours to the individual cores ?

i wonder if i did this right :rotfl:

i followed the instructions here and used "imagecfg -a 0x1 c:\path\to\file.exe", where file.exe is the console.exe
I did it to each *.exe file.
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

YARDofSTUF wrote:I did it to each *.exe file.
console or core exe ?
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Mark wrote:console or core exe ?

all
User avatar
Mark
Posts: 13238
Joined: Wed Apr 11, 2001 12:00 am
Location: .

Post by Mark »

i just set the console affinity and it seems to work.
graysky
Member
Posts: 56
Joined: Thu May 03, 2007 3:05 pm

Post by graysky »

Great guide, thanks. How can I undo the settings I added? In other words I want to enable the app on all the cores (I have a q6600)?

Thanks.
graysky
Member
Posts: 56
Joined: Thu May 03, 2007 3:05 pm

Post by graysky »

graysky wrote:Great guide, thanks. How can I undo the settings I added? In other words I want to enable the app on all the cores (I have a q6600)?
The answer is to backup the exe first since this utility literally modifies the exe you point it to use. It's only useful if you literally want the app to stay running on one and only one core.
Shadwell
New Member
Posts: 1
Joined: Sat Oct 23, 2010 11:30 am

Post by Shadwell »

Flaws:
Imagecfg does not seem to recognize folders with spaces in it like "C:\Program Files". To get by this copy the Imagecfg.exe file to that directory and exclude the directory /path.
Enclose the path with "" and spaces are no problem.

Sorry for the bump but I found this guide still very helpfull running Simcity 4 on my core 2 duo, maybe others might too.
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Good to know it works for you. I still use this for running multiple instances of EAC.
User avatar
YARDofSTUF
Posts: 70006
Joined: Sat Nov 11, 2000 12:00 am
Location: USA

Post by YARDofSTUF »

Post Reply