Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stack memory usage at compile time #9963

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
30f0fa5
TEST/GTEST: reduce stack frame size in INSTANTIATE_TEST_SUITE_P macro
michal-shalev Jun 30, 2024
688a231
UCS/TESTS: reduce stack frame size in UCS_TEST_ macro
michal-shalev Jul 3, 2024
25a4418
TEST/PERF: convert stack allocation to heap
michal-shalev Jun 25, 2024
f1f75bd
UCS/BITOPS/TEST: reduce stack memory usage in is_equal test
michal-shalev Aug 13, 2024
e502ebc
UCS/TIME/TEST: reduce stack memory usage in timerq test
michal-shalev Aug 13, 2024
dab0220
UCS/MEMTRACK: initialize VFS before enabling memtrack and cleanup aft…
michal-shalev Aug 20, 2024
0bd0462
UCS/LOG: convert stack allocation at ucs_log_file_rotate() to heap
michal-shalev Jun 17, 2024
7369f1b
UCS/VFS: convert stack allocation at ucs_vfs_node_add() to heap
michal-shalev Jun 18, 2024
b281de3
UCS/MEMORY/NUMA: convert stack allocation at ucs_numa_node_of_cpu() t…
michal-shalev Aug 28, 2024
ec400d1
UCS/PARSER: convert stack allocation at ucs_config_parse_config_files…
michal-shalev Aug 27, 2024
2251af9
UCS/PARSER: convert stack allocation at ucs_config_parse_config_file(…
michal-shalev Aug 27, 2024
7917b58
UCS/STRING/GTEST: convert stack allocation at test_string path to heap
michal-shalev Aug 28, 2024
859d3f6
UCS/VFS/SOCK: convert stack allocation at ucs_vfs_sock_mkdir() to heap
michal-shalev Aug 29, 2024
714dd9a
UCS/VFS/BASE: convert stack allocation at ucs_vfs_node_add_subdir() t…
michal-shalev Aug 29, 2024
90155e0
UCS/VFS/FUSE: convert stack allocation at ucs_vfs_fuse_wait_for_path(…
michal-shalev Sep 6, 2024
93087c5
UCS/SYS/SOCK: convert stack allocation at ucs_netif_bond_ad_num_ports…
michal-shalev Aug 29, 2024
5a88a20
UCS/SYS/MODULE: convert stack allocation at ucs_module_load_one() to …
michal-shalev Jun 24, 2024
68d459d
UCS/SYS/MODULE: convert stack allocation at ucs_module_init() to heap
michal-shalev Sep 16, 2024
51e6a54
UCT/SM/MM: convert stack allocation at uct_posix_file_open() to heap
michal-shalev Aug 28, 2024
03ef359
UCT/SM/MM: convert stack allocation at uct_posix_procfs_open() to heap
michal-shalev Aug 28, 2024
a654ca8
UCT/SM/MM: convert stack allocation at uct_posix_unlink() to heap
michal-shalev Aug 28, 2024
c8cbbcc
UCT/TCP/BASE: convert stack allocation at uct_tcp_iface_get_sysfs_pat…
michal-shalev Aug 29, 2024
fda33cb
UCT/TCP: convert stack allocation at uct_tcp_iface_query() to heap
michal-shalev Jun 24, 2024
a8a2dd7
UCT/TCP: convert stack allocation at uct_tcp_is_bridge() to heap
michal-shalev Sep 6, 2024
53dbd1c
UCT/IB/BASE: convert stack allocation at uct_ib_device_query() to heap
michal-shalev Aug 29, 2024
55a1c8f
UCP/WORKER/GTEST: convert stack allocation at test_pci_bw get_pci_bw …
michal-shalev Aug 29, 2024
a470cb8
UCP/PROTO/DEBUG: convert stack allocation at ucp_proto_select_write_i…
michal-shalev Aug 29, 2024
e9dc94a
COMMON/HELPERS/GTEST: convert stack allocation at netif_has_sysfs_fil…
michal-shalev Aug 29, 2024
739f0cc
TOOLS/VFS: convert stack allocation at vfs_mount() to heap
michal-shalev Sep 6, 2024
bb819ae
TOOLS/VFS: convert stack allocation at vfs_unmount() to heap
michal-shalev Sep 16, 2024
2388f0d
TOOLS/INFO: reduce stack memory usage in print_type_info()
michal-shalev Sep 16, 2024
4f4b782
UCT/IB/MLX5/DV: convert stack allocation at uct_ib_mlx5_devx_md_open(…
michal-shalev Sep 16, 2024
d9cbe12
UCP/PROTO: convert stack allocation at ucp_proto_multi_init() to heap
michal-shalev Sep 16, 2024
416088e
BUILD/CONFIGURE: enforce 8KB stack threshold on compilation
michal-shalev Jun 19, 2024
35c1916
UCT/UD/TEST: convert stack allocation at connect_iface_2k test_ud to …
michal-shalev Jun 19, 2024
b0d3de4
UCM/TEST: reduce stack memory usage in test_thread test
michal-shalev Sep 11, 2024
8072eee
BUILD: debug stuff
michal-shalev Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions buildlib/tools/coverity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,18 @@ run_coverity() {
fi
cov-analyze --jobs $parallel_jobs $COV_OPT --security --concurrency --dir $cov_build
nerrors=$(cov-format-errors --dir $cov_build | awk '/Processing [0-9]+ errors?/ { print $2 }')
rc=$(($rc+$nerrors))

if [ $nerrors -gt 0 ]; then
cov-format-errors --dir $cov_build --emacs-style
cov_error_log="$(echo -e "\n$(cov-format-errors --dir $cov_build --emacs-style)")"
if [ -d "$WORKSPACE/$cov_build_id" ]; then
rm -rf $WORKSPACE/$cov_build_id
fi
cp -ar $cov_build $WORKSPACE/$cov_build_id
echo "not ok 1 Coverity Detected $nerrors failures"
else
echo "ok 1 Coverity found no issues"
rm -rf $cov_build
fi
modules_for_coverity_unload
return $rc
return $nerrors
}

parse_args $*
Expand All @@ -135,4 +132,9 @@ else
cd "${ucx_build_dir}"
fi

run_coverity "$mode"
run_coverity "$mode" || {
set +x
azure_log_error "Coverity found $nerrors issues: $cov_error_log"
azure_log_error "To debug, rerun with: $0 $mode"
exit 1
}
20 changes: 20 additions & 0 deletions config/m4/compiler.m4
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ AS_IF([test "x$enable_gcov" = xyes],
[AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])])],
[:])

#
# Enable stack usage check
#
# To suppress -Wframe-larger-than=8192 for specific functions, use:
# #pragma GCC diagnostic push
# #pragma GCC diagnostic ignored "-Wframe-larger-than="
# void specific_function() {
# /* Function code */
# }
# #pragma GCC diagnostic pop
#
AC_ARG_ENABLE([stack-usage-check],
AS_HELP_STRING([--enable-stack-usage-check], [Enable stack usage check with -Wframe-larger-than=8192]),
[],
[enable_stack_usage_check=yes])

AS_IF([test "x$enable_stack_usage_check" = xyes],
[ADD_COMPILER_FLAG_IF_SUPPORTED([stack_usage_check], [-Wframe-larger-than=8192],
[AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])])],
[:])
Comment on lines +452 to +471
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force flag only in builds.sh


#
# Check for C++ support
Expand Down
14 changes: 14 additions & 0 deletions contrib/test_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,19 @@ run_tests() {
do_distributed_task 0 4 run_nt_buffer_transfer_tests
}

error_handler() {
set +x
local exit_code=$?
local test_name="$1"
local flag="$2"

azure_log_error "$test_name failed"
azure_log_error "To debug, rerun with: $flag $0"
exit $exit_code
}

run_test_proto_disable() {
trap 'error_handler "Proto V1 test" "PROTO_ENABLE=no"' ERR
# build for devel tests and gtest
build devel --enable-gtest

Expand All @@ -1130,11 +1142,13 @@ run_test_proto_disable() {
}

run_asan_check() {
trap 'error_handler "AddressSanitizer check" "ASAN_CHECK=yes"' ERR
build devel --enable-gtest --enable-asan --without-valgrind
run_gtest "default"
}

run_valgrind_check() {
trap 'error_handler "Valgrind check" "VALGRIND_CHECK=yes"' ERR
if [[ $(uname -m) =~ "aarch" ]] || [[ $(uname -m) =~ "ppc" ]]; then
echo "==== Skip valgrind tests on `uname -m` ===="
return
Expand Down
61 changes: 42 additions & 19 deletions src/tools/info/type_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void print_size(const char *name, size_t size)
print_size(UCS_PP_QUOTE(_type) "." UCS_PP_QUOTE(_field), \
ucs_field_sizeof(_type, _field))

void print_type_info(const char * tl_name)
static void print_ucs(const char *tl_name)
{
if (tl_name == NULL) {
printf("UCS:\n");
Expand Down Expand Up @@ -131,8 +131,13 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(ucs_rcache_region_t);
PRINT_SIZE(ucs_conn_match_elem_t);
PRINT_SIZE(ucs_memory_info_t);
}
}

printf("\nUCT:\n");
static void print_uct(const char *tl_name)
{
if (tl_name == NULL) {
printf("UCT:\n");
PRINT_SIZE(uct_am_handler_t);
PRINT_SIZE(uct_base_iface_t);
PRINT_SIZE(uct_completion_t);
Expand All @@ -152,13 +157,11 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(uct_rkey_bundle_t);
PRINT_SIZE(uct_tcp_ep_t);
PRINT_SIZE(uct_self_ep_t);
}
}

#ifdef HAVE_TL_UGNI
PRINT_SIZE(uct_sockaddr_ugni_t);
PRINT_SIZE(uct_sockaddr_smsg_ugni_t);
PRINT_SIZE(uct_devaddr_ugni_t);
#endif

static void print_ib(const char *tl_name)
{
#if HAVE_IB
printf("\nIB:\n");
PRINT_SIZE(uct_ib_address_t);
Expand All @@ -170,13 +173,13 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(uct_ib_iface_recv_desc_t);
PRINT_SIZE(uct_ib_recv_wr_t);
#endif
printf("\n");
}
}

static void print_rc(const char *tl_name)
{
#if HAVE_TL_RC
if (tl_name == NULL || !strcasecmp(tl_name, "rc_verbs") ||
!strcasecmp(tl_name, "rc_mlx5"))
{
!strcasecmp(tl_name, "rc_mlx5")) {
printf("RC:\n");
PRINT_SIZE(uct_rc_am_short_hdr_t);
PRINT_SIZE(uct_rc_ep_t);
Expand All @@ -185,14 +188,12 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(uct_rc_iface_config_t);
PRINT_SIZE(uct_rc_iface_send_op_t);
PRINT_SIZE(uct_rc_iface_send_desc_t);

PRINT_SIZE(uct_rc_iface_send_desc_t);
if (tl_name == NULL || !strcasecmp(tl_name, "rc_verbs")) {
PRINT_SIZE(uct_rc_verbs_ep_t);
PRINT_SIZE(uct_rc_verbs_iface_config_t);
PRINT_SIZE(uct_rc_verbs_iface_t);
}

#ifdef HAVE_MLX5_DV
if (tl_name == NULL || !strcasecmp(tl_name, "rc_mlx5")) {
PRINT_SIZE(uct_rc_mlx5_am_short_hdr_t);
Expand All @@ -205,7 +206,10 @@ void print_type_info(const char * tl_name)
printf("\n");
}
#endif
}

static void print_dc(const char *tl_name)
{
#if HAVE_TL_DC
if (tl_name == NULL || !strcasecmp(tl_name, "dc_mlx5"))
{
Expand All @@ -217,11 +221,13 @@ void print_type_info(const char * tl_name)
printf("\n");
}
#endif
}

static void print_ud(const char *tl_name)
{
#if HAVE_TL_UD
if (tl_name == NULL || !strcasecmp(tl_name, "ud_verbs") ||
!strcasecmp(tl_name, "ud_mlx5"))
{
!strcasecmp(tl_name, "ud_mlx5")) {
printf("UD:\n");
PRINT_SIZE(uct_ud_ep_t);
PRINT_SIZE(uct_ud_neth_t);
Expand All @@ -230,13 +236,11 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(uct_ud_ep_pending_op_t);
PRINT_SIZE(uct_ud_send_skb_t);
PRINT_SIZE(uct_ud_recv_skb_t);

PRINT_SIZE(uct_rc_iface_send_desc_t);
if (tl_name == NULL || !strcasecmp(tl_name, "ud_verbs")) {
PRINT_SIZE(uct_ud_verbs_ep_t);
PRINT_SIZE(uct_ud_verbs_iface_t);
}

#ifdef HAVE_MLX5_HW_UD
if (tl_name == NULL || !strcasecmp(tl_name, "ud_mlx5")) {
PRINT_SIZE(uct_ud_mlx5_ep_t);
Expand All @@ -246,20 +250,28 @@ void print_type_info(const char * tl_name)
printf("\n");
}
#endif
}

static void print_ugni(const char *tl_name)
{
#ifdef HAVE_TL_UGNI
if (tl_name == NULL || !strcasecmp(tl_name, "ugni")) {
printf("UGNI:\n");
PRINT_SIZE(uct_sockaddr_ugni_t);
PRINT_SIZE(uct_sockaddr_smsg_ugni_t);
PRINT_SIZE(uct_devaddr_ugni_t);
PRINT_SIZE(uct_ugni_device_t);
PRINT_SIZE(uct_ugni_ep_t);
PRINT_SIZE(uct_ugni_iface_t);
PRINT_SIZE(uct_ugni_md_t);
PRINT_SIZE(uct_ugni_compact_smsg_attr_t);

printf("\n");
}
#endif
}

static void print_ucp()
{
printf("\nUCP:\n");
PRINT_SIZE(ucp_context_t);
PRINT_SIZE(ucp_worker_t);
Expand Down Expand Up @@ -291,5 +303,16 @@ void print_type_info(const char * tl_name)
PRINT_SIZE(ucp_mem_t);
PRINT_SIZE(ucp_rkey_t);
PRINT_SIZE(ucp_wireup_msg_t);
}

void print_type_info(const char *tl_name)
{
print_ucs(tl_name);
print_uct(tl_name);
print_ib(tl_name);
print_rc(tl_name);
print_dc(tl_name);
print_ud(tl_name);
print_ugni(tl_name);
print_ucp();
}
76 changes: 55 additions & 21 deletions src/tools/perf/lib/ucp_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,35 +1033,69 @@ class ucp_perf_test_runner {
#define TEST_CASE_ALL_AM(_perf, _case) \
TEST_CASE(_perf, UCS_PP_TUPLE_0 _case, UCS_PP_TUPLE_1 _case, 0, 0)

ucs_status_t ucp_perf_test_dispatch(ucx_perf_context_t *perf)
static ucs_status_t dispatch_osd(ucx_perf_context_t *perf)
{
UCS_PP_FOREACH(TEST_CASE_ALL_OSD, perf,
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_PINGPONG_WAIT_MEM),
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_GET, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_ADD, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_FADD, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_SWAP, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_CSWAP, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_PINGPONG_WAIT_MEM),
(UCX_PERF_CMD_PUT, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_GET, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_ADD, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_FADD, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_SWAP, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_CSWAP, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
return UCS_ERR_INVALID_PARAM;
}

static ucs_status_t dispatch_tag(ucx_perf_context_t *perf)
{
UCS_PP_FOREACH(TEST_CASE_ALL_TAG, perf,
(UCX_PERF_CMD_TAG, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_TAG, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_TAG_SYNC, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_TAG_SYNC, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
(UCX_PERF_CMD_TAG, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_TAG, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_TAG_SYNC, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_TAG_SYNC, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
return UCS_ERR_INVALID_PARAM;
}

static ucs_status_t dispatch_stream(ucx_perf_context_t *perf)
{
UCS_PP_FOREACH(TEST_CASE_ALL_STREAM, perf,
(UCX_PERF_CMD_STREAM, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_STREAM, UCX_PERF_TEST_TYPE_PINGPONG)
);
(UCX_PERF_CMD_STREAM, UCX_PERF_TEST_TYPE_STREAM_UNI),
(UCX_PERF_CMD_STREAM, UCX_PERF_TEST_TYPE_PINGPONG)
);
return UCS_ERR_INVALID_PARAM;
}

static ucs_status_t dispatch_am(ucx_perf_context_t *perf)
{
UCS_PP_FOREACH(TEST_CASE_ALL_AM, perf,
(UCX_PERF_CMD_AM, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_AM, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
(UCX_PERF_CMD_AM, UCX_PERF_TEST_TYPE_PINGPONG),
(UCX_PERF_CMD_AM, UCX_PERF_TEST_TYPE_STREAM_UNI)
);
return UCS_ERR_INVALID_PARAM;
}

typedef ucs_status_t (*ucp_dispatch_func_t)(ucx_perf_context_t *perf);

static ucp_dispatch_func_t dispatchers[] = {
dispatch_osd,
dispatch_tag,
dispatch_stream,
dispatch_am
};

ucs_status_t ucp_perf_test_dispatch(ucx_perf_context_t *perf) {
ucs_status_t status;
int num_dispatchers = sizeof(dispatchers) / sizeof(dispatchers[0]);

for (int i = 0; i < num_dispatchers; ++i) {
status = dispatchers[i](perf);
if (status != UCS_ERR_INVALID_PARAM) {
return status;
}
}

ucs_error("Invalid test case: %d/%d/0x%x",
perf->params.command, perf->params.test_type,
Expand Down
3 changes: 3 additions & 0 deletions src/tools/perf/lib/uct_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ class uct_perf_test_runner {
TEST_CASE_ALL_OSD(_perf, _case, UCT_PERF_DATA_LAYOUT_BCOPY) \
TEST_CASE_ALL_OSD(_perf, _case, UCT_PERF_DATA_LAYOUT_ZCOPY)

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-larger-than="
ucs_status_t uct_perf_test_dispatch(ucx_perf_context_t *perf)
{
UCS_PP_FOREACH(TEST_CASE_ALL_DATA, perf,
Expand All @@ -801,3 +803,4 @@ ucs_status_t uct_perf_test_dispatch(ucx_perf_context_t *perf)
ucs_error("Invalid test case");
return UCS_ERR_INVALID_PARAM;
}
#pragma GCC diagnostic pop
Loading
Loading