开发者

CPU-Core thread classification Function

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜