svn commit: r273958 - head/sys/dev/random

Jilles Tjoelker jilles at stack.nl
Sun Nov 2 20:59:58 UTC 2014


On Sun, Nov 02, 2014 at 12:27:32PM -0800, Xin Li wrote:
> I'd like to propose the attached patch for review.  It replaces
> tsleep's with sx_sleep's, then checks the return value and quit the
> loop.

While you're there, please adjust the wait messages from "block" to
something like "randrd" and "randwr".

This change also stops it from retrying after 100ms. Although such
polling is generally poor design, just giving up after 100ms may not be
the right thing to do here.

If the write delay is supposed to be annoying and to stop "swamping",
perhaps it should not allow signals to cut it short.

> Index: sys/dev/random/random_adaptors.c
> ===================================================================
> --- sys/dev/random/random_adaptors.c	(revision 273982)
> +++ sys/dev/random/random_adaptors.c	(working copy)
> @@ -217,7 +217,7 @@ random_adaptor_read(struct cdev *dev __unused, str
>  
>  	/* (Un)Blocking logic */
>  	error = 0;
> -	while (!random_adaptor->ra_seeded()) {
> +	while (!random_adaptor->ra_seeded() && error == 0) {
>  		if (flags & O_NONBLOCK)	{
>  			error = EWOULDBLOCK;
>  			break;
> @@ -224,7 +224,8 @@ random_adaptor_read(struct cdev *dev __unused, str
>  		}
>  
>  		/* Sleep instead of going into a spin-frenzy */
> -		tsleep(&random_adaptor, PUSER | PCATCH, "block", hz/10);
> +		error = sx_sleep(&random_adaptor, &random_adaptors_lock,
> +		    PUSER | PCATCH, "block", hz/10);
>  
>  		/* keep tapping away at the pre-read until we seed/unblock. */
>  		(random_adaptor->ra_read)(NULL, 0);
> @@ -298,7 +299,7 @@ random_adaptor_write(struct cdev *dev __unused, st
>  
>  	random_buf = malloc(PAGE_SIZE, M_ENTROPY, M_WAITOK);
>  
> -	while (uio->uio_resid > 0) {
> +	while (uio->uio_resid > 0 && error == 0) {
>  		c = MIN(uio->uio_resid, PAGE_SIZE);
>  		error = uiomove(random_buf, c, uio);
>  		if (error)
> @@ -306,7 +307,8 @@ random_adaptor_write(struct cdev *dev __unused, st
>  		(random_adaptor->ra_write)(random_buf, c);
>  
>  		/* Introduce an annoying delay to stop swamping */
> -		tsleep(&random_adaptor, PUSER | PCATCH, "block", hz/10);
> +		error = sx_sleep(&random_adaptor, &random_adaptors_lock,
> +		    PUSER | PCATCH, "block", hz/10);
>  	}
>  
>  	free(random_buf, M_ENTROPY);

-- 
Jilles Tjoelker


More information about the svn-src-head mailing list