svn commit: r274088 - head/sys/kern
Hans Petter Selasky
hselasky at FreeBSD.org
Tue Nov 4 11:29:50 UTC 2014
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);
}
More information about the svn-src-all
mailing list