From patchwork Fri Jan 22 02:14:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 74443 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0M2ICP7010712 for ; Fri, 22 Jan 2010 02:18:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751433Ab0AVCSL (ORCPT ); Thu, 21 Jan 2010 21:18:11 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752374Ab0AVCSL (ORCPT ); Thu, 21 Jan 2010 21:18:11 -0500 Received: from nspiron-1.llnl.gov ([128.115.41.81]:46010 "EHLO nspiron-1.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751433Ab0AVCSJ (ORCPT ); Thu, 21 Jan 2010 21:18:09 -0500 X-Attachments: None Received: from mail-2.llnl.gov ([128.115.41.181]) by nspiron-1.llnl.gov with ESMTP; 21 Jan 2010 18:18:08 -0800 Received: from jeepcj7.llnl.gov (jeepcj7.llnl.gov [134.9.93.67]) by mail-2.llnl.gov (8.13.1/8.12.3/LLNL evision: 1.7 $) with SMTP id o0M2HpTv003382; Thu, 21 Jan 2010 18:17:51 -0800 Date: Thu, 21 Jan 2010 18:14:18 -0800 From: Ira Weiny To: Sasha Khapyorsky Cc: "linux-rdma@vger.kernel.org" Subject: Found one reason libibnetdisc is slower than subnet_discover Message-Id: <20100121181418.a9e955bb.weiny2@llnl.gov> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.10.4; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc.c b/infiniband-diags/libibnetdisc/src/ibnetdisc.c index d0c97a1..fa0dbe4 100644 --- a/infiniband-diags/libibnetdisc/src/ibnetdisc.c +++ b/infiniband-diags/libibnetdisc/src/ibnetdisc.c @@ -101,19 +101,30 @@ static int query_node_info(struct ibmad_port *ibmad_port, return 0; } +static ibnd_node_t *find_existing_node(ibnd_fabric_t * fabric, + uint64_t guid) +{ + int hash = HASHGUID(guid) % HTSZ; + ibnd_node_t *node; + + for (node = fabric->nodestbl[hash]; node; node = node->htnext) + if (node->guid == guid) + return node; + + return NULL; +} + static int query_node(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric, ibnd_node_t * node, ibnd_port_t * port, ib_portid_t * portid) { int rc = 0; void *nd = node->nodedesc; + ibnd_node_t *existing; if ((rc = query_node_info(ibmad_port, fabric, node, portid)) != 0) return rc; - if (!smp_query_via(nd, portid, IB_ATTR_NODE_DESC, 0, 0, ibmad_port)) - return -1; - if ((rc = query_port_info(ibmad_port, portid, 0, port)) != 0) return rc; @@ -121,7 +132,7 @@ static int query_node(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric, port->guid = mad_get_field64(node->info, 0, IB_NODE_PORT_GUID_F); if (node->type != IB_NODE_SWITCH) - return 0; + goto query_nd; node->smalid = port->base_lid; node->smalmc = port->lmc; @@ -135,6 +146,12 @@ static int query_node(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric, port->base_lid = (uint16_t) node->smalid; /* LID is still defined by port 0 */ port->lmc = (uint8_t) node->smalmc; + if ((existing = find_existing_node(fabric, node->guid)) != NULL) { + /* probably don't even need this memcpy */ + memcpy(node, existing, sizeof *node); + return (0); + } + if (!smp_query_via(node->switchinfo, portid, IB_ATTR_SWITCH_INFO, 0, 0, ibmad_port)) node->smaenhsp0 = 0; /* assume base SP0 */ @@ -144,6 +161,11 @@ static int query_node(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric, IBND_DEBUG("portid %s: got switch node %" PRIx64 " '%s'\n", portid2str(portid), node->guid, node->nodedesc); + +query_nd: + if (!smp_query_via(nd, portid, IB_ATTR_NODE_DESC, 0, 0, ibmad_port)) + return -1; + return 0; } @@ -208,19 +230,6 @@ static void dump_endnode(ib_portid_t * path, char *prompt, port->base_lid + (1 << port->lmc) - 1, node->nodedesc); } -static ibnd_node_t *find_existing_node(ibnd_fabric_t * fabric, - ibnd_node_t * new) -{ - int hash = HASHGUID(new->guid) % HTSZ; - ibnd_node_t *node; - - for (node = fabric->nodestbl[hash]; node; node = node->htnext) - if (node->guid == new->guid) - return node; - - return NULL; -} - ibnd_node_t *ibnd_find_node_guid(ibnd_fabric_t * fabric, uint64_t guid) { int hash = HASHGUID(guid) % HTSZ; @@ -459,7 +468,7 @@ static int get_remote_node(struct ibmad_port *ibmad_port, return 1; /* positive == non-fatal error */ } - oldnode = find_existing_node(fabric, &node_buf); + oldnode = find_existing_node(fabric, node_buf.guid); if (oldnode) remotenode = oldnode; else if (!(remotenode = create_node(fabric, scan, &node_buf, path,