From patchwork Thu Oct 29 22:51:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Khapyorsky X-Patchwork-Id: 56543 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9TMlZ9E025469 for ; Thu, 29 Oct 2009 22:49:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755959AbZJ2Wtv (ORCPT ); Thu, 29 Oct 2009 18:49:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756768AbZJ2Wtv (ORCPT ); Thu, 29 Oct 2009 18:49:51 -0400 Received: from ey-out-2122.google.com ([74.125.78.26]:15394 "EHLO ey-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755959AbZJ2Wtv (ORCPT ); Thu, 29 Oct 2009 18:49:51 -0400 Received: by ey-out-2122.google.com with SMTP id 9so552598eyd.19 for ; Thu, 29 Oct 2009 15:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:date:from:to :cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=abJY8YU0wb2qmWkLfTG8N3RyfEcsbYY5oq6tbMlWj3w=; b=tbkqplJAY81vTGkdI8WkPDSpdj/YxUwkrh0F5+A71zH2XOkLyrGZPT2Ff2Tm1KYhJE XE63amCxaucK6H/4iY5GGODsswNurruj36RbCzxGWoSosgDnuw1CIDidZmgWozwqx4XK GtHBhsUeN9EGKc8FBO6pL7EsgT744PI4vM544= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=Uz8+RcZHIq61PxuNVRLt4pT7tGzQglRwJz6wPhuyQEVhyvGEzQtb9tgVJHDK4hh3RN JTgu4kr6gdKx6pWPJ+9kttrI45HRzv1H3DYqd3aeQ2AJKjR3pNca6me3VlGGaFxF+I+x XNnA4fSGup7oHQ8fi+xLLePaE3W8GJg/PEx/k= Received: by 10.211.154.10 with SMTP id g10mr29408ebo.49.1256856594828; Thu, 29 Oct 2009 15:49:54 -0700 (PDT) Received: from me.localdomain (85.64.35.106.dynamic.barak-online.net [85.64.35.106]) by mx.google.com with ESMTPS id 5sm9551322eyf.1.2009.10.29.15.49.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 29 Oct 2009 15:49:54 -0700 (PDT) Received: by me.localdomain (Postfix, from userid 1000) id D87D411E89; Fri, 30 Oct 2009 00:51:59 +0200 (IST) Date: Fri, 30 Oct 2009 00:51:59 +0200 From: Sasha Khapyorsky To: linux-rdma@vger.kernel.org Cc: Hal Rosenstock Subject: [PATCH] infiniband-diags/perfquery: merge some code Message-ID: <20091029225159.GM20136@me> References: <20090923130017.GB7307@comcast.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090923130017.GB7307@comcast.net> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/infiniband-diags/src/perfquery.c b/infiniband-diags/src/perfquery.c index 74f9235..42fffe6 100644 --- a/infiniband-diags/src/perfquery.c +++ b/infiniband-diags/src/perfquery.c @@ -346,81 +346,48 @@ static void reset_counters(int extended, int timeout, int mask, static int reset, reset_only, all_ports, loop_ports, port, extended, xmt_sl, rcv_sl, xmt_disc; -void xmt_sl_query(ib_portid_t * portid, int port, int mask) +static void common_func(ib_portid_t *portid, int port_num, int mask, + unsigned query, unsigned reset, + const char *name, uint16_t attr, + void dump_func(char *, int, void *, int)) { char buf[1024]; - if (reset_only) { - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_XMIT_DATA_SL, srcport)) - IBERROR("perfslreset"); - return; - } + if (query) { + if (!pma_query_via(pc, portid, port_num, ibd_timeout, attr, + srcport)) + IBERROR("cannot query %s", name); - if (!pma_query_via(pc, portid, port, ibd_timeout, - IB_GSI_PORT_XMIT_DATA_SL, srcport)) - IBERROR("perfslquery"); + dump_func(buf, sizeof(buf), pc, sizeof(pc)); - mad_dump_perfcounters_xmt_sl(buf, sizeof buf, pc, sizeof pc); - printf("# PortXmitDataSL counters: %s port %d\n%s", portid2str(portid), - port, buf); + printf("# %s counters: %s port %d\n%s", name, + portid2str(portid), port_num, buf); + } - if (reset) - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_XMIT_DATA_SL, srcport)) - IBERROR("perfslreset"); + if (reset && !performance_reset_via(pc, portid, port, mask, ibd_timeout, + attr, srcport)) + IBERROR("cannot reset %s", name); } -void rcv_sl_query(ib_portid_t * portid, int port, int mask) +static void xmt_sl_query(ib_portid_t * portid, int port, int mask) { - char buf[1024]; - - if (reset_only) { - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_RCV_DATA_SL, srcport)) - IBERROR("perfslreset"); - return; - } - - if (!pma_query_via(pc, portid, port, ibd_timeout, - IB_GSI_PORT_RCV_DATA_SL, srcport)) - IBERROR("perfslquery"); - - mad_dump_perfcounters_rcv_sl(buf, sizeof buf, pc, sizeof pc); - printf("# PortRcvDataSL counters: %s port %d\n%s", portid2str(portid), - port, buf); - - if (reset) - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_RCV_DATA_SL, srcport)) - IBERROR("perfslreset"); + common_func(portid, port, mask, !reset_only, (reset_only || reset), + "PortXmitDataSL", IB_GSI_PORT_XMIT_DATA_SL, + mad_dump_perfcounters_xmt_sl); } -void xmt_disc_query(ib_portid_t * portid, int port, int mask) +static void rcv_sl_query(ib_portid_t * portid, int port, int mask) { - char buf[1024]; - - if (reset_only) { - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_XMIT_DISCARD_DETAILS, - srcport)) - IBERROR("xmtdiscreset"); - return; - } - - if (!pma_query_via(pc, portid, port, ibd_timeout, - IB_GSI_PORT_XMIT_DISCARD_DETAILS, srcport)) - IBERROR("xmtdiscquery"); - - mad_dump_perfcounters_xmt_disc(buf, sizeof buf, pc, sizeof pc); - printf("# PortXmitDiscardDetails: %s port %d\n%s", portid2str(portid), - port, buf); + common_func(portid, port, mask, !reset_only, (reset_only || reset), + "PortRcvDataSL", IB_GSI_PORT_RCV_DATA_SL, + mad_dump_perfcounters_rcv_sl); +} - if (reset) - if (!performance_reset_via(pc, portid, port, mask, ibd_timeout, - IB_GSI_PORT_XMIT_DISCARD_DETAILS, - srcport)) - IBERROR("xmtdiscreset"); +static void xmt_disc_query(ib_portid_t * portid, int port, int mask) +{ + common_func(portid, port, mask, !reset_only, (reset_only || reset), + "PortXmitDiscardDetails", IB_GSI_PORT_XMIT_DISCARD_DETAILS, + mad_dump_perfcounters_xmt_disc); } static int process_opt(void *context, int ch, char *optarg)