find a way to create Thread binded to LogicalCore properly
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
/* Pin the calling thread to a single logical processor.
|
||||
* core_id >= 0 : bind to that logical processor (global index, across groups).
|
||||
* core_id < 0 : clear affinity constraint within the current group. */
|
||||
SN_API void SN_DECL sn_set_thread_affinity(int core_id)
|
||||
SN_API void SN_DECL sn_set_thread_affinity(int core_id, int numa_id)
|
||||
{
|
||||
if (core_id < 0) {
|
||||
if (core_id < 0 || numa_id < 0) {
|
||||
/* Query which group the thread currently belongs to */
|
||||
GROUP_AFFINITY current;
|
||||
GetThreadGroupAffinity(GetCurrentThread(), ¤t);
|
||||
@@ -21,14 +21,13 @@ SN_API void SN_DECL sn_set_thread_affinity(int core_id)
|
||||
SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL);
|
||||
return;
|
||||
}
|
||||
WORD group = (WORD)(core_id / 64);
|
||||
int index = core_id % 64;
|
||||
DWORD count = GetActiveProcessorCount(group);
|
||||
DWORD count = GetActiveProcessorCount(numa_id);
|
||||
if ((DWORD)index >= count)
|
||||
return;
|
||||
GROUP_AFFINITY ga;
|
||||
memset(&ga, 0, sizeof(ga));
|
||||
ga.Group = group;
|
||||
ga.Group = (WORD)numa_id;
|
||||
ga.Mask = (KAFFINITY)1 << index;
|
||||
SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user