Monday, March 19, 2007

Process Affinity

Processor affinity is a modification of the native central queue scheduling algorithm. Each task (be it process or thread) in the queue has a tag indicating its preferred / kin processor. At allocation time, each task is allocated to its kin processor in preference to others.

Processor affinity takes advantage of the fact that some remnants of a process may remain in one processor's state (in particular, in its cache) from the last time the process ran, and so scheduling it to run on the same processor the next time could result in the process running more efficiently than if it were to run on another processor.

win32process.SetProcessAffinityMask

SetProcessAffinityMask(handle, mask)

Sets a processor affinity mask for a specified process.

Parameters


win32process.SetThreadAffinityMask

int = SetThreadAffinityMask(handle, mask )

Sets a processor affinity mask for a specified thread.


def SetProcessorAffinity(self):
try:
import win32api, win32process

# get number of processors
systemInfo = win32api.GetSystemInfo()
numprocs = systemInfo[5]

# if multiple procs, set processor affinity to the first
# this sets proc affinity for children also, so vic will get this
# (vic is ill-behaved on multiproc machines)
if numprocs > 1:
log.info("Found %d processors; setting affinity",numprocs)
cp = win32api.GetCurrentProcess()
win32process.SetProcessAffinityMask(cp, 1)

except Exception,e:
log.exception("Exception setting processor affinity")

0 Comments:

Post a Comment

<< Home