[PATCH 3/3] opensm/osm_node_info_rcv.c: using if_PF for all the fatal conditions
This is just the first file - similar optimization will be done on other MADs receivers. Note that this patch doesn't mess with all the non-fatal cases. The goal was not to help SM to perform better with all the validations that it does (which, of course, can be addressed in a separate patch), but to make sure that the fatal cases will never be predicted wrong, so any fatal check won't affect the SM performance. Signed-off-by: Yevgeny Kliteynik --- opensm/osm_node_info_rcv.c | 28 ++-- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/opensm/osm_node_info_rcv.c b/opensm/osm_node_info_rcv.c index 58c92b9..10055ef 100644 --- a/opensm/osm_node_info_rcv.c +++ b/opensm/osm_node_info_rcv.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved. - * Copyright (c) 2002-2011 Mellanox Technologies LTD. All rights reserved. + * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. * Copyright (c) 2009 HNR Consulting. All rights reserved. * @@ -152,7 +152,7 @@ static void ni_rcv_set_links(IN osm_sm_t * sm, osm_node_t * p_node, p_neighbor_node = osm_get_node_by_guid(sm->p_subn, p_ni_context->node_guid); - if (!p_neighbor_node) { + if_PF (!p_neighbor_node) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D10: " "Unexpected removal of neighbor node 0x%" PRIx64 "\n", cl_ntoh64(p_ni_context->node_guid)); @@ -415,7 +415,7 @@ static void ni_rcv_process_existing_ca_or_router(IN osm_sm_t * sm, osm_node_init_physp(p_node, port_num, p_madw); p_port = osm_port_new(p_ni, p_node); - if (p_port == NULL) { + if_PF (p_port == NULL) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D04: " "Unable to create new port object\n"); goto Exit; @@ -428,7 +428,7 @@ static void ni_rcv_process_existing_ca_or_router(IN osm_sm_t * sm, (osm_port_t *) cl_qmap_insert(&sm->p_subn->port_guid_tbl, p_ni->port_guid, &p_port->map_item); - if (p_port_check != p_port) { + if_PF (p_port_check != p_port) { /* We should never be here! Somehow, this port GUID already exists in the table. @@ -443,7 +443,7 @@ static void ni_rcv_process_existing_ca_or_router(IN osm_sm_t * sm, p_alias_guid = osm_alias_guid_new(p_ni->port_guid, p_port); - if (!p_alias_guid) { + if_PF (!p_alias_guid) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D11: " "alias guid memory allocation failed" " for port GUID 0x%" PRIx64 "\n", @@ -615,7 +615,7 @@ static void ni_rcv_process_new(IN osm_sm_t * sm, IN const osm_madw_t * p_madw) cl_ntoh64(p_ni->node_guid), cl_ntoh64(p_smp->trans_id)); p_node = osm_node_new(p_madw); - if (p_node == NULL) { + if_PF (p_node == NULL) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D07: " "Unable to create new node object\n"); goto Exit; @@ -626,7 +626,7 @@ static void ni_rcv_process_new(IN osm_sm_t * sm, IN const osm_madw_t * p_madw) ports in the port table. */ p_port = osm_port_new(p_ni, p_node); - if (p_port == NULL) { + if_PF (p_port == NULL) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D14: " "Unable to create new port object\n"); osm_node_delete(&p_node); @@ -639,7 +639,7 @@ static void ni_rcv_process_new(IN osm_sm_t * sm, IN const osm_madw_t * p_madw) p_port_check = (osm_port_t *) cl_qmap_insert(&sm->p_subn->port_guid_tbl, p_ni->port_guid, &p_port->map_item); - if (p_port_check != p_port) { + if_PF (p_port_check != p_port) { /* We should never be here! Somehow, this port GUID already exists in the table. @@ -662,7 +662,7 @@ static void ni_rcv_process_new(IN osm_sm_t * sm, IN const osm_madw_t * p_madw) p_alias_guid = osm_alias_guid_new(p_ni->port_guid, p_port); - if (!p_alias_guid) { + if_PF (!p_alias_guid) { OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D18: " "alias guid memory allocation failed" " for port GUID 0x%" PRIx64 "\n", @@ -697,7 +697,7 @@ alias_done2: /* If there were RouterInfo or other router attrib
[PATCH 2/3] complib: define "if" statements with branch prediction hints
Similar to "likely" and "unlikely" that are used in kernel, defined "if_PT" and "if_PF" for "predict true" and "predict false" respectively. Signed-off-by: Yevgeny Kliteynik --- include/complib/cl_types_osd.h | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/complib/cl_types_osd.h b/include/complib/cl_types_osd.h index ce1a452..f9abb28 100644 --- a/include/complib/cl_types_osd.h +++ b/include/complib/cl_types_osd.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved. - * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. + * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two @@ -64,6 +64,21 @@ BEGIN_C_DECLS #include #include #include + +/* + * Branch prediction hints + */ +#if defined(HAVE_BUILTIN_EXPECT) +#define CL_PREDICT_TRUE(exp) __builtin_expect( ((uintptr_t)(exp)), 1 ) +#define CL_PREDICT_FALSE(exp) __builtin_expect( ((uintptr_t)(exp)), 0 ) +#else +#define CL_PREDICT_TRUE(exp) (exp) +#define CL_PREDICT_FALSE(exp) (exp) +#endif + +#define if_PF(cond)if(CL_PREDICT_FALSE(cond)) +#define if_PT(cond)if(CL_PREDICT_TRUE(cond)) + #if defined (_DEBUG_) #define CL_ASSERT assert #else /* _DEBUG_ */ -- 1.7.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/3] configure.in: check that compiler supports __builtin_expect()
Signed-off-by: Yevgeny Kliteynik --- configure.in | 11 +++ 1 file changed, 11 insertions(+) diff --git a/configure.in b/configure.in index b2d07bc..0a56da6 100644 --- a/configure.in +++ b/configure.in @@ -56,6 +56,17 @@ AC_HEADER_TIME AC_STRUCT_TM AC_C_VOLATILE +dnl See if we have __builtin_expect +AC_MSG_CHECKING([if the compiler supports __builtin_expect]) +AC_TRY_COMPILE(, [ return __builtin_expect(1, 1) ? 1 : 0], +[ have_builtin_expect=yes + AC_MSG_RESULT([yes]) ], +[ have_builtin_expect=no + AC_MSG_RESULT([no]) ]) +if test "x_$have_builtin_expect" = "x_yes" ; then + AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define to 1 if the compiler supports __builtin_expect.]) +fi + dnl We use --version-script with ld if possible AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script, if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then -- 1.7.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/3] configure.in: check that compiler supports __builtin_expect()
Signed-off-by: Yevgeny Kliteynik --- configure.in | 11 +++ 1 file changed, 11 insertions(+) diff --git a/configure.in b/configure.in index b2d07bc..0a56da6 100644 --- a/configure.in +++ b/configure.in @@ -56,6 +56,17 @@ AC_HEADER_TIME AC_STRUCT_TM AC_C_VOLATILE +dnl See if we have __builtin_expect +AC_MSG_CHECKING([if the compiler supports __builtin_expect]) +AC_TRY_COMPILE(, [ return __builtin_expect(1, 1) ? 1 : 0], +[ have_builtin_expect=yes + AC_MSG_RESULT([yes]) ], +[ have_builtin_expect=no + AC_MSG_RESULT([no]) ]) +if test "x_$have_builtin_expect" = "x_yes" ; then + AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], [Define to 1 if the compiler supports __builtin_expect.]) +fi + dnl We use --version-script with ld if possible AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script, if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then -- 1.7.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html