From bb29dc816ac6fe8678765c3b869f47326b942367 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Tue, 29 Oct 2024 09:34:07 -0700 Subject: [PATCH] check if numa available or not before loading numa functions (#1163) --- source/common.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/source/common.c b/source/common.c index 1822f93e2..a391f4fcb 100644 --- a/source/common.c +++ b/source/common.c @@ -358,26 +358,32 @@ void aws_common_library_init(struct aws_allocator *allocator) { } else { AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_available() failed to load"); } - - *(void **)(&g_numa_num_configured_nodes_ptr) = dlsym(g_libnuma_handle, "numa_num_configured_nodes"); - if (g_numa_num_configured_nodes_ptr) { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_configured_nodes() loaded"); + if (g_numa_available_ptr() == -1) { + AWS_LOGF_INFO( + AWS_LS_COMMON_GENERAL, + "static: numa_available() returns -1, numa functions are not available. Skip loading the other " + "numa functions."); } else { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_configured_nodes() failed to load"); - } + *(void **)(&g_numa_num_configured_nodes_ptr) = dlsym(g_libnuma_handle, "numa_num_configured_nodes"); + if (g_numa_num_configured_nodes_ptr) { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_configured_nodes() loaded"); + } else { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_configured_nodes() failed to load"); + } - *(void **)(&g_numa_num_possible_cpus_ptr) = dlsym(g_libnuma_handle, "numa_num_possible_cpus"); - if (g_numa_num_possible_cpus_ptr) { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_possible_cpus() loaded"); - } else { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_possible_cpus() failed to load"); - } + *(void **)(&g_numa_num_possible_cpus_ptr) = dlsym(g_libnuma_handle, "numa_num_possible_cpus"); + if (g_numa_num_possible_cpus_ptr) { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_possible_cpus() loaded"); + } else { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_num_possible_cpus() failed to load"); + } - *(void **)(&g_numa_node_of_cpu_ptr) = dlsym(g_libnuma_handle, "numa_node_of_cpu"); - if (g_numa_node_of_cpu_ptr) { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_node_of_cpu() loaded"); - } else { - AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_node_of_cpu() failed to load"); + *(void **)(&g_numa_node_of_cpu_ptr) = dlsym(g_libnuma_handle, "numa_node_of_cpu"); + if (g_numa_node_of_cpu_ptr) { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_node_of_cpu() loaded"); + } else { + AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: numa_node_of_cpu() failed to load"); + } } } else {