如何使用sched_getaffinity(2)和了sched_setaffinity(2)。请给code样品中的C程序使用 [英] How to use sched_getaffinity(2) and sched_setaffinity(2) . Please give code sample to use in C program
问题描述
我试图
与处理器寄托运行16副本时(每个核心2份)
Run 16 copies concurrently with processor pinning (2 copies per core)
运行8份同时与处理器钉扎(每核心2份)和翻转处理器内核的某些功能之后最远的核心功能,说1完成。
Run 8 copies concurrently with processor pinning (2 copies per core) and flipping processor core to the furthest core after certain function say function 1 finishes.
我现在面临的问题是如何选择最远的处理器。
The problem I am facing is how to select the farthest processor.
有的朋友建议使用sched_getaffinity(2)了sched_setaffinity,但我不觉得任何的好例子。
Some friends suggested to use sched_getaffinity(2) and sched_setaffinity but I dont find any good examples.
请帮忙。
推荐答案
要使用了sched_setaffinity使核心7当前进程来看,你做到这一点:
To use sched_setaffinity to make the current process run on core 7 you do this:
cpu_set_t my_set; /* Define your cpu_set bit mask. */
CPU_ZERO(&my_set); /* Initialize it all to 0, i.e. no CPUs selected. */
CPU_SET(7, &my_set); /* set the bit that represents core 7. */
sched_setaffinity(0, sizeof(cpu_set_t), &my_set); /* Set affinity of tihs process to */
/* the defined mask, i.e. only 7. */
请参阅 http://linux.die.net/man/2/sched_setaffinity &安培; <一href=\"http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html\">http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html获取更多信息。
See http://linux.die.net/man/2/sched_setaffinity & http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html for more info.
这篇关于如何使用sched_getaffinity(2)和了sched_setaffinity(2)。请给code样品中的C程序使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!