views:

174

answers:

1

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.

+1  A: 

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.

Nikolai N Fetissov
(+1) for the article and the tips. I read up on the calls and the article.
Hassan Syed
best answer so far :D
Hassan Syed