From 21fa606276a74e6b8930331d4855eb4228ad348b Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Wed, 2 Apr 2008 13:11:48 +0000 Subject: [PATCH] - Add two fields in lwkt_serialize to profile serializer contention. - Expose serializer contention data through em's private sysctl tree. --- sys/conf/options | 5 ++++- sys/config/LINT | 5 ++++- sys/dev/netif/em/Makefile | 8 ++++++-- sys/dev/netif/em/if_em.c | 14 +++++++++++++- sys/kern/lwkt_serialize.c | 20 ++++++++++++++++++-- sys/sys/serialize.h | 4 +++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/sys/conf/options b/sys/conf/options index 8f65847924..b3ce45253d 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/options,v 1.191.2.53 2003/06/04 17:56:58 sam Exp $ -# $DragonFly: src/sys/conf/options,v 1.78 2008/02/19 21:24:36 thomas Exp $ +# $DragonFly: src/sys/conf/options,v 1.79 2008/04/02 13:11:48 sephe Exp $ # # On the handling of kernel options # @@ -558,3 +558,6 @@ SCTP_MAP_LOGGING opt_sctp.h # syslink kernel support # SYSLINK opt_syslink.h + +# serializer profiling support +PROFILE_SERIALIZER opt_serializer.h diff --git a/sys/config/LINT b/sys/config/LINT index f6e3576ac2..2dd6ecb64a 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/config/LINT,v 1.152 2008/03/22 09:45:44 sephe Exp $ +# $DragonFly: src/sys/config/LINT,v 1.153 2008/04/02 13:11:48 sephe Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -2765,3 +2765,6 @@ options SCTP_BLK_LOGGING options SCTP_STR_LOGGING options SCTP_FR_LOGGING options SCTP_MAP_LOGGING + +# Serializer profiling +options PROFILE_SERIALIZER diff --git a/sys/dev/netif/em/Makefile b/sys/dev/netif/em/Makefile index 5f3f35344c..3382cd325e 100644 --- a/sys/dev/netif/em/Makefile +++ b/sys/dev/netif/em/Makefile @@ -1,9 +1,10 @@ #$FreeBSD: src/sys/modules/em/Makefile,v 1.1.2.3 2002/06/18 21:00:56 pdeuskar Exp $ -#$DragonFly: src/sys/dev/netif/em/Makefile,v 1.7 2006/12/23 10:39:16 sephe Exp $ +#$DragonFly: src/sys/dev/netif/em/Makefile,v 1.8 2008/04/02 13:11:48 sephe Exp $ KMOD= if_em SRCS= if_em.c if_em_hw.c -SRCS+= device_if.h bus_if.h pci_if.h opt_polling.h opt_inet.h opt_ktr.h +SRCS+= device_if.h bus_if.h pci_if.h +SRCS+= opt_polling.h opt_inet.h opt_ktr.h opt_serializer.h .ifndef BUILDING_WITH_KERNEL opt_polling.h: @@ -11,6 +12,9 @@ opt_polling.h: opt_inet.h: echo "#define INET 1" > ${.OBJDIR}/${.TARGET} + +opt_serializer.h: + touch ${.OBJDIR}/${.TARGET} .endif .include diff --git a/sys/dev/netif/em/if_em.c b/sys/dev/netif/em/if_em.c index 559fea3444..e5fc7f67f8 100644 --- a/sys/dev/netif/em/if_em.c +++ b/sys/dev/netif/em/if_em.c @@ -64,7 +64,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/dev/netif/em/if_em.c,v 1.66 2008/04/02 11:48:30 sephe Exp $ + * $DragonFly: src/sys/dev/netif/em/if_em.c,v 1.67 2008/04/02 13:11:48 sephe Exp $ * $FreeBSD$ */ /* @@ -95,6 +95,7 @@ #include "opt_polling.h" #include "opt_inet.h" +#include "opt_serializer.h" #include #include @@ -2157,6 +2158,17 @@ em_setup_interface(device_t dev, struct adapter *adapter) ether_ifattach(ifp, adapter->hw.mac_addr, NULL); +#ifdef PROFILE_SERIALIZER + SYSCTL_ADD_UINT(&adapter->sysctl_ctx, + SYSCTL_CHILDREN(adapter->sysctl_tree), OID_AUTO, + "serializer_sleep", CTLFLAG_RW, + &ifp->if_serializer->sleep_cnt, 0, NULL); + SYSCTL_ADD_UINT(&adapter->sysctl_ctx, + SYSCTL_CHILDREN(adapter->sysctl_tree), OID_AUTO, + "serializer_tryfail", CTLFLAG_RW, + &ifp->if_serializer->tryfail_cnt, 0, NULL); +#endif + /* * Tell the upper layer(s) we support long frames. */ diff --git a/sys/kern/lwkt_serialize.c b/sys/kern/lwkt_serialize.c index 635956b599..033c90c836 100644 --- a/sys/kern/lwkt_serialize.c +++ b/sys/kern/lwkt_serialize.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_serialize.c,v 1.9 2005/12/01 18:34:09 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_serialize.c,v 1.10 2008/04/02 13:11:48 sephe Exp $ */ /* * This API provides a fast locked-bus-cycle-based serializer. It's @@ -44,6 +44,8 @@ * disablement facility. */ +#include "opt_serializer.h" + #include #include #include @@ -68,6 +70,10 @@ lwkt_serialize_init(lwkt_serialize_t s) #ifdef INVARIANTS s->last_td = (void *)-4; #endif +#ifdef PROFILE_SERIALIZER + s->sleep_cnt = 0; + s->tryfail_cnt = 0; +#endif } void @@ -99,6 +105,9 @@ lwkt_serialize_try(lwkt_serialize_t s) #endif return(1); } +#ifdef PROFILE_SERIALIZER + s->tryfail_cnt++; +#endif return (0); } @@ -177,6 +186,9 @@ lwkt_serialize_handler_try(lwkt_serialize_t s, void (*func)(void *, void *), return(0); } } +#ifdef PROFILE_SERIALIZER + s->tryfail_cnt++; +#endif return(1); } @@ -195,8 +207,12 @@ lwkt_serialize_sleep(void *info) lwkt_serialize_t s = info; crit_enter(); tsleep_interlock(s); - if (atomic_intr_cond_test(&s->interlock) != 0) + if (atomic_intr_cond_test(&s->interlock) != 0) { +#ifdef PROFILE_SERIALIZER + s->sleep_cnt++; +#endif tsleep(s, 0, "slize", 0); + } crit_exit(); } diff --git a/sys/sys/serialize.h b/sys/sys/serialize.h index 8911582633..2d45d2dad1 100644 --- a/sys/sys/serialize.h +++ b/sys/sys/serialize.h @@ -8,7 +8,7 @@ * required. Unlike tokens this serialization is not safe from deadlocks * nor is it recursive, and care must be taken when using it. * - * $DragonFly: src/sys/sys/serialize.h,v 1.5 2008/03/16 15:22:45 sephe Exp $ + * $DragonFly: src/sys/sys/serialize.h,v 1.6 2008/04/02 13:11:48 sephe Exp $ */ #ifndef _SYS_SERIALIZE_H_ @@ -23,6 +23,8 @@ struct thread; struct lwkt_serialize { __atomic_intr_t interlock; struct thread *last_td; + unsigned int sleep_cnt; + unsigned int tryfail_cnt; }; /* -- 2.41.0