From 2d6b12b4999603aa0dff03a24758f30ff6427aa4 Mon Sep 17 00:00:00 2001 From: adrian Date: Fri, 28 Aug 2015 05:58:16 +0000 Subject: [PATCH] Replace the printf()s with optional rate limited debugging for RSS. Submitted by: Tiwei Bie Differential Revision: https://reviews.freebsd.org/D3471 --- sys/net/rss_config.c | 22 +++++++++++++++------- sys/net/rss_config.h | 15 +++++++++++++++ sys/netinet/in_rss.c | 14 +++++++------- sys/netinet6/in6_rss.c | 2 +- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/sys/net/rss_config.c b/sys/net/rss_config.c index 55f4952fbec2..a0ca69f24fd9 100644 --- a/sys/net/rss_config.c +++ b/sys/net/rss_config.c @@ -151,6 +151,15 @@ static const u_int rss_basecpu; SYSCTL_INT(_net_inet_rss, OID_AUTO, basecpu, CTLFLAG_RD, __DECONST(int *, &rss_basecpu), 0, "RSS base CPU"); +/* + * Print verbose debugging messages. + * 0 - disable + * non-zero - enable + */ +int rss_debug = 0; +SYSCTL_INT(_net_inet_rss, OID_AUTO, debug, CTLFLAG_RWTUN, &rss_debug, 0, + "RSS debug level"); + /* * RSS secret key, intended to prevent attacks on load-balancing. Its * effectiveness may be limited by algorithm choice and available entropy @@ -194,8 +203,8 @@ rss_init(__unused void *arg) break; default: - printf("%s: invalid RSS hashalgo %u, coercing to %u", - __func__, rss_hashalgo, RSS_HASH_TOEPLITZ); + RSS_DEBUG("invalid RSS hashalgo %u, coercing to %u\n", + rss_hashalgo, RSS_HASH_TOEPLITZ); rss_hashalgo = RSS_HASH_TOEPLITZ; } @@ -229,8 +238,8 @@ rss_init(__unused void *arg) * ones. */ if (rss_bits == 0 || rss_bits > RSS_MAXBITS) { - printf("%s: RSS bits %u not valid, coercing to %u", - __func__, rss_bits, RSS_MAXBITS); + RSS_DEBUG("RSS bits %u not valid, coercing to %u\n", + rss_bits, RSS_MAXBITS); rss_bits = RSS_MAXBITS; } @@ -241,9 +250,8 @@ rss_init(__unused void *arg) */ rss_buckets = (1 << rss_bits); if (rss_buckets < rss_ncpus) - printf("%s: WARNING: rss_buckets (%u) less than " - "rss_ncpus (%u)\n", __func__, rss_buckets, - rss_ncpus); + RSS_DEBUG("WARNING: rss_buckets (%u) less than " + "rss_ncpus (%u)\n", rss_buckets, rss_ncpus); rss_mask = rss_buckets - 1; } else { rss_bits = 0; diff --git a/sys/net/rss_config.h b/sys/net/rss_config.h index 37d82ae15426..2ab32a43f58b 100644 --- a/sys/net/rss_config.h +++ b/sys/net/rss_config.h @@ -92,6 +92,21 @@ #define RSS_HASH_PKT_INGRESS 0 #define RSS_HASH_PKT_EGRESS 1 +/* + * Rate limited debugging routines. + */ +#define RSS_DEBUG(format, ...) do { \ + if (rss_debug) { \ + static struct timeval lastfail; \ + static int curfail; \ + if (ppsratecheck(&lastfail, &curfail, 5)) \ + printf("RSS (%s:%u): " format, __func__, __LINE__,\ + ##__VA_ARGS__); \ + } \ +} while (0) + +extern int rss_debug; + /* * Device driver interfaces to query RSS properties that must be programmed * into hardware. diff --git a/sys/netinet/in_rss.c b/sys/netinet/in_rss.c index 264b6d7c2c83..40c5f3b976e3 100644 --- a/sys/netinet/in_rss.c +++ b/sys/netinet/in_rss.c @@ -147,7 +147,7 @@ rss_proto_software_hash_v4(struct in_addr s, struct in_addr d, } /* No configured available hashtypes! */ - printf("%s: no available hashtypes!\n", __func__); + RSS_DEBUG("no available hashtypes!\n"); return (-1); } @@ -183,7 +183,7 @@ rss_mbuf_software_hash_v4(const struct mbuf *m, int dir, uint32_t *hashval, * XXX For now this only handles hashing on incoming mbufs. */ if (dir != RSS_HASH_PKT_INGRESS) { - printf("%s: called on EGRESS packet!\n", __func__); + RSS_DEBUG("called on EGRESS packet!\n"); return (-1); } @@ -192,11 +192,11 @@ rss_mbuf_software_hash_v4(const struct mbuf *m, int dir, uint32_t *hashval, * to have an IPv4 header in it. */ if (m->m_pkthdr.len < (sizeof(struct ip))) { - printf("%s: short mbuf pkthdr\n", __func__); + RSS_DEBUG("short mbuf pkthdr\n"); return (-1); } if (m->m_len < (sizeof(struct ip))) { - printf("%s: short mbuf len\n", __func__); + RSS_DEBUG("short mbuf len\n"); return (-1); } @@ -280,7 +280,7 @@ rss_mbuf_software_hash_v4(const struct mbuf *m, int dir, uint32_t *hashval, (proto == IPPROTO_TCP) && (is_frag == 0)) { if (m->m_len < iphlen + sizeof(struct tcphdr)) { - printf("%s: short TCP frame?\n", __func__); + RSS_DEBUG("short TCP frame?\n"); return (-1); } th = (const struct tcphdr *)((c_caddr_t)ip + iphlen); @@ -295,7 +295,7 @@ rss_mbuf_software_hash_v4(const struct mbuf *m, int dir, uint32_t *hashval, (is_frag == 0)) { uh = (const struct udphdr *)((c_caddr_t)ip + iphlen); if (m->m_len < iphlen + sizeof(struct udphdr)) { - printf("%s: short UDP frame?\n", __func__); + RSS_DEBUG("short UDP frame?\n"); return (-1); } return rss_proto_software_hash_v4(ip->ip_src, ip->ip_dst, @@ -313,7 +313,7 @@ rss_mbuf_software_hash_v4(const struct mbuf *m, int dir, uint32_t *hashval, hashval, hashtype); } else { - printf("%s: no available hashtypes!\n", __func__); + RSS_DEBUG("no available hashtypes!\n"); return (-1); } } diff --git a/sys/netinet6/in6_rss.c b/sys/netinet6/in6_rss.c index f125b361daa3..c284980320a6 100644 --- a/sys/netinet6/in6_rss.c +++ b/sys/netinet6/in6_rss.c @@ -147,6 +147,6 @@ rss_proto_software_hash_v6(const struct in6_addr *s, const struct in6_addr *d, } /* No configured available hashtypes! */ - printf("%s: no available hashtypes!\n", __func__); + RSS_DEBUG("no available hashtypes!\n"); return (-1); }