Skip to contentSkip to conversation

opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw

PATCH Superseded Hal Rosenstock 3 participants 5 messages Oct 14, 2009 2 messages not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index bb9ccda..a2acdbd 100644
@@ -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

#2 lore raw
In reply to a message not in the archive
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

---

opensm/opensm/osm_ucast_updn.c +1 -1
index bb9ccda..a2acdbd 100644
@@ -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

#3 lore raw
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

---

opensm/opensm/osm_ucast_updn.c +2 -1
index bb9ccda..a2acdbd 100644
@@ -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

#5 lore raw
In reply to a message not in the archive
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

#6 lore raw
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() is malloc() + 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 global malloc() -> 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