2
votes

I know that there are ways to enforce thread/process affinity to bind a particular thread/process to a CPU/core in various OSs. I am just wondering if there is a way to enforce the CPU Socket affinity. i.e. to enforce a thread/process to be bound to a CPU Socket which can house a multiprocessor chip.

The question arises due to the fact that multi-processors per chip are increasing day by day.

2

2 Answers

1
votes

The only way I know of doing this is to find out which thread IDs map to which socket (or NUMA node). Once you have this information, you can use the usual thread-binding methods to enforce it.

If you're on Linux, you can use the numactl.h library to find out which hardware thread belongs on which NUMA node. Although a NUMA node isn't always one-to-one with a socket, it is the case for all post-Core 2 Xeons and all Opteron systems to date.

On Windows, you can use GetNumaNodeProcessorMask to figure out which hardware threads are on a node.

In the case where they don't map one-to-one (such as the Core 2 Xeons, where both sockets are on the same NUMA node), it probably won't matter anyway from a performance standpoint unless you're trying to micromanage the shared cache on each processor.

1
votes

If i understand your question correctly, all you need to do is set the affinity of the process or thread to be the set of cores that reside on a CPU.

Depending on your operating system, there are ways to deduce this information. For example, in linux, you can look at /proc/cpuinfo and see which cores belong to a given processor.