[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [UNIKRAFT PATCH 3/5] lib/ukmpi: Provide ring buffer allocation and free methods



Hi Alexander,

I don't understand where this is coming from. Was it also taken from
FreeBSD? If so then it should be introduced together with the other
copy-pasted code (that same commit should introduce both buf_ring.h and
ring.c). And the adaption commit would add the differences. If Simon is
also an author then I think you should also add his Signed-off-by.

And please don't forget to run checkpatch (for this one and buf_ring.h).

Cheers,
Costin


On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@xxxxxxxxx>
> 
> This commit introduces two new methods for initializing and
> de-initializing ring buffers.
> 
> Signed-off-by: Alexander Jung <alexander.jung@xxxxxxxxx>
> ---
>  lib/ukmpi/ring.c | 87 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
>  create mode 100644 lib/ukmpi/ring.c
> 
> diff --git a/lib/ukmpi/ring.c b/lib/ukmpi/ring.c
> new file mode 100644
> index 0000000..1fbb81e
> --- /dev/null
> +++ b/lib/ukmpi/ring.c
> @@ -0,0 +1,87 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Kip Macy <kmacy@xxxxxxxxxxx>
> + *          Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
> + *          Alexander Jung <alexander.jung@xxxxxxxxx>
> + *
> + * Copyright (c) 2007-2009, Kip Macy <kmacy@xxxxxxxxxxx>
> + *               2018-2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *               All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
> IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +/*
> + * Simple ring implementation to handle object references.
> + *
> + * Inspired by FreeBSD and modified (commit-id: c45cce1).
> + */
> +
> +
> +#include <sys/param.h>
> +#include <uk/ring.h>
> +#include <uk/assert.h>
> +#include <uk/alloc.h>
> +#include <uk/mutex.h>
> +#include <uk/config.h>
> +#include <uk/print.h>
> +
> +#ifndef POWER_OF_2
> +#define POWER_OF_2(x)   (((x)) && (!((x) & ((x) - 1))))
> +#endif
> +
> +struct uk_ring *
> +uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex 
> *lock)
> +{
> +  struct uk_ring *br;
> +
> +  UK_ASSERT(a);
> +  /* Buf ring must be size power of 2 */
> +  UK_ASSERT(POWER_OF_2(count));
> +  
> +  br = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
> +  if (br == NULL) {
> +    uk_pr_err("Could not allocate ring: out of memory\n");
> +    return NULL;
> +  }
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  br->lock = lock;
> +#endif  
> +
> +  br->prod_size = br->cons_size = count;
> +  br->prod_mask = br->cons_mask = count - 1;
> +  br->prod_head = br->cons_head = 0;
> +  br->prod_tail = br->cons_tail = 0;
> +
> +  return br;
> +}
> +
> +void
> +uk_ring_free(struct uk_ring *br, struct uk_alloc *a)
> +{
> +  UK_ASSERT(a);
> +  uk_free(a, br);
> +}
> 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.