find a way to create Thread binded to LogicalCore properly
This commit is contained in:
@@ -137,7 +137,7 @@ static int sn_linux_count_cpu_list(char const *path)
|
||||
if (!sn_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
sn_linux_counter_context counter = {0};
|
||||
sn_linux_counter_context counter = { 0 };
|
||||
if (!sn_linux_visit_id_list(buffer, sn_linux_count_id, &counter))
|
||||
return 0;
|
||||
|
||||
@@ -173,8 +173,7 @@ static size_t sn_linux_round_up_to_page_size(size_t size)
|
||||
return rounded - (rounded % effective_page_size);
|
||||
}
|
||||
|
||||
static int sn_linux_bind_memory_to_node(void *address, size_t size, int numa_id,
|
||||
uint32_t flags)
|
||||
static int sn_linux_bind_memory_to_node(void *address, size_t size, int numa_id, uint32_t flags)
|
||||
{
|
||||
#if defined(SYS_mbind)
|
||||
size_t bits_per_word = sizeof(unsigned long) * 8u;
|
||||
@@ -185,9 +184,8 @@ static int sn_linux_bind_memory_to_node(void *address, size_t size, int numa_id,
|
||||
|
||||
node_mask[(size_t)numa_id / bits_per_word] = 1ul << ((size_t)numa_id % bits_per_word);
|
||||
|
||||
int syscall_result = (int)syscall(SYS_mbind, address, size,
|
||||
MPOL_BIND | MPOL_F_STATIC_NODES, node_mask,
|
||||
(unsigned long)numa_id + 1ul, flags);
|
||||
int syscall_result = (int)syscall(SYS_mbind, address, size, MPOL_BIND | MPOL_F_STATIC_NODES,
|
||||
node_mask, (unsigned long)numa_id + 1ul, flags);
|
||||
free(node_mask);
|
||||
return syscall_result == 0;
|
||||
#else
|
||||
@@ -216,7 +214,7 @@ static int sn_linux_populate_writable_mapping(void *address, size_t size)
|
||||
/* 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)
|
||||
{
|
||||
int cpu_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (cpu_count <= 0)
|
||||
@@ -246,7 +244,7 @@ SN_API int SN_DECL sn_get_numa_overall(int *out_numa_count, int *count_of_each_n
|
||||
if (!sn_linux_read_first_line("/sys/devices/system/node/online", buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
sn_linux_max_context max_context = {-1};
|
||||
sn_linux_max_context max_context = { -1 };
|
||||
if (!sn_linux_visit_id_list(buffer, sn_linux_track_max_id, &max_context) ||
|
||||
max_context.max_value < 0)
|
||||
return 0;
|
||||
@@ -258,7 +256,7 @@ SN_API int SN_DECL sn_get_numa_overall(int *out_numa_count, int *count_of_each_n
|
||||
for (int index = 0; index <= max_context.max_value; index++)
|
||||
count_of_each_numa[index] = 0;
|
||||
|
||||
sn_linux_fill_node_count_context fill_context = {count_of_each_numa};
|
||||
sn_linux_fill_node_count_context fill_context = { count_of_each_numa };
|
||||
if (!sn_linux_visit_id_list(buffer, sn_linux_fill_node_cpu_count, &fill_context))
|
||||
return 0;
|
||||
}
|
||||
@@ -277,7 +275,7 @@ SN_API int SN_DECL sn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *g
|
||||
if (!sn_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
sn_linux_fill_cpu_context fill_context = {internal, global, 0};
|
||||
sn_linux_fill_cpu_context fill_context = { internal, global, 0 };
|
||||
return sn_linux_visit_id_list(buffer, sn_linux_fill_cpu_id, &fill_context);
|
||||
}
|
||||
|
||||
@@ -293,8 +291,7 @@ SN_API void *SN_DECL sn_numa_alloc(size_t size, int numa_id)
|
||||
mmap_flags |= MAP_POPULATE;
|
||||
#endif
|
||||
|
||||
void *memory = mmap(NULL, allocation_size, PROT_READ | PROT_WRITE,
|
||||
mmap_flags, -1, 0);
|
||||
void *memory = mmap(NULL, allocation_size, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
|
||||
if (memory == MAP_FAILED)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user