Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Add refcnt constraint checks for debugging



details:   https://anonhg.NetBSD.org/src/rev/15ade1303e54
branches:  trunk
changeset: 340391:15ade1303e54
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Sep 03 02:04:31 2015 +0000

description:
Add refcnt constraint checks for debugging

It's useful to know where the constraint is violated (by extra rtfree).
It's enabled only if DEBUG because it's heavy (O(n)).

diffstat:

 sys/net/route.c |  28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diffs (56 lines):

diff -r 2e5a8133c0b6 -r 15ade1303e54 sys/net/route.c
--- a/sys/net/route.c   Thu Sep 03 01:40:06 2015 +0000
+++ b/sys/net/route.c   Thu Sep 03 02:04:31 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $      */
+/*     $NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -410,6 +410,26 @@
        return newrt;
 }
 
+#ifdef DEBUG
+/*
+ * Check the following constraint for each rtcache:
+ *   if a rtcache holds a rtentry, the rtentry's refcnt is more than zero,
+ *   i.e., the rtentry should be referenced at least by the rtcache.
+ */
+static void
+rtcache_check_rtrefcnt(int family)
+{
+       struct domain *dom = pffinddomain(family);
+       struct route *ro;
+
+       if (dom == NULL)
+               return;
+
+       LIST_FOREACH(ro, &dom->dom_rtcache, ro_rtcache_next)
+               KDASSERT(ro->_ro_rt == NULL || ro->_ro_rt->rt_refcnt > 0);
+}
+#endif
+
 void
 rtfree(struct rtentry *rt)
 {
@@ -419,6 +439,10 @@
        KASSERT(rt->rt_refcnt > 0);
 
        rt->rt_refcnt--;
+#ifdef DEBUG
+       if (rt_getkey(rt) != NULL)
+               rtcache_check_rtrefcnt(rt_getkey(rt)->sa_family);
+#endif
        if (rt->rt_refcnt == 0 && (rt->rt_flags & RTF_UP) == 0) {
                rt_assert_inactive(rt);
                rttrash--;



Home | Main Index | Thread Index | Old Index