Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Feb 2011 16:35:10 +0000 (UTC)
From:      Matthew D Fleming <mdf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r218195 - in head/sys: amd64/amd64 arm/arm i386/i386 ia64/ia64 kern mips/mips powerpc/powerpc sparc64/sparc64 sun4v/sun4v sys ufs/ffs
Message-ID:  <201102021635.p12GZA94015170@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mdf
Date: Wed Feb  2 16:35:10 2011
New Revision: 218195
URL: http://svn.freebsd.org/changeset/base/218195

Log:
  Put the general logic for being a CPU hog into a new function
  should_yield().  Use this in various places.  Encapsulate the common
  case of check-and-yield into a new function maybe_yield().
  
  Change several checks for a magic number of iterations to use
  should_yield() instead.
  
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/uio_machdep.c
  head/sys/arm/arm/uio_machdep.c
  head/sys/i386/i386/uio_machdep.c
  head/sys/ia64/ia64/uio_machdep.c
  head/sys/kern/imgact_elf.c
  head/sys/kern/subr_uio.c
  head/sys/kern/vfs_mount.c
  head/sys/kern/vfs_subr.c
  head/sys/mips/mips/uio_machdep.c
  head/sys/powerpc/powerpc/uio_machdep.c
  head/sys/sparc64/sparc64/uio_machdep.c
  head/sys/sun4v/sun4v/uio_machdep.c
  head/sys/sys/uio.h
  head/sys/sys/vnode.h
  head/sys/ufs/ffs/ffs_rawread.c
  head/sys/ufs/ffs/ffs_softdep.c

Modified: head/sys/amd64/amd64/uio_machdep.c
==============================================================================
--- head/sys/amd64/amd64/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/amd64/amd64/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -88,8 +88,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		    page_offset;
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/arm/arm/uio_machdep.c
==============================================================================
--- head/sys/arm/arm/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/arm/arm/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -94,8 +94,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		cp = (char*)sf_buf_kva(sf) + page_offset;
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/i386/i386/uio_machdep.c
==============================================================================
--- head/sys/i386/i386/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/i386/i386/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -90,8 +90,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		cp = (char *)sf_buf_kva(sf) + page_offset;
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/ia64/ia64/uio_machdep.c
==============================================================================
--- head/sys/ia64/ia64/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/ia64/ia64/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -89,8 +89,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		    page_offset;
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/kern/imgact_elf.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -1622,8 +1622,7 @@ compress_core (gzFile file, char *inbuf,
 		}
 		inbuf += chunk_len;
 		len -= chunk_len;
-		if (ticks - PCPU_GET(switchticks) >= hogticks)
-			uio_yield();
+		maybe_yield();
 	}
 
 	return (error);

Modified: head/sys/kern/subr_uio.c
==============================================================================
--- head/sys/kern/subr_uio.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/kern/subr_uio.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -158,8 +158,7 @@ uiomove(void *cp, int n, struct uio *uio
 		switch (uio->uio_segflg) {
 
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else
@@ -283,11 +282,8 @@ uiomoveco(void *cp, int n, struct uio *u
 		switch (uio->uio_segflg) {
 
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
-
+			maybe_yield();
 			error = userspaceco(cp, cnt, uio, disposable);
-
 			if (error)
 				return (error);
 			break;
@@ -356,6 +352,21 @@ again:
 	return (0);
 }
 
+int
+should_yield(void)
+{
+
+	return (ticks - PCPU_GET(switchticks) >= hogticks);
+}
+
+void
+maybe_yield(void)
+{
+
+	if (should_yield())
+		uio_yield();
+}
+
 void
 uio_yield(void)
 {

Modified: head/sys/kern/vfs_mount.c
==============================================================================
--- head/sys/kern/vfs_mount.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/kern/vfs_mount.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -1659,9 +1659,8 @@ __mnt_vnode_next(struct vnode **mvp, str
 	mtx_assert(MNT_MTX(mp), MA_OWNED);
 
 	KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
-	if ((*mvp)->v_yield++ == 500) {
+	if (should_yield()) {
 		MNT_IUNLOCK(mp);
-		(*mvp)->v_yield = 0;
 		uio_yield();
 		MNT_ILOCK(mp);
 	}

Modified: head/sys/kern/vfs_subr.c
==============================================================================
--- head/sys/kern/vfs_subr.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/kern/vfs_subr.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -707,11 +707,11 @@ vlrureclaim(struct mount *mp)
 		vdropl(vp);
 		done++;
 next_iter_mntunlocked:
-		if ((count % 256) != 0)
+		if (should_yield())
 			goto relock_mnt;
 		goto yield;
 next_iter:
-		if ((count % 256) != 0)
+		if (should_yield())
 			continue;
 		MNT_IUNLOCK(mp);
 yield:

Modified: head/sys/mips/mips/uio_machdep.c
==============================================================================
--- head/sys/mips/mips/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/mips/mips/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -107,8 +107,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		}
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/powerpc/powerpc/uio_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/powerpc/powerpc/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -97,8 +97,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 
 		switch (uio->uio_segflg) {
 			case UIO_USERSPACE:
-				if (ticks - PCPU_GET(switchticks) >= hogticks)
-					uio_yield();
+				maybe_yield();
 				if (uio->uio_rw == UIO_READ)
 					error = copyout(cp, iov->iov_base, cnt);
 				else

Modified: head/sys/sparc64/sparc64/uio_machdep.c
==============================================================================
--- head/sys/sparc64/sparc64/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/sparc64/sparc64/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -103,8 +103,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		}
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/sun4v/sun4v/uio_machdep.c
==============================================================================
--- head/sys/sun4v/sun4v/uio_machdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/sun4v/sun4v/uio_machdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -94,8 +94,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offs
 		cp = (char *)TLB_PHYS_TO_DIRECT(pa) + page_offset;
 		switch (uio->uio_segflg) {
 		case UIO_USERSPACE:
-			if (ticks - PCPU_GET(switchticks) >= hogticks)
-				uio_yield();
+			maybe_yield();
 			if (uio->uio_rw == UIO_READ)
 				error = copyout(cp, iov->iov_base, cnt);
 			else

Modified: head/sys/sys/uio.h
==============================================================================
--- head/sys/sys/uio.h	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/sys/uio.h	Wed Feb  2 16:35:10 2011	(r218195)
@@ -95,6 +95,8 @@ int	copyinstrfrom(const void * __restric
 	    size_t len, size_t * __restrict copied, int seg);
 int	copyinuio(struct iovec *iovp, u_int iovcnt, struct uio **uiop);
 void	uio_yield(void);
+void	maybe_yield(void);
+int	should_yield(void);
 int	uiomove(void *cp, int n, struct uio *uio);
 int	uiomove_frombuf(void *buf, int buflen, struct uio *uio);
 int	uiomove_fromphys(struct vm_page *ma[], vm_offset_t offset, int n,

Modified: head/sys/sys/vnode.h
==============================================================================
--- head/sys/sys/vnode.h	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/sys/vnode.h	Wed Feb  2 16:35:10 2011	(r218195)
@@ -121,7 +121,6 @@ struct vnode {
 		struct socket	*vu_socket;	/* v unix domain net (VSOCK) */
 		struct cdev	*vu_cdev; 	/* v device (VCHR, VBLK) */
 		struct fifoinfo	*vu_fifoinfo;	/* v fifo (VFIFO) */
-		int		vu_yield;	/*   yield count (VMARKER) */
 	} v_un;
 
 	/*
@@ -177,7 +176,6 @@ struct vnode {
 #define	v_socket	v_un.vu_socket
 #define	v_rdev		v_un.vu_cdev
 #define	v_fifoinfo	v_un.vu_fifoinfo
-#define	v_yield		v_un.vu_yield
 
 /* XXX: These are temporary to avoid a source sweep at this time */
 #define v_object	v_bufobj.bo_object

Modified: head/sys/ufs/ffs/ffs_rawread.c
==============================================================================
--- head/sys/ufs/ffs/ffs_rawread.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/ufs/ffs/ffs_rawread.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -243,8 +243,7 @@ ffs_rawread_readahead(struct vnode *vp,
 		if (vmapbuf(bp) < 0)
 			return EFAULT;
 		
-		if (ticks - PCPU_GET(switchticks) >= hogticks)
-			uio_yield();
+		maybe_yield();
 		bzero(bp->b_data, bp->b_bufsize);
 
 		/* Mark operation completed (similar to bufdone()) */

Modified: head/sys/ufs/ffs/ffs_softdep.c
==============================================================================
--- head/sys/ufs/ffs/ffs_softdep.c	Wed Feb  2 15:53:09 2011	(r218194)
+++ head/sys/ufs/ffs/ffs_softdep.c	Wed Feb  2 16:35:10 2011	(r218195)
@@ -1342,7 +1342,7 @@ softdep_process_worklist(mp, full)
 	int full;
 {
 	struct thread *td = curthread;
-	int cnt, matchcnt, loopcount;
+	int cnt, matchcnt;
 	struct ufsmount *ump;
 	long starttime;
 
@@ -1354,7 +1354,6 @@ softdep_process_worklist(mp, full)
 	matchcnt = 0;
 	ump = VFSTOUFS(mp);
 	ACQUIRE_LOCK(&lk);
-	loopcount = 1;
 	starttime = time_second;
 	softdep_process_journal(mp, full?MNT_WAIT:0);
 	while (ump->softdep_on_worklist > 0) {
@@ -1379,7 +1378,7 @@ softdep_process_worklist(mp, full)
 		 * We do not generally want to stop for buffer space, but if
 		 * we are really being a buffer hog, we will stop and wait.
 		 */
-		if (loopcount++ % 128 == 0) {
+		if (should_yield()) {
 			FREE_LOCK(&lk);
 			uio_yield();
 			bwillwrite();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102021635.p12GZA94015170>