svn commit: r274088 - head/sys/kern

Mateusz Guzik mjguzik at gmail.com
Tue Nov 4 11:40:47 UTC 2014


On Tue, Nov 04, 2014 at 11:29:49AM +0000, Hans Petter Selasky wrote:
> 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);

Should not you align to word size instead?

Also maybe it would be beneficial to derive the limit from KSTACK_PAGES
(something silly like KSTACK_PAGES * 32 or something), which I believe would
address earlier complaints.

>  	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);
>  }
> 

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the svn-src-all mailing list