opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw
PATCH 1/1 opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw
Also, combine malloc/memset into calloc
---
opensm/opensm/osm_ucast_updn.c +2 -2
@@ -2,6 +2,7 @@* Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. +* Copyright (c) 2009 HNR Consulting. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU
@@ -431,13 +432,12 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)"Current number of ports in the subnet is %d\n" , cl_qmap_count(&p_osm->subn.port_guid_tbl)); - cas_per_sw =malloc ((IB_LID_UCAST_END_HO +1 ) *sizeof (*cas_per_sw)); + cas_per_sw =calloc (p_osm->subn.max_ucast_lid_ho,sizeof (*cas_per_sw));if (!cas_per_sw) {OSM_LOG (&p_osm->log,OSM_LOG_ERROR ,"ERR AA14: " "cannot alloc mem for CAs per switch counter array\n" ); goto _exit; } -memset (cas_per_sw,0 , (IB_LID_UCAST_END_HO +1 ) *sizeof (*cas_per_sw));/* Find the Maximum number of CAs (and routers) for histogram normalization */ OSM_LOG(&p_osm->log, OSM_LOG_VERBOSE,
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Hal Rosenstock
Also, combine malloc/memset into calloc
Any special reason for malloc/calloc change?
Please don't mix two things in one patch.
Sasha
Quoted 21 lines
Signed-off-by Hal Rosenstock <[email protected]>---
opensm/opensm/osm_ucast_updn.c +1
-1@@ -2,6 +2,7 @@* Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. +* Copyright (c) 2009 HNR Consulting. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -431,13 +432,12 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)"Current number of ports in the subnet is %d\n" , cl_qmap_count(&p_osm->subn.port_guid_tbl)); - cas_per_sw =malloc ((IB_LID_UCAST_END_HO +1 ) *sizeof (*cas_per_sw));
opensm/opensm/osm_ucast_updn.c static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn) · line 443
Quoted 10 lines
opensm/opensm/osm_ucast_updn.c +1
-1+ cas_per_sw =calloc (p_osm->subn.max_ucast_lid_ho,sizeof (*cas_per_sw));if (!cas_per_sw) {OSM_LOG (&p_osm->log,OSM_LOG_ERROR ,"ERR AA14: " "cannot alloc mem for CAs per switch counter array\n" ); goto _exit; } -memset (cas_per_sw,0 , (IB_LID_UCAST_END_HO +1 ) *sizeof (*cas_per_sw));/* Find the Maximum number of CAs (and routers) for histogram normalization */ OSM_LOG(&p_osm->log, OSM_LOG_VERBOSE,
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Sasha Khapyorsky
Quoted 2 lines · Hal Rosenstock
Also, combine malloc/memset into calloc
Any special reason for malloc/calloc change?
It's a little more concise and efficient to calloc rather than malloc/memset. Any reason not to do this ?
Quoted 1 line
Please don't mix two things in one patch.
I thought this was minor. I'll resubmit if you prefer.
-- Hal
Quoted 30 lines
Sasha
Quoted 28 lines
Signed-off-by Hal Rosenstock <[email protected]>---
opensm/opensm/osm_ucast_updn.c +2
-1@@ -2,6 +2,7 @@ * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved. * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. + * Copyright (c) 2009 HNR Consulting. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU@@ -431,13 +432,12 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn) "Current number of ports in the subnet is %d\n", cl_qmap_count(&p_osm->subn.port_guid_tbl)); - cas_per_sw = malloc((IB_LID_UCAST_END_HO + 1) * sizeof(*cas_per_sw)); + cas_per_sw = calloc(p_osm->subn.max_ucast_lid_ho, sizeof(*cas_per_sw)); if (!cas_per_sw) {
OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR AA14: " "cannot alloc mem for CAs per switch counter array\n"); goto_exit;
}
-memset(cas_per_sw, 0, (IB_LID_UCAST_END_HO + 1) * sizeof(*cas_per_sw));
Quoted 8 lines
Quoted 3 lines
/* Find the Maximum number of CAs (and routers) for histogram normalization */ OSM_LOG(&p_osm->log,
OSM_LOG_VERBOSE,--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): f0e08f230910140633i43bd7648w1feba7c2be6c0d11-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 9 lines · Hal Rosenstock
Quoted 5 lines · Sasha Khapyorsky
Quoted 2 lines · Hal Rosenstock
Also, combine malloc/memset into calloc
Any special reason for malloc/calloc change?
It's a little more concise and efficient to calloc rather than malloc/memset.
Why do you think so? Normally calloc() is malloc() + memset() - you just get extra call and extra check.
Quoted 1 line
Any reason not to do this ?
Above.
calloc() can be nicer in some cases and pretty common, feel free to use it when appropriate. But I don't think that we need to make a global malloc() -> calloc() conversion without any good reason.
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 14 lines · Sasha Khapyorsky
Quoted 9 lines · Hal Rosenstock
Quoted 5 lines · Sasha Khapyorsky
Quoted 2 lines · Hal Rosenstock
Also, combine malloc/memset into calloc
Any special reason for malloc/calloc change?
It's a little more concise and efficient to calloc rather than malloc/memset.
Why do you think so? Normally
calloc()ismalloc()+memset()- you just get extra call and extra check.
Quoted 7 lines
Quoted 1 line
Any reason not to do this ?
Above.
calloc()can be nicer in some cases and pretty common, feel free to use it when appropriate. But I don't think that we need to make a globalmalloc()->calloc()conversion without any good reason.
The generated code is slightly smaller.
What do you consider appropriate/good reason ?
-- Hal
Quoted 2 lines
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html