From 8acb59d0c66d917c2ca6b31bef7ab93d7df57332 Mon Sep 17 00:00:00 2001 From: Wenduo Wang Date: Thu, 1 Aug 2024 00:06:15 +0000 Subject: [PATCH] opal,ompi: move container_of definition to its own header Centralize container_of macro definition so that we don't have to define it everywhere. Signed-off-by: Wenduo Wang --- contrib/check_unnecessary_headers.sh | 23 ++++++++++++----------- ompi/mca/mtl/ofi/mtl_ofi.h | 1 + opal/mca/btl/usnic/btl_usnic.h | 5 +---- opal/util/Makefile.am | 1 + opal/util/bipartite_graph.c | 5 +---- opal/util/misc.h | 27 +++++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 opal/util/misc.h diff --git a/contrib/check_unnecessary_headers.sh b/contrib/check_unnecessary_headers.sh index bac0e427951..d11e5bf467f 100644 --- a/contrib/check_unnecessary_headers.sh +++ b/contrib/check_unnecessary_headers.sh @@ -116,17 +116,18 @@ SEARCH_HEADER[30]="opal/util/convert.h opal_size2int" SEARCH_HEADER[31]="opal/util/daemon_init.h opal_daemon_init" SEARCH_HEADER[32]="opal/util/error.h opal_perror opal_strerror opal_strerror_r opal_err2str_fn_t opal_error_register" SEARCH_HEADER[33]="opal/util/if.h IF_NAMESIZE opal_ifnametoaddr opal_ifaddrtoname opal_ifnametoindex opal_ifnametokindex opal_ifindextokindex opal_ifcount opal_ifbegin opal_ifnext opal_ifindextoname opal_ifkindextoname opal_ifindextoaddr opal_ifindextomask opal_ifindextoflags opal_ifislocal opal_iffinalize" -SEARCH_HEADER[34]="opal/util/net.h opal_net_init opal_net_finalize opal_net_prefix2netmask opal_net_islocalhost opal_net_samenetwork opal_net_addr_isipv4public opal_net_get_hostname opal_net_get_port" -SEARCH_HEADER[35]="opal/util/opal_environ.h opal_environ_merge opal_setenv opal_unsetenv opal_home_directory opal_tmp_directory environ" -SEARCH_HEADER[36]="opal/util/opal_getcwd.h opal_getcwd" -SEARCH_HEADER[37]="opal/util/os_dirpath.h opal_os_dirpath_create opal_os_dirpath_is_empty opal_os_dirpath_access opal_os_dirpath_destroy" -SEARCH_HEADER[38]="opal/util/os_path.h opal_os_path opal_make_filename_os_friendly" -SEARCH_HEADER[39]="opal/util/output.h opal_output_stream_t opal_output_init opal_output_finalize opal_output_open opal_output_reopen opal_output_switch opal_output_reopen_all opal_output_close opal_output opal_output_verbose opal_output_vverbose opal_output_string opal_output_vstring opal_output_set_verbosity opal_output_get_verbosity opal_output_set_output_file_info OPAL_OUTPUT OPAL_OUTPUT_VERBOSE" -SEARCH_HEADER[40]="opal/util/path.h opal_path_find opal_path_findv opal_path_is_absolute opal_find_absolute_path opal_path_access" -SEARCH_HEADER[41]="opal/util/printf.h snprintf vsnprintf" -SEARCH_HEADER[42]="opal/util/show_help.h opal_show_help_init opal_show_help_finalize opal_show_help opal_show_vhelp opal_show_help_string opal_show_help_finish_parsing" -SEARCH_HEADER[43]="opal/util/strncpy.h opal_strncpy" -SEARCH_HEADER[44]="" +SEARCH_HEADER[34]="opal/util/misc.h container_of" +SEARCH_HEADER[35]="opal/util/net.h opal_net_init opal_net_finalize opal_net_prefix2netmask opal_net_islocalhost opal_net_samenetwork opal_net_addr_isipv4public opal_net_get_hostname opal_net_get_port" +SEARCH_HEADER[36]="opal/util/opal_environ.h opal_environ_merge opal_setenv opal_unsetenv opal_home_directory opal_tmp_directory environ" +SEARCH_HEADER[37]="opal/util/opal_getcwd.h opal_getcwd" +SEARCH_HEADER[38]="opal/util/os_dirpath.h opal_os_dirpath_create opal_os_dirpath_is_empty opal_os_dirpath_access opal_os_dirpath_destroy" +SEARCH_HEADER[39]="opal/util/os_path.h opal_os_path opal_make_filename_os_friendly" +SEARCH_HEADER[40]="opal/util/output.h opal_output_stream_t opal_output_init opal_output_finalize opal_output_open opal_output_reopen opal_output_switch opal_output_reopen_all opal_output_close opal_output opal_output_verbose opal_output_vverbose opal_output_string opal_output_vstring opal_output_set_verbosity opal_output_get_verbosity opal_output_set_output_file_info OPAL_OUTPUT OPAL_OUTPUT_VERBOSE" +SEARCH_HEADER[41]="opal/util/path.h opal_path_find opal_path_findv opal_path_is_absolute opal_find_absolute_path opal_path_access" +SEARCH_HEADER[42]="opal/util/printf.h snprintf vsnprintf" +SEARCH_HEADER[43]="opal/util/show_help.h opal_show_help_init opal_show_help_finalize opal_show_help opal_show_vhelp opal_show_help_string opal_show_help_finish_parsing" +SEARCH_HEADER[44]="opal/util/strncpy.h opal_strncpy" +SEARCH_HEADER[45]="" delete_unnessary_header . diff --git a/ompi/mca/mtl/ofi/mtl_ofi.h b/ompi/mca/mtl/ofi/mtl_ofi.h index 84502505c9f..aae756b0518 100644 --- a/ompi/mca/mtl/ofi/mtl_ofi.h +++ b/ompi/mca/mtl/ofi/mtl_ofi.h @@ -24,6 +24,7 @@ #include "ompi/mca/mtl/mtl.h" #include "ompi/mca/mtl/base/base.h" #include "opal/datatype/opal_convertor.h" +#include "opal/util/misc.h" #include "opal/util/show_help.h" #include "opal/util/printf.h" diff --git a/opal/mca/btl/usnic/btl_usnic.h b/opal/mca/btl/usnic/btl_usnic.h index 93bf3af239b..eeddcdfbb40 100644 --- a/opal/mca/btl/usnic/btl_usnic.h +++ b/opal/mca/btl/usnic/btl_usnic.h @@ -35,6 +35,7 @@ #include "opal/class/opal_hash_table.h" #include "opal/util/alfg.h" #include "opal/util/event.h" +#include "opal/util/misc.h" #include "opal_stdint.h" #include "opal/mca/btl/base/base.h" @@ -65,10 +66,6 @@ static inline uint64_t get_ticks(void) /* RNG buffer declaration */ extern opal_rng_buff_t opal_btl_usnic_rand_buff; -#ifndef container_of -# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member))) -#endif - #ifndef max # define max(a, b) (((a) > (b)) ? (a) : (b)) #endif diff --git a/opal/util/Makefile.am b/opal/util/Makefile.am index 2c62bb50351..3a835bc8fcb 100644 --- a/opal/util/Makefile.am +++ b/opal/util/Makefile.am @@ -63,6 +63,7 @@ headers = \ if.h \ keyval_parse.h \ malloc.h \ + misc.h \ net.h \ numtostr.h \ opal_environ.h \ diff --git a/opal/util/bipartite_graph.c b/opal/util/bipartite_graph.c index a3b1bd4d33b..0ec510619ca 100644 --- a/opal/util/bipartite_graph.c +++ b/opal/util/bipartite_graph.c @@ -18,16 +18,13 @@ #include "opal/class/opal_pointer_array.h" #include "opal/constants.h" #include "opal/util/error.h" +#include "opal/util/misc.h" #include "opal/util/output.h" #include "opal_stdint.h" #include "opal/util/bipartite_graph.h" #include "opal/util/bipartite_graph_internal.h" -#ifndef container_of -# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member))) -#endif - #define GRAPH_DEBUG 0 #if GRAPH_DEBUG # define GRAPH_DEBUG_OUT(args) printf(args) diff --git a/opal/util/misc.h b/opal/util/misc.h new file mode 100644 index 00000000000..7f0d5b3137a --- /dev/null +++ b/opal/util/misc.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Amazon.com, Inc. or its affiliates. + * All Rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +/** @file: + * Miscellaneous utilities + */ + +#ifndef OPAL_UTIL_MISC_H +#define OPAL_UTIL_MISC_H + +#include "opal/include/opal_config.h" + +BEGIN_C_DECLS + +#ifndef container_of +# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member))) +#endif + +END_C_DECLS +#endif