Path: blob/master/drivers/infiniband/hw/ipath/ipath_stats.c
15112 views
/*1* Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.2* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#include "ipath_kernel.h"3435struct infinipath_stats ipath_stats;3637/**38* ipath_snap_cntr - snapshot a chip counter39* @dd: the infinipath device40* @creg: the counter to snapshot41*42* called from add_timer and user counter read calls, to deal with43* counters that wrap in "human time". The words sent and received, and44* the packets sent and received are all that we worry about. For now,45* at least, we don't worry about error counters, because if they wrap46* that quickly, we probably don't care. We may eventually just make this47* handle all the counters. word counters can wrap in about 20 seconds48* of full bandwidth traffic, packet counters in a few hours.49*/5051u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)52{53u32 val, reg64 = 0;54u64 val64;55unsigned long t0, t1;56u64 ret;5758t0 = jiffies;59/* If fast increment counters are only 32 bits, snapshot them,60* and maintain them as 64bit values in the driver */61if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&62(creg == dd->ipath_cregs->cr_wordsendcnt ||63creg == dd->ipath_cregs->cr_wordrcvcnt ||64creg == dd->ipath_cregs->cr_pktsendcnt ||65creg == dd->ipath_cregs->cr_pktrcvcnt)) {66val64 = ipath_read_creg(dd, creg);67val = val64 == ~0ULL ? ~0U : 0;68reg64 = 1;69} else /* val64 just to keep gcc quiet... */70val64 = val = ipath_read_creg32(dd, creg);71/*72* See if a second has passed. This is just a way to detect things73* that are quite broken. Normally this should take just a few74* cycles (the check is for long enough that we don't care if we get75* pre-empted.) An Opteron HT O read timeout is 4 seconds with76* normal NB values77*/78t1 = jiffies;79if (time_before(t0 + HZ, t1) && val == -1) {80ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",81creg);82ret = 0ULL;83goto bail;84}85if (reg64) {86ret = val64;87goto bail;88}8990if (creg == dd->ipath_cregs->cr_wordsendcnt) {91if (val != dd->ipath_lastsword) {92dd->ipath_sword += val - dd->ipath_lastsword;93dd->ipath_lastsword = val;94}95val64 = dd->ipath_sword;96} else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {97if (val != dd->ipath_lastrword) {98dd->ipath_rword += val - dd->ipath_lastrword;99dd->ipath_lastrword = val;100}101val64 = dd->ipath_rword;102} else if (creg == dd->ipath_cregs->cr_pktsendcnt) {103if (val != dd->ipath_lastspkts) {104dd->ipath_spkts += val - dd->ipath_lastspkts;105dd->ipath_lastspkts = val;106}107val64 = dd->ipath_spkts;108} else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {109if (val != dd->ipath_lastrpkts) {110dd->ipath_rpkts += val - dd->ipath_lastrpkts;111dd->ipath_lastrpkts = val;112}113val64 = dd->ipath_rpkts;114} else if (creg == dd->ipath_cregs->cr_ibsymbolerrcnt) {115if (dd->ibdeltainprog)116val64 -= val64 - dd->ibsymsnap;117val64 -= dd->ibsymdelta;118} else if (creg == dd->ipath_cregs->cr_iblinkerrrecovcnt) {119if (dd->ibdeltainprog)120val64 -= val64 - dd->iblnkerrsnap;121val64 -= dd->iblnkerrdelta;122} else123val64 = (u64) val;124125ret = val64;126127bail:128return ret;129}130131/**132* ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports133* @dd: the infinipath device134*135* print the delta of egrfull/hdrqfull errors for kernel ports no more than136* every 5 seconds. User processes are printed at close, but kernel doesn't137* close, so... Separate routine so may call from other places someday, and138* so function name when printed by _IPATH_INFO is meaningfull139*/140static void ipath_qcheck(struct ipath_devdata *dd)141{142static u64 last_tot_hdrqfull;143struct ipath_portdata *pd = dd->ipath_pd[0];144size_t blen = 0;145char buf[128];146u32 hdrqtail;147148*buf = 0;149if (pd->port_hdrqfull != dd->ipath_p0_hdrqfull) {150blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",151pd->port_hdrqfull -152dd->ipath_p0_hdrqfull);153dd->ipath_p0_hdrqfull = pd->port_hdrqfull;154}155if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {156blen += snprintf(buf + blen, sizeof buf - blen,157"%srcvegrfull %llu",158blen ? ", " : "",159(unsigned long long)160(ipath_stats.sps_etidfull -161dd->ipath_last_tidfull));162dd->ipath_last_tidfull = ipath_stats.sps_etidfull;163}164165/*166* this is actually the number of hdrq full interrupts, not actual167* events, but at the moment that's mostly what I'm interested in.168* Actual count, etc. is in the counters, if needed. For production169* users this won't ordinarily be printed.170*/171172if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&173ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {174blen += snprintf(buf + blen, sizeof buf - blen,175"%shdrqfull %llu (all ports)",176blen ? ", " : "",177(unsigned long long)178(ipath_stats.sps_hdrqfull -179last_tot_hdrqfull));180last_tot_hdrqfull = ipath_stats.sps_hdrqfull;181}182if (blen)183ipath_dbg("%s\n", buf);184185hdrqtail = ipath_get_hdrqtail(pd);186if (pd->port_head != hdrqtail) {187if (dd->ipath_lastport0rcv_cnt ==188ipath_stats.sps_port0pkts) {189ipath_cdbg(PKT, "missing rcv interrupts? "190"port0 hd=%x tl=%x; port0pkts %llx; write"191" hd (w/intr)\n",192pd->port_head, hdrqtail,193(unsigned long long)194ipath_stats.sps_port0pkts);195ipath_write_ureg(dd, ur_rcvhdrhead, hdrqtail |196dd->ipath_rhdrhead_intr_off, pd->port_port);197}198dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;199}200}201202static void ipath_chk_errormask(struct ipath_devdata *dd)203{204static u32 fixed;205u32 ctrl;206unsigned long errormask;207unsigned long hwerrs;208209if (!dd->ipath_errormask || !(dd->ipath_flags & IPATH_INITTED))210return;211212errormask = ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);213214if (errormask == dd->ipath_errormask)215return;216fixed++;217218hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);219ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);220221ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,222dd->ipath_errormask);223224if ((hwerrs & dd->ipath_hwerrmask) ||225(ctrl & INFINIPATH_C_FREEZEMODE)) {226/* force re-interrupt of pending events, just in case */227ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);228ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, 0ULL);229ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);230dev_info(&dd->pcidev->dev,231"errormask fixed(%u) %lx -> %lx, ctrl %x hwerr %lx\n",232fixed, errormask, (unsigned long)dd->ipath_errormask,233ctrl, hwerrs);234} else235ipath_dbg("errormask fixed(%u) %lx -> %lx, no freeze\n",236fixed, errormask,237(unsigned long)dd->ipath_errormask);238}239240241/**242* ipath_get_faststats - get word counters from chip before they overflow243* @opaque - contains a pointer to the infinipath device ipath_devdata244*245* called from add_timer246*/247void ipath_get_faststats(unsigned long opaque)248{249struct ipath_devdata *dd = (struct ipath_devdata *) opaque;250int i;251static unsigned cnt;252unsigned long flags;253u64 traffic_wds;254255/*256* don't access the chip while running diags, or memory diags can257* fail258*/259if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_INITTED) ||260ipath_diag_inuse)261/* but re-arm the timer, for diags case; won't hurt other */262goto done;263264/*265* We now try to maintain a "active timer", based on traffic266* exceeding a threshold, so we need to check the word-counts267* even if they are 64-bit.268*/269traffic_wds = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt) +270ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);271spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);272traffic_wds -= dd->ipath_traffic_wds;273dd->ipath_traffic_wds += traffic_wds;274if (traffic_wds >= IPATH_TRAFFIC_ACTIVE_THRESHOLD)275atomic_add(5, &dd->ipath_active_time); /* S/B #define */276spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);277278if (dd->ipath_flags & IPATH_32BITCOUNTERS) {279ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);280ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);281}282283ipath_qcheck(dd);284285/*286* deal with repeat error suppression. Doesn't really matter if287* last error was almost a full interval ago, or just a few usecs288* ago; still won't get more than 2 per interval. We may want289* longer intervals for this eventually, could do with mod, counter290* or separate timer. Also see code in ipath_handle_errors() and291* ipath_handle_hwerrors().292*/293294if (dd->ipath_lasterror)295dd->ipath_lasterror = 0;296if (dd->ipath_lasthwerror)297dd->ipath_lasthwerror = 0;298if (dd->ipath_maskederrs299&& time_after(jiffies, dd->ipath_unmasktime)) {300char ebuf[256];301int iserr;302iserr = ipath_decode_err(dd, ebuf, sizeof ebuf,303dd->ipath_maskederrs);304if (dd->ipath_maskederrs &305~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |306INFINIPATH_E_PKTERRS))307ipath_dev_err(dd, "Re-enabling masked errors "308"(%s)\n", ebuf);309else {310/*311* rcvegrfull and rcvhdrqfull are "normal", for some312* types of processes (mostly benchmarks) that send313* huge numbers of messages, while not processing314* them. So only complain about these at debug315* level.316*/317if (iserr)318ipath_dbg(319"Re-enabling queue full errors (%s)\n",320ebuf);321else322ipath_cdbg(ERRPKT, "Re-enabling packet"323" problem interrupt (%s)\n", ebuf);324}325326/* re-enable masked errors */327dd->ipath_errormask |= dd->ipath_maskederrs;328ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,329dd->ipath_errormask);330dd->ipath_maskederrs = 0;331}332333/* limit qfull messages to ~one per minute per port */334if ((++cnt & 0x10)) {335for (i = (int) dd->ipath_cfgports; --i >= 0; ) {336struct ipath_portdata *pd = dd->ipath_pd[i];337338if (pd && pd->port_lastrcvhdrqtail != -1)339pd->port_lastrcvhdrqtail = -1;340}341}342343ipath_chk_errormask(dd);344done:345mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);346}347348349