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

Re: [Minios-devel] [UNIKRAFT PATCH v2] arch/spinlock: Add spin_lock_irq variants


  • To: Cristian Banu <cristb@xxxxxxxxx>, "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
  • Date: Wed, 29 May 2019 12:44:52 +0000
  • Accept-language: en-GB, gl-ES, de-DE, en-US
  • Delivery-date: Wed, 29 May 2019 12:45:05 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHU621RlTjmGfbI5UWt37E2pZk5AaaCYcMA
  • Thread-topic: [UNIKRAFT PATCH v2] arch/spinlock: Add spin_lock_irq variants

Looks fine to me. Thanks!

Reviewed-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>

On 05.04.19, 07:06, "Cristian Banu" <cristb@xxxxxxxxx> wrote:

    Spin_lock_irq* variants are used for synchronizing data that might be
    accessed from within an interrupt handler. Added (void)(lock) to each
    of the spin_lock macros to force the compiler to check the existence
    of the lock.
    
    The DEFINE_SPINLOCK() macro now defines the variable, and thus it can
    be used as `static DEFINE_SPINLOCK(x)`.
    
    Signed-off-by: Cristian Banu <cristb@xxxxxxxxx>
    ---
    Changes in v2:
     - Move the irq variants to plat/spinlock.
    ---
     include/uk/arch/spinlock.h | 12 +++++-----
     include/uk/plat/spinlock.h | 59 
++++++++++++++++++++++++++++++++++++++++++++++
     2 files changed, 65 insertions(+), 6 deletions(-)
     create mode 100644 include/uk/plat/spinlock.h
    
    diff --git a/include/uk/arch/spinlock.h b/include/uk/arch/spinlock.h
    index b7a7501e3bfb..16d2fe5d5d97 100644
    --- a/include/uk/arch/spinlock.h
    +++ b/include/uk/arch/spinlock.h
    @@ -36,14 +36,14 @@ typedef struct {} spinlock_t;
     #error "Define your spinlock operations!"
     #else
     
    -#define ukarch_spin_lock_init(lock)      do {} while (0)
    -#define ukarch_spin_is_locked(lock)      do {} while (0)
    -#define ukarch_spin_lock(lock)           do {} while (0)
    -#define ukarch_spin_trylock(lock)        do {} while (0)
    -#define ukarch_spin_unlock(lock)         do {} while (0)
    +#define ukarch_spin_lock_init(lock)      (void)(lock)
    +#define ukarch_spin_is_locked(lock)      (void)(lock)
    +#define ukarch_spin_lock(lock)           (void)(lock)
    +#define ukarch_spin_trylock(lock)        (void)(lock)
    +#define ukarch_spin_unlock(lock)         (void)(lock)
     
     /* Defines a preinitialized spin_lock in unlocked state */
    -#define DEFINE_SPINLOCK(lock)            do {} while (0)
    +#define DEFINE_SPINLOCK(lock)            spinlock_t lock = {}
     
     #endif
     
    diff --git a/include/uk/plat/spinlock.h b/include/uk/plat/spinlock.h
    new file mode 100644
    index 000000000000..54801afea22b
    --- /dev/null
    +++ b/include/uk/plat/spinlock.h
    @@ -0,0 +1,59 @@
    +/* SPDX-License-Identifier: BSD-2-Clause */
    +/*
    + * Authors: Cristian Banu <cristb@xxxxxxxxx>
    + *
    + * Copyright (c) 2019, Politehnica University of Bucharest. 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.
    + *
    + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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.
    + */
    +
    +#ifndef __UKPLAT_SPINLOCK_H__
    +#define __UKPLAT_SPINLOCK_H__
    +
    +#include <uk/arch/spinlock.h>
    +#include <uk/plat/lcpu.h>
    +
    +#define ukplat_spin_lock_irq(lock) \
    +   do { \
    +           ukplat_lcpu_disable_irq(); \
    +           ukarch_spin_lock(lock); \
    +   } while (0)
    +
    +#define ukplat_spin_unlock_irq(lock) \
    +   do { \
    +           ukarch_spin_unlock(lock); \
    +           ukplat_lcpu_enable_irq(); \
    +   } while (0)
    +
    +#define ukplat_spin_lock_irqsave(lock, flags) \
    +   do { \
    +           flags = ukplat_lcpu_save_irqf(); \
    +           ukarch_spin_lock(lock); \
    +   } while (0)
    +
    +#define ukplat_spin_unlock_irqrestore(lock, flags) \
    +   do { \
    +           ukarch_spin_unlock(lock); \
    +           ukplat_lcpu_restore_irqf(flags); \
    +   } while (0)
    +
    +#endif /* __PLAT_SPINLOCK_H__ */
    -- 
    2.11.0
    
    

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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