* [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw
@ 2009-10-14 13:14 Hal Rosenstock
[not found] ` <20091014131435.GA23890-Wuw85uim5zDR7s880joybQ@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Hal Rosenstock @ 2009-10-14 13:14 UTC (permalink / raw)
To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Also, combine malloc/memset into calloc
Signed-off-by: Hal Rosenstock <hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
diff --git a/opensm/opensm/osm_ucast_updn.c b/opensm/opensm/osm_ucast_updn.c
index bb9ccda..a2acdbd 100644
--- a/opensm/opensm/osm_ucast_updn.c
+++ b/opensm/opensm/osm_ucast_updn.c
@@ -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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <20091014131435.GA23890-Wuw85uim5zDR7s880joybQ@public.gmane.org>]
* Re: [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw [not found] ` <20091014131435.GA23890-Wuw85uim5zDR7s880joybQ@public.gmane.org> @ 2009-10-14 13:29 ` Sasha Khapyorsky 2009-10-14 13:33 ` Hal Rosenstock 0 siblings, 1 reply; 5+ messages in thread From: Sasha Khapyorsky @ 2009-10-14 13:29 UTC (permalink / raw) To: Hal Rosenstock; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On 09:14 Wed 14 Oct , Hal Rosenstock wrote: > > Also, combine malloc/memset into calloc Any special reason for malloc/calloc change? Please don't mix two things in one patch. Sasha > > Signed-off-by: Hal Rosenstock <hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- > diff --git a/opensm/opensm/osm_ucast_updn.c b/opensm/opensm/osm_ucast_updn.c > index bb9ccda..a2acdbd 100644 > --- a/opensm/opensm/osm_ucast_updn.c > +++ b/opensm/opensm/osm_ucast_updn.c > @@ -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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw 2009-10-14 13:29 ` Sasha Khapyorsky @ 2009-10-14 13:33 ` Hal Rosenstock [not found] ` <f0e08f230910140633i43bd7648w1feba7c2be6c0d11-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Hal Rosenstock @ 2009-10-14 13:33 UTC (permalink / raw) To: Sasha Khapyorsky; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On Wed, Oct 14, 2009 at 9:29 AM, Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org> wrote: > On 09:14 Wed 14 Oct , Hal Rosenstock wrote: >> >> 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 ? > Please don't mix two things in one patch. I thought this was minor. I'll resubmit if you prefer. -- Hal > Sasha > >> >> Signed-off-by: Hal Rosenstock <hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> --- >> diff --git a/opensm/opensm/osm_ucast_updn.c b/opensm/opensm/osm_ucast_updn.c >> index bb9ccda..a2acdbd 100644 >> --- a/opensm/opensm/osm_ucast_updn.c >> +++ b/opensm/opensm/osm_ucast_updn.c >> @@ -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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <f0e08f230910140633i43bd7648w1feba7c2be6c0d11-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw [not found] ` <f0e08f230910140633i43bd7648w1feba7c2be6c0d11-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-10-14 14:34 ` Sasha Khapyorsky 2009-10-14 14:36 ` Hal Rosenstock 0 siblings, 1 reply; 5+ messages in thread From: Sasha Khapyorsky @ 2009-10-14 14:34 UTC (permalink / raw) To: Hal Rosenstock; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On 09:33 Wed 14 Oct , Hal Rosenstock wrote: > On Wed, Oct 14, 2009 at 9:29 AM, Sasha Khapyorsky <sashak-smomgflXvObQFizaE/u3fw@public.gmane.orgm> wrote: > > On 09:14 Wed 14 Oct , Hal Rosenstock wrote: > >> > >> 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. > 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw 2009-10-14 14:34 ` Sasha Khapyorsky @ 2009-10-14 14:36 ` Hal Rosenstock 0 siblings, 0 replies; 5+ messages in thread From: Hal Rosenstock @ 2009-10-14 14:36 UTC (permalink / raw) To: Sasha Khapyorsky; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA On Wed, Oct 14, 2009 at 10:34 AM, Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org> wrote: > On 09:33 Wed 14 Oct , Hal Rosenstock wrote: >> On Wed, Oct 14, 2009 at 9:29 AM, Sasha Khapyorsky <sashak@voltaire.com> wrote: >> > On 09:14 Wed 14 Oct , Hal Rosenstock wrote: >> >> >> >> 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. > >> 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 > Sasha > -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-10-14 14:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-14 13:14 [PATCH] opensm/osm_ucast_updn.c: Reduce temporary allocation of cas_per_sw Hal Rosenstock
[not found] ` <20091014131435.GA23890-Wuw85uim5zDR7s880joybQ@public.gmane.org>
2009-10-14 13:29 ` Sasha Khapyorsky
2009-10-14 13:33 ` Hal Rosenstock
[not found] ` <f0e08f230910140633i43bd7648w1feba7c2be6c0d11-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-14 14:34 ` Sasha Khapyorsky
2009-10-14 14:36 ` Hal Rosenstock
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox