ipath_stats.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  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 two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * 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 OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/pci.h>
  33. #include "ipath_kernel.h"
  34. struct infinipath_stats ipath_stats;
  35. /**
  36. * ipath_snap_cntr - snapshot a chip counter
  37. * @dd: the infinipath device
  38. * @creg: the counter to snapshot
  39. *
  40. * called from add_timer and user counter read calls, to deal with
  41. * counters that wrap in "human time". The words sent and received, and
  42. * the packets sent and received are all that we worry about. For now,
  43. * at least, we don't worry about error counters, because if they wrap
  44. * that quickly, we probably don't care. We may eventually just make this
  45. * handle all the counters. word counters can wrap in about 20 seconds
  46. * of full bandwidth traffic, packet counters in a few hours.
  47. */
  48. u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)
  49. {
  50. u32 val, reg64 = 0;
  51. u64 val64;
  52. unsigned long t0, t1;
  53. u64 ret;
  54. t0 = jiffies;
  55. /* If fast increment counters are only 32 bits, snapshot them,
  56. * and maintain them as 64bit values in the driver */
  57. if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
  58. (creg == dd->ipath_cregs->cr_wordsendcnt ||
  59. creg == dd->ipath_cregs->cr_wordrcvcnt ||
  60. creg == dd->ipath_cregs->cr_pktsendcnt ||
  61. creg == dd->ipath_cregs->cr_pktrcvcnt)) {
  62. val64 = ipath_read_creg(dd, creg);
  63. val = val64 == ~0ULL ? ~0U : 0;
  64. reg64 = 1;
  65. } else /* val64 just to keep gcc quiet... */
  66. val64 = val = ipath_read_creg32(dd, creg);
  67. /*
  68. * See if a second has passed. This is just a way to detect things
  69. * that are quite broken. Normally this should take just a few
  70. * cycles (the check is for long enough that we don't care if we get
  71. * pre-empted.) An Opteron HT O read timeout is 4 seconds with
  72. * normal NB values
  73. */
  74. t1 = jiffies;
  75. if (time_before(t0 + HZ, t1) && val == -1) {
  76. ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
  77. creg);
  78. ret = 0ULL;
  79. goto bail;
  80. }
  81. if (reg64) {
  82. ret = val64;
  83. goto bail;
  84. }
  85. if (creg == dd->ipath_cregs->cr_wordsendcnt) {
  86. if (val != dd->ipath_lastsword) {
  87. dd->ipath_sword += val - dd->ipath_lastsword;
  88. dd->ipath_lastsword = val;
  89. }
  90. val64 = dd->ipath_sword;
  91. } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
  92. if (val != dd->ipath_lastrword) {
  93. dd->ipath_rword += val - dd->ipath_lastrword;
  94. dd->ipath_lastrword = val;
  95. }
  96. val64 = dd->ipath_rword;
  97. } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
  98. if (val != dd->ipath_lastspkts) {
  99. dd->ipath_spkts += val - dd->ipath_lastspkts;
  100. dd->ipath_lastspkts = val;
  101. }
  102. val64 = dd->ipath_spkts;
  103. } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
  104. if (val != dd->ipath_lastrpkts) {
  105. dd->ipath_rpkts += val - dd->ipath_lastrpkts;
  106. dd->ipath_lastrpkts = val;
  107. }
  108. val64 = dd->ipath_rpkts;
  109. } else
  110. val64 = (u64) val;
  111. ret = val64;
  112. bail:
  113. return ret;
  114. }
  115. /**
  116. * ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports
  117. * @dd: the infinipath device
  118. *
  119. * print the delta of egrfull/hdrqfull errors for kernel ports no more than
  120. * every 5 seconds. User processes are printed at close, but kernel doesn't
  121. * close, so... Separate routine so may call from other places someday, and
  122. * so function name when printed by _IPATH_INFO is meaningfull
  123. */
  124. static void ipath_qcheck(struct ipath_devdata *dd)
  125. {
  126. static u64 last_tot_hdrqfull;
  127. size_t blen = 0;
  128. char buf[128];
  129. *buf = 0;
  130. if (dd->ipath_pd[0]->port_hdrqfull != dd->ipath_p0_hdrqfull) {
  131. blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
  132. dd->ipath_pd[0]->port_hdrqfull -
  133. dd->ipath_p0_hdrqfull);
  134. dd->ipath_p0_hdrqfull = dd->ipath_pd[0]->port_hdrqfull;
  135. }
  136. if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {
  137. blen += snprintf(buf + blen, sizeof buf - blen,
  138. "%srcvegrfull %llu",
  139. blen ? ", " : "",
  140. (unsigned long long)
  141. (ipath_stats.sps_etidfull -
  142. dd->ipath_last_tidfull));
  143. dd->ipath_last_tidfull = ipath_stats.sps_etidfull;
  144. }
  145. /*
  146. * this is actually the number of hdrq full interrupts, not actual
  147. * events, but at the moment that's mostly what I'm interested in.
  148. * Actual count, etc. is in the counters, if needed. For production
  149. * users this won't ordinarily be printed.
  150. */
  151. if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
  152. ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
  153. blen += snprintf(buf + blen, sizeof buf - blen,
  154. "%shdrqfull %llu (all ports)",
  155. blen ? ", " : "",
  156. (unsigned long long)
  157. (ipath_stats.sps_hdrqfull -
  158. last_tot_hdrqfull));
  159. last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
  160. }
  161. if (blen)
  162. ipath_dbg("%s\n", buf);
  163. if (dd->ipath_port0head != (u32)
  164. le64_to_cpu(*dd->ipath_hdrqtailptr)) {
  165. if (dd->ipath_lastport0rcv_cnt ==
  166. ipath_stats.sps_port0pkts) {
  167. ipath_cdbg(PKT, "missing rcv interrupts? "
  168. "port0 hd=%llx tl=%x; port0pkts %llx\n",
  169. (unsigned long long)
  170. le64_to_cpu(*dd->ipath_hdrqtailptr),
  171. dd->ipath_port0head,
  172. (unsigned long long)
  173. ipath_stats.sps_port0pkts);
  174. ipath_kreceive(dd);
  175. }
  176. dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
  177. }
  178. }
  179. /**
  180. * ipath_get_faststats - get word counters from chip before they overflow
  181. * @opaque - contains a pointer to the infinipath device ipath_devdata
  182. *
  183. * called from add_timer
  184. */
  185. void ipath_get_faststats(unsigned long opaque)
  186. {
  187. struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
  188. u32 val;
  189. static unsigned cnt;
  190. /*
  191. * don't access the chip while running diags, or memory diags can
  192. * fail
  193. */
  194. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT) ||
  195. ipath_diag_inuse)
  196. /* but re-arm the timer, for diags case; won't hurt other */
  197. goto done;
  198. if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
  199. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  200. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  201. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  202. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  203. }
  204. ipath_qcheck(dd);
  205. /*
  206. * deal with repeat error suppression. Doesn't really matter if
  207. * last error was almost a full interval ago, or just a few usecs
  208. * ago; still won't get more than 2 per interval. We may want
  209. * longer intervals for this eventually, could do with mod, counter
  210. * or separate timer. Also see code in ipath_handle_errors() and
  211. * ipath_handle_hwerrors().
  212. */
  213. if (dd->ipath_lasterror)
  214. dd->ipath_lasterror = 0;
  215. if (dd->ipath_lasthwerror)
  216. dd->ipath_lasthwerror = 0;
  217. if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs)
  218. && time_after(jiffies, dd->ipath_unmasktime)) {
  219. char ebuf[256];
  220. ipath_decode_err(ebuf, sizeof ebuf,
  221. (dd->ipath_maskederrs & ~dd->
  222. ipath_ignorederrs));
  223. if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
  224. ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
  225. ipath_dev_err(dd, "Re-enabling masked errors "
  226. "(%s)\n", ebuf);
  227. else {
  228. /*
  229. * rcvegrfull and rcvhdrqfull are "normal", for some
  230. * types of processes (mostly benchmarks) that send
  231. * huge numbers of messages, while not processing
  232. * them. So only complain about these at debug
  233. * level.
  234. */
  235. ipath_dbg("Disabling frequent queue full errors "
  236. "(%s)\n", ebuf);
  237. }
  238. dd->ipath_maskederrs = dd->ipath_ignorederrs;
  239. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  240. ~dd->ipath_maskederrs);
  241. }
  242. /* limit qfull messages to ~one per minute per port */
  243. if ((++cnt & 0x10)) {
  244. for (val = dd->ipath_cfgports - 1; ((int)val) >= 0;
  245. val--) {
  246. if (dd->ipath_lastegrheads[val] != -1)
  247. dd->ipath_lastegrheads[val] = -1;
  248. if (dd->ipath_lastrcvhdrqtails[val] != -1)
  249. dd->ipath_lastrcvhdrqtails[val] = -1;
  250. }
  251. }
  252. if (dd->ipath_nosma_bufs) {
  253. dd->ipath_nosma_secs += 5;
  254. if (dd->ipath_nosma_secs >= 30) {
  255. ipath_cdbg(SMA, "No SMA bufs avail %u seconds; "
  256. "cancelling pending sends\n",
  257. dd->ipath_nosma_secs);
  258. /*
  259. * issue an abort as well, in case we have a packet
  260. * stuck in launch fifo. This could corrupt an
  261. * outgoing user packet in the worst case,
  262. * but this is a pretty catastrophic, anyway.
  263. */
  264. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  265. INFINIPATH_S_ABORT);
  266. ipath_disarm_piobufs(dd, dd->ipath_lastport_piobuf,
  267. dd->ipath_piobcnt2k +
  268. dd->ipath_piobcnt4k -
  269. dd->ipath_lastport_piobuf);
  270. /* start again, if necessary */
  271. dd->ipath_nosma_secs = 0;
  272. } else
  273. ipath_cdbg(SMA, "No SMA bufs avail %u tries, "
  274. "after %u seconds\n",
  275. dd->ipath_nosma_bufs,
  276. dd->ipath_nosma_secs);
  277. }
  278. done:
  279. mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
  280. }