How to use sched_getaffinity and sched_setaffinity in Linux from C?

后端 未结 3 468
清歌不尽
清歌不尽 2020-12-03 05:29

I am trying to:

  • Run 16 copies concurrently with processor pinning (2 copies per core)

  • Run 8 copies concurrently with processor pinning (2 co

3条回答
  •  遥遥无期
    2020-12-03 06:07

    Don't use CPU_SETSIZE as cpusetsize parameter for sched_[set|get]affinity. The names are misleading but this is wrong. The macro CPU_SETSIZE is (quoting man 3 cpu_set) "a value one greater than the maximum CPU number that can be stored in cpu_set_t." You have to use

    sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
    

    instead.

提交回复
热议问题