[openib-general] Re: [PATCH] kDAPL: cstyle dat-provider/dapl_ring_buffer_util.c

James Lentini jlentini at netapp.com
Thu Jun 23 19:27:40 PDT 2005


Committed in revision 2705.

On Thu, 23 Jun 2005, Tom Duffy wrote:

tduffy> Signed-off-by: Tom Duffy <tduffy at sun.com>
tduffy> 
tduffy> Index: linux-kernel-work/dat-provider/dapl_ring_buffer_util.c
tduffy> ===================================================================
tduffy> --- linux-kernel-work/dat-provider/dapl_ring_buffer_util.c	(revision 2704)
tduffy> +++ linux-kernel-work/dat-provider/dapl_ring_buffer_util.c	(working copy)
tduffy> @@ -63,9 +63,8 @@ u32 dapl_rbuf_alloc(struct dapl_ring_buf
tduffy>  
tduffy>  	/* Put size on a power of 2 boundary */
tduffy>  	rsize = 1;
tduffy> -	while ((int) rsize < size) {
tduffy> +	while ((int) rsize < size)
tduffy>  		rsize <<= 1;
tduffy> -	}
tduffy>  
tduffy>  	rbuf->base = kmalloc(rsize * sizeof *rbuf->base, GFP_ATOMIC);
tduffy>  	if (rbuf->base) {
tduffy> @@ -100,42 +99,37 @@ u32 dapl_rbuf_alloc(struct dapl_ring_buf
tduffy>   */
tduffy>  u32 dapl_rbuf_realloc(struct dapl_ring_buffer *rbuf, int size)
tduffy>  {
tduffy> -    struct dapl_ring_buffer new_rbuf;
tduffy> -    void *entry;
tduffy> -    u32 dat_status = DAT_SUCCESS;
tduffy> -
tduffy> -    /* decreasing the size or retaining the old size is not allowed */
tduffy> -    if (size <= rbuf->lim + 1)
tduffy> -    {
tduffy> -	dat_status = DAT_ERROR (DAT_INVALID_PARAMETER, DAT_INVALID_ARG2);
tduffy> -	goto bail;
tduffy> -    }
tduffy> -
tduffy> -    /*
tduffy> -     * !This is NOT ATOMIC!
tduffy> -     * Simple algorithm: Allocate a new ring buffer, take everything
tduffy> -     * out of the old one and put it in the new one, and release the 
tduffy> -     * old base buffer.
tduffy> -     */
tduffy> -    dat_status = dapl_rbuf_alloc (&new_rbuf, size);
tduffy> -    if (dat_status != DAT_SUCCESS)
tduffy> -    {
tduffy> -	goto bail;
tduffy> -    }
tduffy> -
tduffy> -    while ( (entry = dapl_rbuf_remove(rbuf)) != NULL)
tduffy> -    {
tduffy> -	/* We know entries will fit so ignore the return code */
tduffy> -	(void)dapl_rbuf_add (&new_rbuf, entry);
tduffy> -    }
tduffy> +	struct dapl_ring_buffer new_rbuf;
tduffy> +	void *entry;
tduffy> +	u32 status = DAT_SUCCESS;
tduffy> +
tduffy> +	/* decreasing the size or retaining the old size is not allowed */
tduffy> +	if (size <= rbuf->lim + 1) {
tduffy> +		status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2);
tduffy> +		goto bail;
tduffy> +	}
tduffy> +
tduffy> +	/*
tduffy> +	 * !This is NOT ATOMIC!
tduffy> +	 * Simple algorithm: Allocate a new ring buffer, take everything
tduffy> +	 * out of the old one and put it in the new one, and release the 
tduffy> +	 * old base buffer.
tduffy> +	 */
tduffy> +	status = dapl_rbuf_alloc(&new_rbuf, size);
tduffy> +	if (status != DAT_SUCCESS)
tduffy> +		goto bail;
tduffy> +
tduffy> +	while ((entry = dapl_rbuf_remove(rbuf)) != NULL)
tduffy> +		/* We know entries will fit so ignore the return code */
tduffy> +		(void)dapl_rbuf_add(&new_rbuf, entry);
tduffy>  
tduffy> -    /* release the old base buffer */
tduffy> -    kfree(rbuf->base);
tduffy> +	/* release the old base buffer */
tduffy> +	kfree(rbuf->base);
tduffy>  
tduffy> -    *rbuf = new_rbuf;
tduffy> +	*rbuf = new_rbuf;
tduffy>   
tduffy> - bail:
tduffy> -    return dat_status;
tduffy> +bail:
tduffy> +	return status;
tduffy>  }
tduffy>  
tduffy>  /*
tduffy> @@ -155,9 +149,8 @@ u32 dapl_rbuf_realloc(struct dapl_ring_b
tduffy>   */
tduffy>  void dapl_rbuf_destroy(struct dapl_ring_buffer *rbuf)
tduffy>  {
tduffy> -	if ((NULL == rbuf) || (NULL == rbuf->base)) {
tduffy> +	if ((NULL == rbuf) || (NULL == rbuf->base))
tduffy>  		return;
tduffy> -	}
tduffy>  
tduffy>  	kfree(rbuf->base);
tduffy>  	rbuf->base = NULL;
tduffy> @@ -221,22 +214,18 @@ u32 dapl_rbuf_add(struct dapl_ring_buffe
tduffy>   */
tduffy>  void *dapl_rbuf_remove(struct dapl_ring_buffer *rbuf)
tduffy>  {
tduffy> -	int pos;
tduffy> -	int val;
tduffy> +	int pos, val;
tduffy>  
tduffy> -	while (atomic_read(&rbuf->head) !=
tduffy> -	       atomic_read(&rbuf->tail)) {
tduffy> +	while (atomic_read(&rbuf->head) != atomic_read(&rbuf->tail)) {
tduffy>  		pos = atomic_read(&rbuf->tail);
tduffy>  		val = dapl_os_atomic_assign(&rbuf->tail, pos, pos + 1);
tduffy>  		if (val == pos) {
tduffy>  			pos = (pos + 1) & rbuf->lim;	/* verify in range */
tduffy> -
tduffy>  			return rbuf->base[pos];
tduffy>  		}
tduffy>  	}
tduffy>  
tduffy>  	return NULL;
tduffy> -
tduffy>  }
tduffy>  
tduffy>  /*
tduffy> @@ -261,12 +250,10 @@ int dapl_rbuf_count(struct dapl_ring_buf
tduffy>  
tduffy>  	head = atomic_read(&rbuf->head) & rbuf->lim;
tduffy>  	tail = atomic_read(&rbuf->tail) & rbuf->lim;
tduffy> -	if (head > tail) {
tduffy> +	if (head > tail)
tduffy>  		count = head - tail;
tduffy> -	} else {
tduffy> -		/* add 1 to lim as it is a mask, number of entries - 1 */
tduffy> +	else /* add 1 to lim as it is a mask, number of entries - 1 */
tduffy>  		count = (rbuf->lim + 1 - tail + head) & rbuf->lim;
tduffy> -	}
tduffy>  
tduffy>  	return count;
tduffy>  }
tduffy> @@ -292,12 +279,11 @@ int dapl_rbuf_count(struct dapl_ring_buf
tduffy>   */
tduffy>  void dapl_rbuf_adjust(struct dapl_ring_buffer *rbuf, unsigned long offset)
tduffy>  {
tduffy> -    int	pos;
tduffy> +	int pos;
tduffy>  
tduffy> -    pos = atomic_read(&rbuf->head);
tduffy> -    while ( pos != atomic_read(&rbuf->tail) )
tduffy> -    {
tduffy> -	rbuf->base[pos] = rbuf->base[pos] + offset;
tduffy> -	pos = (pos + 1) & rbuf->lim; /* verify in range */
tduffy> -    }
tduffy> +	pos = atomic_read(&rbuf->head);
tduffy> +	while (pos != atomic_read(&rbuf->tail)) {
tduffy> +		rbuf->base[pos] = rbuf->base[pos] + offset;
tduffy> +		pos = (pos + 1) & rbuf->lim; /* verify in range */
tduffy> +	}
tduffy>  }
tduffy> 



More information about the general mailing list