From: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Having so many globals with such commonly used names creates a lot of -WShadow warnings, move them into a struct to avoid shadowing function locals. Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx> --- src/perfquery.c | 310 ++++++++++++++++++++++++++---------------------- 1 file changed, 166 insertions(+), 144 deletions(-) diff --git a/src/perfquery.c b/src/perfquery.c index 2450fba2699316..c7536dcc52ef00 100644 --- a/src/perfquery.c +++ b/src/perfquery.c @@ -453,12 +453,16 @@ 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, rcv_err, extended_speeds, smpl_ctl, oprcvcounters, flowctlcounters, - vloppackets, vlopdata, vlxmitflowctlerrors, vlxmitcounters, swportvlcong, - rcvcc, slrcvfecn, slrcvbecn, xmitcc, vlxmittimecc; -static int ports[MAX_PORTS]; -static int ports_count; +static struct +{ + int reset, reset_only, all_ports, loop_ports, port, extended, xmt_sl, + rcv_sl, xmt_disc, rcv_err, extended_speeds, smpl_ctl, + oprcvcounters, flowctlcounters, vloppackets, vlopdata, + vlxmitflowctlerrors, vlxmitcounters, swportvlcong, rcvcc, + slrcvfecn, slrcvbecn, xmitcc, vlxmittimecc; + int ports[MAX_PORTS]; + int ports_count; +} info; static void common_func(ib_portid_t * portid, int port_num, int mask, unsigned query, unsigned reset, @@ -480,36 +484,38 @@ static void common_func(ib_portid_t * portid, int port_num, int mask, } memset(pc, 0, sizeof(pc)); - if (reset && !performance_reset_via(pc, portid, port, mask, ibd_timeout, - attr, srcport)) + if (reset && !performance_reset_via(pc, portid, info.port, mask, + ibd_timeout, attr, srcport)) IBEXIT("cannot reset %s", name); } static void xmt_sl_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortXmitDataSL", IB_GSI_PORT_XMIT_DATA_SL, - mad_dump_perfcounters_xmt_sl); + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortXmitDataSL", + IB_GSI_PORT_XMIT_DATA_SL, mad_dump_perfcounters_xmt_sl); } static void rcv_sl_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortRcvDataSL", IB_GSI_PORT_RCV_DATA_SL, - mad_dump_perfcounters_rcv_sl); + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortRcvDataSL", + IB_GSI_PORT_RCV_DATA_SL, mad_dump_perfcounters_rcv_sl); } 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, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortXmitDiscardDetails", + IB_GSI_PORT_XMIT_DISCARD_DETAILS, mad_dump_perfcounters_xmt_disc); } static void rcv_err_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortRcvErrorDetails", IB_GSI_PORT_RCV_ERROR_DETAILS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortRcvErrorDetails", + IB_GSI_PORT_RCV_ERROR_DETAILS, mad_dump_perfcounters_rcv_err); } @@ -583,7 +589,7 @@ static void extended_speeds_query(ib_portid_t * portid, int port, { int mask = ext_mask; - if (!reset_only) { + if (!info.reset_only) { if (is_rsfec_mode_active(portid, port, cap_mask)) common_func(portid, port, mask, 1, 0, "PortExtendedSpeedsCounters with RS-FEC Active", @@ -596,92 +602,103 @@ static void extended_speeds_query(ib_portid_t * portid, int port, mad_dump_port_ext_speeds_counters); } - if ((reset_only || reset) && + if ((info.reset_only || info.reset) && !ext_speeds_reset_via(pc, portid, port, ext_mask, ibd_timeout)) IBEXIT("cannot reset PortExtendedSpeedsCounters"); } static void oprcvcounters_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortOpRcvCounters", IB_GSI_PORT_PORT_OP_RCV_COUNTERS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortOpRcvCounters", + IB_GSI_PORT_PORT_OP_RCV_COUNTERS, mad_dump_perfcounters_port_op_rcv_counters); } static void flowctlcounters_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortFlowCtlCounters", IB_GSI_PORT_PORT_FLOW_CTL_COUNTERS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortFlowCtlCounters", + IB_GSI_PORT_PORT_FLOW_CTL_COUNTERS, mad_dump_perfcounters_port_flow_ctl_counters); } static void vloppackets_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortVLOpPackets", IB_GSI_PORT_PORT_VL_OP_PACKETS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortVLOpPackets", + IB_GSI_PORT_PORT_VL_OP_PACKETS, mad_dump_perfcounters_port_vl_op_packet); } static void vlopdata_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortVLOpData", IB_GSI_PORT_PORT_VL_OP_DATA, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortVLOpData", + IB_GSI_PORT_PORT_VL_OP_DATA, mad_dump_perfcounters_port_vl_op_data); } static void vlxmitflowctlerrors_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortVLXmitFlowCtlUpdateErrors", IB_GSI_PORT_PORT_VL_XMIT_FLOW_CTL_UPDATE_ERRORS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), + "PortVLXmitFlowCtlUpdateErrors", + IB_GSI_PORT_PORT_VL_XMIT_FLOW_CTL_UPDATE_ERRORS, mad_dump_perfcounters_port_vl_xmit_flow_ctl_update_errors); } static void vlxmitcounters_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortVLXmitWaitCounters", IB_GSI_PORT_PORT_VL_XMIT_WAIT_COUNTERS, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortVLXmitWaitCounters", + IB_GSI_PORT_PORT_VL_XMIT_WAIT_COUNTERS, mad_dump_perfcounters_port_vl_xmit_wait_counters); } static void swportvlcong_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "SwPortVLCongestion", IB_GSI_SW_PORT_VL_CONGESTION, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "SwPortVLCongestion", + IB_GSI_SW_PORT_VL_CONGESTION, mad_dump_perfcounters_sw_port_vl_congestion); } static void rcvcc_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortRcvConCtrl", IB_GSI_PORT_RCV_CON_CTRL, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortRcvConCtrl", + IB_GSI_PORT_RCV_CON_CTRL, mad_dump_perfcounters_rcv_con_ctrl); } static void slrcvfecn_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortSLRcvFECN", IB_GSI_PORT_SL_RCV_FECN, - mad_dump_perfcounters_sl_rcv_fecn); + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortSLRcvFECN", + IB_GSI_PORT_SL_RCV_FECN, mad_dump_perfcounters_sl_rcv_fecn); } static void slrcvbecn_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortSLRcvBECN", IB_GSI_PORT_SL_RCV_BECN, - mad_dump_perfcounters_sl_rcv_becn); + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortSLRcvBECN", + IB_GSI_PORT_SL_RCV_BECN, mad_dump_perfcounters_sl_rcv_becn); } static void xmitcc_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortXmitConCtrl", IB_GSI_PORT_XMIT_CON_CTRL, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortXmitConCtrl", + IB_GSI_PORT_XMIT_CON_CTRL, mad_dump_perfcounters_xmit_con_ctrl); } static void vlxmittimecc_query(ib_portid_t * portid, int port, int mask) { - common_func(portid, port, mask, !reset_only, (reset_only || reset), - "PortVLXmitTimeCong", IB_GSI_PORT_VL_XMIT_TIME_CONG, + common_func(portid, port, mask, !info.reset_only, + (info.reset_only || info.reset), "PortVLXmitTimeCong", + IB_GSI_PORT_VL_XMIT_TIME_CONG, mad_dump_perfcounters_vl_xmit_time_cong); } @@ -703,74 +720,74 @@ static int process_opt(void *context, int ch, char *optarg) { switch (ch) { case 'x': - extended = 1; + info.extended = 1; break; case 'X': - xmt_sl = 1; + info.xmt_sl = 1; break; case 'S': - rcv_sl = 1; + info.rcv_sl = 1; break; case 'D': - xmt_disc = 1; + info.xmt_disc = 1; break; case 'E': - rcv_err = 1; + info.rcv_err = 1; break; case 'T': - extended_speeds = 1; + info.extended_speeds = 1; break; case 'c': - smpl_ctl = 1; + info.smpl_ctl = 1; break; case 1: - oprcvcounters = 1; + info.oprcvcounters = 1; break; case 2: - flowctlcounters = 1; + info.flowctlcounters = 1; break; case 3: - vloppackets = 1; + info.vloppackets = 1; break; case 4: - vlopdata = 1; + info.vlopdata = 1; break; case 5: - vlxmitflowctlerrors = 1; + info.vlxmitflowctlerrors = 1; break; case 6: - vlxmitcounters = 1; + info.vlxmitcounters = 1; break; case 7: - swportvlcong = 1; + info.swportvlcong = 1; break; case 8: - rcvcc = 1; + info.rcvcc = 1; break; case 9: - slrcvfecn = 1; + info.slrcvfecn = 1; break; case 10: - slrcvbecn = 1; + info.slrcvbecn = 1; break; case 11: - xmitcc = 1; + info.xmitcc = 1; break; case 12: - vlxmittimecc = 1; + info.vlxmittimecc = 1; break; case 'a': - all_ports++; - port = ALL_PORTS; + info.all_ports++; + info.port = ALL_PORTS; break; case 'l': - loop_ports++; + info.loop_ports++; break; case 'r': - reset++; + info.reset++; break; case 'R': - reset_only++; + info.reset_only++; break; default: return -1; @@ -850,10 +867,11 @@ int main(int argc, char **argv) if (strchr(argv[1], ',')) { tmpstr = strtok(argv[1], ","); while (tmpstr) { - ports[ports_count++] = strtoul(tmpstr, 0, 0); + info.ports[info.ports_count++] = + strtoul(tmpstr, 0, 0); tmpstr = strtok(NULL, ","); } - port = ports[0]; + info.port = info.ports[0]; } else if ((tmpstr = strchr(argv[1], '-'))) { int pmin, pmax; @@ -868,12 +886,12 @@ int main(int argc, char **argv) IBEXIT("max port must be greater than min port in range"); while (pmin <= pmax) - ports[ports_count++] = pmin++; + info.ports[info.ports_count++] = pmin++; - port = ports[0]; + info.port = info.ports[0]; } else - port = strtoul(argv[1], 0, 0); + info.port = strtoul(argv[1], 0, 0); } if (argc > 2) { ext_mask = strtoull(argv[2], 0, 0); @@ -891,13 +909,14 @@ int main(int argc, char **argv) ibd_dest_type, ibd_sm_id, srcport) < 0) IBEXIT("can't resolve destination port %s", argv[0]); } else { - if (resolve_self(ibd_ca, ibd_ca_port, &portid, &port, 0) < 0) + if (resolve_self(ibd_ca, ibd_ca_port, &portid, &info.port, 0) < + 0) IBEXIT("can't resolve self port %s", argv[0]); } /* PerfMgt ClassPortInfo is a required attribute */ memset(pc, 0, sizeof(pc)); - if (!pma_query_via(pc, &portid, port, ibd_timeout, CLASS_PORT_INFO, + if (!pma_query_via(pc, &portid, info.port, ibd_timeout, CLASS_PORT_INFO, srcport)) IBEXIT("classportinfo query"); /* ClassPortInfo should be supported as part of libibmad */ @@ -906,104 +925,104 @@ int main(int argc, char **argv) cap_mask2 = ntohl(cap_mask2) >> 5; if (!(cap_mask & IB_PM_ALL_PORT_SELECT)) { /* bit 8 is AllPortSelect */ - if (!all_ports && port == ALL_PORTS) + if (!info.all_ports && info.port == ALL_PORTS) IBEXIT("AllPortSelect not supported"); - if (all_ports && port == ALL_PORTS) + if (info.all_ports && info.port == ALL_PORTS) all_ports_loop = 1; } - if (xmt_sl) { - xmt_sl_query(&portid, port, mask); + if (info.xmt_sl) { + xmt_sl_query(&portid, info.port, mask); goto done; } - if (rcv_sl) { - rcv_sl_query(&portid, port, mask); + if (info.rcv_sl) { + rcv_sl_query(&portid, info.port, mask); goto done; } - if (xmt_disc) { - xmt_disc_query(&portid, port, mask); + if (info.xmt_disc) { + xmt_disc_query(&portid, info.port, mask); goto done; } - if (rcv_err) { - rcv_err_query(&portid, port, mask); + if (info.rcv_err) { + rcv_err_query(&portid, info.port, mask); goto done; } - if (extended_speeds) { - extended_speeds_query(&portid, port, ext_mask, cap_mask); + if (info.extended_speeds) { + extended_speeds_query(&portid, info.port, ext_mask, cap_mask); goto done; } - if (oprcvcounters) { - oprcvcounters_query(&portid, port, mask); + if (info.oprcvcounters) { + oprcvcounters_query(&portid, info.port, mask); goto done; } - if (flowctlcounters) { - flowctlcounters_query(&portid, port, mask); + if (info.flowctlcounters) { + flowctlcounters_query(&portid, info.port, mask); goto done; } - if (vloppackets) { - vloppackets_query(&portid, port, mask); + if (info.vloppackets) { + vloppackets_query(&portid, info.port, mask); goto done; } - if (vlopdata) { - vlopdata_query(&portid, port, mask); + if (info.vlopdata) { + vlopdata_query(&portid, info.port, mask); goto done; } - if (vlxmitflowctlerrors) { - vlxmitflowctlerrors_query(&portid, port, mask); + if (info.vlxmitflowctlerrors) { + vlxmitflowctlerrors_query(&portid, info.port, mask); goto done; } - if (vlxmitcounters) { - vlxmitcounters_query(&portid, port, mask); + if (info.vlxmitcounters) { + vlxmitcounters_query(&portid, info.port, mask); goto done; } - if (swportvlcong) { - swportvlcong_query(&portid, port, mask); + if (info.swportvlcong) { + swportvlcong_query(&portid, info.port, mask); goto done; } - if (rcvcc) { - rcvcc_query(&portid, port, mask); + if (info.rcvcc) { + rcvcc_query(&portid, info.port, mask); goto done; } - if (slrcvfecn) { - slrcvfecn_query(&portid, port, mask); + if (info.slrcvfecn) { + slrcvfecn_query(&portid, info.port, mask); goto done; } - if (slrcvbecn) { - slrcvbecn_query(&portid, port, mask); + if (info.slrcvbecn) { + slrcvbecn_query(&portid, info.port, mask); goto done; } - if (xmitcc) { - xmitcc_query(&portid, port, mask); + if (info.xmitcc) { + xmitcc_query(&portid, info.port, mask); goto done; } - if (vlxmittimecc) { - vlxmittimecc_query(&portid, port, mask); + if (info.vlxmittimecc) { + vlxmittimecc_query(&portid, info.port, mask); goto done; } - if (smpl_ctl) { - dump_portsamples_control(&portid, port); + if (info.smpl_ctl) { + dump_portsamples_control(&portid, info.port); goto done; } - - if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { + if (all_ports_loop || + (info.loop_ports && (info.all_ports || info.port == ALL_PORTS))) { if (!smp_query_via(data, &portid, IB_ATTR_NODE_INFO, 0, 0, srcport)) IBEXIT("smp query nodeinfo failed"); @@ -1021,35 +1040,35 @@ int main(int argc, char **argv) if (enhancedport0) start_port = 0; } - if (all_ports_loop && !loop_ports) + if (all_ports_loop && !info.loop_ports) IBWARN ("Emulating AllPortSelect by iterating through all ports"); } - if (reset_only) + if (info.reset_only) goto do_reset; - if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { + if (all_ports_loop || + (info.loop_ports && (info.all_ports || info.port == ALL_PORTS))) { for (i = start_port; i <= num_ports; i++) - dump_perfcounters(extended, ibd_timeout, - cap_mask, cap_mask2, - &portid, i, (all_ports_loop - && !loop_ports)); - if (all_ports_loop && !loop_ports) { - if (extended != 1) + dump_perfcounters(info.extended, ibd_timeout, cap_mask, + cap_mask2, &portid, i, + (all_ports_loop && !info.loop_ports)); + if (all_ports_loop && !info.loop_ports) { + if (info.extended != 1) output_aggregate_perfcounters(&portid, cap_mask); else output_aggregate_perfcounters_ext(&portid, cap_mask, cap_mask2); } - } else if (ports_count > 1) { - for (i = 0; i < ports_count; i++) - dump_perfcounters(extended, ibd_timeout, cap_mask, - cap_mask2, &portid, ports[i], - (all_ports && !loop_ports)); - if (all_ports && !loop_ports) { - if (extended != 1) + } else if (info.ports_count > 1) { + for (i = 0; i < info.ports_count; i++) + dump_perfcounters(info.extended, ibd_timeout, cap_mask, + cap_mask2, &portid, info.ports[i], + (info.all_ports && !info.loop_ports)); + if (info.all_ports && !info.loop_ports) { + if (info.extended != 1) output_aggregate_perfcounters(&portid, cap_mask); else @@ -1057,21 +1076,21 @@ int main(int argc, char **argv) cap_mask, cap_mask2); } } else - dump_perfcounters(extended, ibd_timeout, cap_mask, cap_mask2, - &portid, port, 0); + dump_perfcounters(info.extended, ibd_timeout, cap_mask, + cap_mask2, &portid, info.port, 0); - if (!reset) + if (!info.reset) goto done; do_reset: - if (argc <= 2 && !extended) { + if (argc <= 2 && !info.extended) { if (cap_mask & IB_PM_PC_XMIT_WAIT_SUP) mask |= (1 << 16); /* reset portxmitwait */ if (cap_mask & IB_PM_IS_QP1_DROP_SUP) mask |= (1 << 17); /* reset qp1dropped */ } - if (extended) { + if (info.extended) { mask |= 0xfff0000; if (cap_mask & IB_PM_PC_XMIT_WAIT_SUP) mask |= (1 << 28); @@ -1079,14 +1098,17 @@ do_reset: mask |= (1 << 29); } - if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { + if (all_ports_loop || + (info.loop_ports && (info.all_ports || info.port == ALL_PORTS))) { for (i = start_port; i <= num_ports; i++) - reset_counters(extended, ibd_timeout, mask, &portid, i); - } else if (ports_count > 1) { - for (i = 0; i < ports_count; i++) - reset_counters(extended, ibd_timeout, mask, &portid, ports[i]); + reset_counters(info.extended, ibd_timeout, mask, + &portid, i); + } else if (info.ports_count > 1) { + for (i = 0; i < info.ports_count; i++) + reset_counters(info.extended, ibd_timeout, mask, + &portid, info.ports[i]); } else - reset_counters(extended, ibd_timeout, mask, &portid, port); + reset_counters(info.extended, ibd_timeout, mask, &portid, info.port); done: mad_rpc_close_port(srcport); -- 2.21.0