This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Net stack debug patch


This patch adds some code to record and display information about all
the mbufs in the FreeBSD stack.

Currently it is controlled by the CYGDBG_NET_SHOW_MBUFS option.
Whenever the stack runs out of mbufs in eth_drv_recv() it prints out a
list of mbufs showing what they are all doing.

I wrote this code to debug a problem I was having and thought it might
be generally useful.

Opinions? Should it go in?



Index: io/eth/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/eth/current/ChangeLog,v
retrieving revision 1.41
diff -u -5 -r1.41 ChangeLog
--- io/eth/current/ChangeLog	11 Mar 2003 15:41:11 -0000	1.41
+++ io/eth/current/ChangeLog	14 Mar 2003 19:19:26 -0000
@@ -1,5 +1,10 @@
+2003-03-14  Nick Garnett  <nickg at calivar dot com>
+
+	* src/net/eth_drv.c: Added calls to cyg_net_show_mbufs() whenever
+	we see an out-of-mbufs problem.
+
 2003-03-11  Mark Salter  <msalter at redhat dot com>
 
 	* src/stand_alone/eth_drv.c (eth_drv_stop): Uncomment, make non-static,
 	and use __local_enet_sc.
 	* include/eth_drv.h: Add extern decl for eth_drv_stop.
Index: io/eth/current/src/net/eth_drv.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/eth/current/src/net/eth_drv.c,v
retrieving revision 1.26
diff -u -5 -r1.26 eth_drv.c
--- io/eth/current/src/net/eth_drv.c	7 Feb 2003 00:27:08 -0000	1.26
+++ io/eth/current/src/net/eth_drv.c	14 Mar 2003 19:19:29 -0000
@@ -817,10 +817,13 @@
     MGETHDR(m, M_DONTWAIT, MT_DATA);
     if (m == 0) {
 #ifdef CYGPKG_IO_ETH_DRIVERS_WARN_NO_MBUFS
         START_CONSOLE();
         diag_printf("warning: eth_recv out of MBUFs\n");
+#ifdef CYGDBG_NET_SHOW_MBUFS        
+        cyg_net_show_mbufs();
+#endif
         END_CONSOLE();
 #endif
     }
 
     // Set up buffers
@@ -852,10 +855,13 @@
             if (m == 0) {
                 m_freem(top);
 #ifdef CYGPKG_IO_ETH_DRIVERS_WARN_NO_MBUFS
                 START_CONSOLE();
                 diag_printf("out of MBUFs [2]");
+#ifdef CYGDBG_NET_SHOW_MBUFS                
+                cyg_net_show_mbufs();
+#endif
                 END_CONSOLE();
 #endif
                 sg_list[sg_len].buf = (CYG_ADDRESS)0;
                 sg_list[sg_len].len = total_len;
                 sg_len++;
@@ -870,10 +876,13 @@
                 m_freem(top);
                 m_free(m);
 #ifdef CYGPKG_IO_ETH_DRIVERS_WARN_NO_MBUFS
                 START_CONSOLE();
                 diag_printf("warning: eth_recv out of MBUFs\n");
+#ifdef CYGDBG_NET_SHOW_MBUFS                
+                cyg_net_show_mbufs();
+#endif
                 END_CONSOLE();
 #endif
                 sg_list[sg_len].buf = (CYG_ADDRESS)0;
                 sg_list[sg_len].len = total_len;
                 sg_len++;
Index: net/bsd_tcpip/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.18
diff -u -5 -r1.18 ChangeLog
--- net/bsd_tcpip/current/ChangeLog	14 Mar 2003 13:04:05 -0000	1.18
+++ net/bsd_tcpip/current/ChangeLog	14 Mar 2003 19:19:29 -0000
@@ -1,5 +1,9 @@
+2003-03-14  Nick Garnett  <nickg at balti dot calivar dot com>
+
+	* include/sys/mbuf.h: Added prototype for cyg_net_show_mbufs().
+
 2003-03-14  Andrew Lunn  <andrew dot lunn at ascom dot ch>
 
 	* src/sys/net/if.c (if_attach): Removed printf which causes the
 	ethernet device to become corrupt. At this point the app driver
 	has started but not completed taking over from the redboot
Index: net/bsd_tcpip/current/include/sys/mbuf.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/include/sys/mbuf.h,v
retrieving revision 1.1
diff -u -5 -r1.1 mbuf.h
--- net/bsd_tcpip/current/include/sys/mbuf.h	20 May 2002 22:25:01 -0000	1.1
+++ net/bsd_tcpip/current/include/sys/mbuf.h	14 Mar 2003 19:19:34 -0000
@@ -632,8 +632,11 @@
 struct	mbuf *m_aux_find __P((struct mbuf *, int, int));
 void	m_aux_delete __P((struct mbuf *, struct mbuf *));
 extern void *cyg_net_mbuf_alloc(int type, int flags);
 extern void cyg_net_mbuf_free(caddr_t addr, int type);
 extern void *cyg_net_cluster_alloc(void );
+#ifdef CYGDBG_NET_SHOW_MBUFS                
+extern void cyg_net_show_mbufs(void);
+#endif
 #endif /* _KERNEL */
 
 #endif /* !_SYS_MBUF_H_ */
Index: net/bsd_tcpip/current/src/ecos/support.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/src/ecos/support.c,v
retrieving revision 1.4
diff -u -5 -r1.4 support.c
--- net/bsd_tcpip/current/src/ecos/support.c	3 Dec 2002 17:22:46 -0000	1.4
+++ net/bsd_tcpip/current/src/ecos/support.c	14 Mar 2003 19:19:36 -0000
@@ -212,10 +212,49 @@
     START_STATS();
     cyg_mempool_var_free(net_mem, addr);
     FINISH_STATS(stats_free);
 }
 
+#ifdef CYGDBG_NET_SHOW_MBUFS
+
+struct mbuf *mbinfo[300];
+
+void cyg_net_show_mbufs(void)
+{
+    int i;
+    diag_printf(" MBUF   : TYPE FLGS     DATA[LEN]   NEXT    NEXTPKT\n");
+    for( i = 0; i < 300; i++ )
+    {
+        struct mbuf *m = mbinfo[i];
+        char *type;
+        if( m == 0 ) continue;
+
+        switch( m->m_hdr.mh_type )
+        {
+        case MT_FREE: type="FREE"; break;
+        case MT_DATA: type="DATA"; break;
+        case MT_HEADER: type="HEADER"; break;
+        case MT_SONAME: type="SONAME"; break;
+        case MT_FTABLE: type="FTABLE"; break;
+        case MT_CONTROL: type="CONTROL"; break;
+        case MT_OOBDATA: type="OOBDATA"; break;
+        default: type="UNKNOWN"; break;
+        }
+
+        diag_printf("%08x: %s %04x %08x[%03d] %08x %08x\n",
+                    m, type,
+                    m->m_hdr.mh_flags,
+                    m->m_hdr.mh_data,
+                    m->m_hdr.mh_len,
+                    m->m_hdr.mh_next,
+                    m->m_hdr.mh_nextpkt);
+    }
+    diag_printf(" MBUF   : TYPE FLGS     DATA[LEN]   NEXT    NEXTPKT\n");    
+}
+
+#endif
+
 void *
 cyg_net_mbuf_alloc(int type, int flags)
 {
     void *res;    
 
@@ -226,10 +265,21 @@
         res = cyg_mempool_fix_try_alloc(net_mbufs);
     } else {
         res = cyg_mempool_fix_alloc(net_mbufs);
     }
     FINISH_STATS(stats_mbuf_alloc);
+#ifdef CYGDBG_NET_SHOW_MBUFS    
+    {
+        int i;
+        for( i = 0; i < (sizeof(mbinfo)/sizeof(mbinfo[0])); i++ )
+            if( mbinfo[i] == 0 )
+            {
+                mbinfo[i] = (struct mbuf *)res;
+                break;
+            }
+    }
+#endif
     // Check that this nastiness works OK
     CYG_ASSERT( dtom(res) == res, "dtom failed, base of mbuf" );
     CYG_ASSERT( dtom((char *)res + MSIZE/2) == res, "dtom failed, mid mbuf" );
     log(LOG_MDEBUG, "%p\n", res);
     return (res);
Index: net/common/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/common/current/ChangeLog,v
retrieving revision 1.23
diff -u -5 -r1.23 ChangeLog
--- net/common/current/ChangeLog	7 Mar 2003 02:14:52 -0000	1.23
+++ net/common/current/ChangeLog	14 Mar 2003 19:19:37 -0000
@@ -1,5 +1,10 @@
+2003-03-14  Nick Garnett  <nickg at balti dot calivar dot com>
+
+	* cdl/net.cdl: Added CYGDBG_NET_SHOW_MBUFS option to turn on
+	accumulation and display of mbuf state information. 
+
 2003-03-06  Gary Thomas  <gary at mlbassoc dot com>
 
 	* src/getaddrinfo.c: Need to clear any addresses - malloc() can
 	return garbage which the stack desn't like.
 
Index: net/common/current/cdl/net.cdl
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/common/current/cdl/net.cdl,v
retrieving revision 1.3
diff -u -5 -r1.3 net.cdl
--- net/common/current/cdl/net.cdl	24 Feb 2003 14:29:34 -0000	1.3
+++ net/common/current/cdl/net.cdl	14 Mar 2003 19:19:37 -0000
@@ -285,10 +285,20 @@
                 This component controls whether there is diagnostic 
                 information about how long memcpy, malloc, mbuf_alloc
                 etc take to perform."
     }
 
+    cdl_option CYGDBG_NET_SHOW_MBUFS {
+        display       "Network MBUF diagnostics"
+        default_value 0
+        description   "
+                This option controls whether diagnostic 
+                information about the state of all mbufs is collected.
+                This information will be displayed whenever the network
+                stack runs out of mbufs."
+    }
+
     cdl_component CYGPKG_NET_OPTIONS {
         display "Networking support build options"
         flavor  none
         no_define
 
@@ -353,11 +363,10 @@
                     tests/set_mac_address \
                     tests/bridge \
                     tests/flood \
                     tests/ping_test \
                     tests/dhcp_test \
-                    tests/dhcp_test2 \
                     tests/ping_lo_test \
                     tests/tcp_lo_test \
                     tests/udp_lo_test \
                     tests/multi_lo_select \
                     tests/tcp_lo_select"


-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]