--- sys.orig/net/if_ethersubr.c Sun Jul 10 14:26:37 2005 +++ sys/net/if_ethersubr.c Sun Jul 10 18:58:45 2005 @@ -82,6 +82,19 @@ #include #include #endif + +/* Kernel Instrumentation */ +#ifndef TIMING +#define TIMING +#endif + +#ifdef TIMING +#include +struct mbuf* inst_curpkt = NULL; /* Packet to be traced */ +quad_t inst_start = 0; /* Start trace time */ +int inst_reset = 0; /* Used to reset the trace */ +#endif + int (*ef_inputp)(struct ifnet*, struct ether_header *eh, struct mbuf *m); int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp, struct sockaddr *dst, short *tp, int *hlen); @@ -495,6 +508,13 @@ struct ether_header *eh; u_short etype; +/* Debugging - Remove later */ +#ifdef TIMING + log(LOG_INFO, "ether_input: start = %d, ticks = %d\n", + inst_reset, ticks); + log(LOG_INFO, "tracing packet : %c\n", inst_curpkt==NULL?'n':'y'); +#endif + /* * Do consistency checks to verify assumptions * made by code past this point. @@ -546,6 +566,44 @@ * consumers can get to it. */ mac_create_mbuf_from_ifnet(ifp, m); +#endif + +#ifdef TIMING + /* Packet Timing Instrumentation + * Log trace packet + */ + static u_quad_t prev_time = 0; + if (prev_time == 0) { + prev_time = rdtsc(); + } else { + u_long diff = rdtsc() - prev_time; + log(LOG_INFO, "Diff=%lu, pktlen=%lu\n", + diff, + (u_long) m->m_pkthdr.len); + prev_time = rdtsc(); + } + +#if 0 + if (inst_curpkt != NULL && ticks - inst_reset > 4) { + log(LOG_INFO, "mbuf %x: Timing RESET\n", (u_int) m); + inst_curpkt = NULL; + inst_start = 0; + } + + if (inst_curpkt == NULL && ntohs(eh->ether_type) == ETHERTYPE_IP) { + /* Start the timing for all IP packets at this point, + * however, we are only interested in UDP packets and + * therefore we have to reset inst_curpkt to NULL if + * it isn't a UDP packet. But, this task will be accomplished + * at the specific higher level + */ + log(LOG_INFO, "mbuf %x: Start trace - sys = %d, tsc_freq = %ui \n", (u_int) m, ticks, (u_int) tsc_freq); + inst_curpkt = m; + inst_start = rdtsc(); + inst_reset = ticks; + } +#endif + #endif /* --- sys.orig/netinet/ip_input.c Sun Jul 10 14:26:38 2005 +++ sys/netinet/ip_input.c Sun Jul 10 19:07:33 2005 @@ -87,6 +87,15 @@ #include #endif +/* Kernel Instrumentation */ +#ifndef TIMING +#define TIMING +#endif + +#ifdef TIMING +#include +#endif + int rsvp_on = 0; int ipforwarding = 0; @@ -325,6 +334,16 @@ int s, error; #endif /* FAST_IPSEC */ +#if 0 +#ifdef TIMING + if (inst_curpkt != NULL) { + log(LOG_INFO, "mbuf %x: ip_input after %u ticks\n", + (u_int) m, + (u_int) (rdtsc() - inst_start)); + } +#endif +#endif + M_ASSERTPKTHDR(m); if (m->m_flags & M_FASTFWD_OURS) { @@ -772,10 +791,24 @@ * Switch out to protocol's input routine. */ ipstat.ips_delivered++; +#if 0 +#ifdef TIMING + if (ip->ip_p == IPPROTO_TCP) { + log(LOG_INFO, "mbuf %x: Not a UDP packet - stop timing\n", (u_int) m); + inst_curpkt = NULL; + inst_start = 0; + } +#endif +#endif (*inetsw[ip_protox[ip->ip_p]].pr_input)(m, hlen); return; bad: +#ifdef TIMING + inst_curpkt = NULL; + inst_start = 0; +#endif + m_freem(m); } --- sys.orig/netinet/udp_usrreq.c Sun Jul 10 14:26:38 2005 +++ sys/netinet/udp_usrreq.c Sun Jul 10 19:08:14 2005 @@ -84,6 +84,15 @@ #include +/* Kernel Instrumentation */ +#ifndef TIMING +#define TIMING +#endif + +#ifdef TIMING +#include +#endif + /* * UDP protocol implementation. * Per RFC 768, August, 1980. @@ -156,6 +165,18 @@ struct sockaddr_in udp_in; udpstat.udps_ipackets++; + +#if 0 +#ifdef TIMING + if (inst_curpkt != NULL) { + log(LOG_INFO, "mbuf %x: udp_input %x\n", + (u_int) m, + (u_int) (rdtsc() - inst_start)); + inst_curpkt = NULL; + inst_start = 0; + } +#endif +#endif /* * Strip IP options, if any; should skip this, --- sys.orig/sys/timing.h Mon Jul 11 19:37:18 2005 +++ sys/sys/timing.h Sun Jul 10 17:33:10 2005 @@ -0,0 +1,16 @@ +#ifndef _SYS_TIMING_H_ +#define _SYS_TIMING_H_ + +#define TIMING + +#ifdef TIMING +#include +#include /* For rdtsc() and tsc_freq */ +#include +#include +#include +extern struct mbuf* inst_curpkt; /* Packet to be traced */ +extern quad_t inst_start; /* Start trace time */ +#endif /* TIMING */ + +#endif /* !_SYS_TIMING_H_ */