Question

I'm going to be writing a multi-threaded shared memory messaging system for ultra high-volume message delivery between processes. The messages will originate from the worker threads of a web-server. I'd like to exploit the CPU cache locality that cores on the same CPU share. So that when I wake up a worker thread on the receiving end of this IPC system, I wake up a thread on the same CPU.

I need for Linux (prefferably POSIX in genaral) and windows the API calls and the bitmasking I need to do to extract the information which will let me classify the executing thread-id -- from the context of said thread -- using the following struct:

struct thread_core_id
{
    uint16_t cpu_Id;
    uint16_t core_Id;
};

Functions for both platforms will be greatly appreciated. I'm hoping this can be done without system calls -- i.e., context-switches.

-- edit --

I'm focusing on x86 at the moment, but other architectures would be useful as well.

Was it helpful?

Solution

For Linux specifically you should be able to get the required information out of /proc/cpuinfo and /sys/devices/system/cpu/cpu*/cache and use that with sched_{s|g}etaffinity() calls. Take a look at What Every Programmer Should Know About Memory, if you haven't already, around section 5.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top