Module Name: src Committed By: knakahara Date: Wed Mar 23 07:05:28 UTC 2016
Modified Files: src/sys/net: if.c Log Message: add drop count which means the sum of struct if_percpuq's per-CPU queues. ok by ozaki-r@n.o To generate a diff of this commit: cvs rdiff -u -r1.326 -r1.327 src/sys/net/if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.326 src/sys/net/if.c:1.327 --- src/sys/net/if.c:1.326 Mon Mar 7 01:41:55 2016 +++ src/sys/net/if.c Wed Mar 23 07:05:28 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.326 2016/03/07 01:41:55 ozaki-r Exp $ */ +/* $NetBSD: if.c,v 1.327 2016/03/23 07:05:28 knakahara Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.326 2016/03/07 01:41:55 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.327 2016/03/23 07:05:28 knakahara Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -210,6 +210,11 @@ struct if_percpuq { static struct mbuf *if_percpuq_dequeue(struct if_percpuq *); +static void if_percpuq_drops(void *, void *, struct cpu_info *); +static int sysctl_percpuq_drops_handler(SYSCTLFN_PROTO); +static void sysctl_percpuq_setup(struct sysctllog **, const char *, + struct if_percpuq *); + #if defined(INET) || defined(INET6) static void sysctl_net_pktq_setup(struct sysctllog **, int); #endif @@ -718,6 +723,8 @@ if_percpuq_create(struct ifnet *ifp) ipq->ipq_ifqs = percpu_alloc(sizeof(struct ifqueue)); percpu_foreach(ipq->ipq_ifqs, &if_percpuq_init_ifq, NULL); + sysctl_percpuq_setup(&ifp->if_sysctl_log, ifp->if_xname, ipq); + return ipq; } @@ -782,6 +789,100 @@ out: splx(s); } +static void +if_percpuq_drops(void *p, void *arg, struct cpu_info *ci __unused) +{ + struct ifqueue *const ifq = p; + int *sum = arg; + + *sum += ifq->ifq_drops; +} + +static int +sysctl_percpuq_drops_handler(SYSCTLFN_ARGS) +{ + struct sysctlnode node; + struct if_percpuq *ipq; + int sum = 0; + int error; + + node = *rnode; + ipq = node.sysctl_data; + + percpu_foreach(ipq->ipq_ifqs, if_percpuq_drops, &sum); + + node.sysctl_data = ∑ + error = sysctl_lookup(SYSCTLFN_CALL(&node)); + if (error != 0 || newp == NULL) + return error; + + return 0; +} + +static void +sysctl_percpuq_setup(struct sysctllog **clog, const char* ifname, + struct if_percpuq *ipq) +{ + const struct sysctlnode *cnode, *rnode; + + if (sysctl_createv(clog, 0, NULL, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "interfaces", + SYSCTL_DESCR("Per-interface controls"), + NULL, 0, NULL, 0, + CTL_NET, CTL_CREATE, CTL_EOL) != 0) + goto bad; + + if (sysctl_createv(clog, 0, &rnode, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, ifname, + SYSCTL_DESCR("Interface controls"), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL) != 0) + goto bad; + + if (sysctl_createv(clog, 0, &rnode, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "rcvq", + SYSCTL_DESCR("Interface input queue controls"), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL) != 0) + goto bad; + +#ifdef NOTYET + /* XXX Should show each per-CPU queue length? */ + if (sysctl_createv(clog, 0, &rnode, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "len", + SYSCTL_DESCR("Current input queue length"), + sysctl_percpuq_len, 0, NULL, 0, + CTL_CREATE, CTL_EOL) != 0) + goto bad; + + if (sysctl_createv(clog, 0, &rnode, &cnode, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "maxlen", + SYSCTL_DESCR("Maximum allowed input queue length"), + sysctl_percpuq_maxlen_handler, 0, (void *)ipq, 0, + CTL_CREATE, CTL_EOL) != 0) + goto bad; +#endif + + if (sysctl_createv(clog, 0, &rnode, &cnode, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "drops", + SYSCTL_DESCR("Total packets dropped due to full input queue"), + sysctl_percpuq_drops_handler, 0, (void *)ipq, 0, + CTL_CREATE, CTL_EOL) != 0) + goto bad; + + return; +bad: + printf("%s: could not attach sysctl nodes\n", ifname); + return; +} + + /* * The common interface input routine that is called by device drivers, * which should be used only when the driver's rx handler already runs