Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Nov 2014 11:29:49 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r274088 - head/sys/kern
Message-ID:  <201411041129.sA4BTnwX030600@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Nov  4 11:29:49 2014
New Revision: 274088
URL: https://svnweb.freebsd.org/changeset/base/274088

Log:
  Simplify logic a bit. Ensure data buffer is properly aligned,
  especially for platforms where unaligned access is not allowed. Make
  it possible to override the small buffer size.
  
  A simple continuous read string test using libusb showed a reduction
  in CPU usage from roughly 10% to less than 1% using a dual-core GHz
  CPU, when the malloc() operation was skipped for small buffers.
  
  MFC after:	2 weeks

Modified:
  head/sys/kern/sys_generic.c

Modified: head/sys/kern/sys_generic.c
==============================================================================
--- head/sys/kern/sys_generic.c	Tue Nov  4 10:25:52 2014	(r274087)
+++ head/sys/kern/sys_generic.c	Tue Nov  4 11:29:49 2014	(r274088)
@@ -646,10 +646,13 @@ struct ioctl_args {
 int
 sys_ioctl(struct thread *td, struct ioctl_args *uap)
 {
+#ifndef SYS_IOCTL_SMALL_SIZE
+#define	SYS_IOCTL_SMALL_SIZE 128
+#endif
+	u_char smalldata[SYS_IOCTL_SMALL_SIZE] __aligned(8);
 	u_long com;
 	int arg, error;
 	u_int size;
-	u_char smalldata[128];
 	caddr_t data;
 
 	if (uap->com > 0xffffffff) {
@@ -682,10 +685,10 @@ sys_ioctl(struct thread *td, struct ioct
 			data = (void *)&arg;
 			size = 0;
 		} else {
-			if (size <= sizeof(smalldata))
-				data = smalldata;
-			else
+			if (size > SYS_IOCTL_SMALL_SIZE)
 				data = malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
+			else
+				data = smalldata;
 		}
 	} else
 		data = (void *)&uap->data;
@@ -707,7 +710,7 @@ sys_ioctl(struct thread *td, struct ioct
 		error = copyout(data, uap->data, (u_int)size);
 
 out:
-	if (size > 0 && data != (caddr_t)&smalldata)
+	if (size > SYS_IOCTL_SMALL_SIZE)
 		free(data, M_IOCTLOPS);
 	return (error);
 }



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