Changeset 4621d23 in mainline


Ignore:
Timestamp:
2018-09-06T19:54:11Z (5 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
508b0df1
Parents:
ffa73c6
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-13 03:00:17)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-06 19:54:11)
Message:

Use compiler builtins for kernel atomics

Files:
9 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • abi/include/_bits/native.h

    rffa73c6 r4621d23  
    5555typedef __UINTPTR_TYPE__ sysarg_t;
    5656typedef __INTPTR_TYPE__  native_t;
    57 typedef __UINTPTR_TYPE__ atomic_count_t;
    58 typedef __INTPTR_TYPE__  atomic_signed_t;
    5957
    6058#define PRIdn  __PRIdPTR__  /**< Format for native_t. */
    6159#define PRIun  __PRIuPTR__  /**< Format for sysarg_t. */
    6260#define PRIxn  __PRIxPTR__  /**< Format for hexadecimal sysarg_t. */
    63 #define PRIua  __PRIuPTR__  /**< Format for atomic_count_t. */
    6461
    6562#endif
  • kernel/arch/arm32/src/atomic.c

    rffa73c6 r4621d23  
    3636#include <synch/spinlock.h>
    3737#include <arch/barrier.h>
     38#include <arch/asm.h>
    3839
     40unsigned __atomic_fetch_add_4(volatile unsigned *mem, unsigned val, int model)
     41{
     42        /*
     43         * This implementation is for UP pre-ARMv6 systems where we do not have
     44         * the LDREX and STREX instructions.
     45         */
     46        ipl_t ipl = interrupts_disable();
     47        unsigned ret = *mem;
     48        *mem += val;
     49        interrupts_restore(ipl);
     50        return ret;
     51}
     52
     53unsigned __atomic_fetch_sub_4(volatile unsigned *mem, unsigned val, int model)
     54{
     55        ipl_t ipl = interrupts_disable();
     56        unsigned ret = *mem;
     57        *mem -= val;
     58        interrupts_restore(ipl);
     59        return ret;
     60}
    3961
    4062IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(cas_lock, "arm-cas-lock");
  • kernel/generic/include/atomic.h

    rffa73c6 r4621d23  
    3636#define KERN_ATOMIC_H_
    3737
     38#include <stdbool.h>
    3839#include <typedefs.h>
    39 #include <arch/atomic.h>
    40 #include <verify.h>
     40#include <stdatomic.h>
    4141
    42 NO_TRACE ATOMIC static inline void atomic_set(atomic_t *val, atomic_count_t i)
    43     WRITES(&val->count)
    44     REQUIRES_EXTENT_MUTABLE(val)
     42typedef size_t atomic_count_t;
     43typedef ssize_t atomic_signed_t;
     44
     45#define PRIua  "zu"          /**< Format for atomic_count_t. */
     46
     47typedef struct {
     48        volatile atomic_size_t count;
     49} atomic_t;
     50
     51static inline void atomic_set(atomic_t *val, atomic_count_t i)
    4552{
    46         val->count = i;
     53        atomic_store(&val->count, i);
    4754}
    4855
    49 NO_TRACE ATOMIC static inline atomic_count_t atomic_get(atomic_t *val)
    50     REQUIRES_EXTENT_MUTABLE(val)
     56static inline atomic_count_t atomic_get(atomic_t *val)
    5157{
    52         return val->count;
     58        return atomic_load(&val->count);
    5359}
    5460
     61static inline size_t atomic_predec(atomic_t *val)
     62{
     63        return atomic_fetch_sub(&val->count, 1) - 1;
     64}
    5565
    56 /*
    57  * If the architecture does not provide operations that are atomic
    58  * only with respect to the local cpu (eg exception handlers) and
    59  * not other cpus, implement these cpu local atomic operations with
    60  * full blown smp-safe atomics.
    61  */
    62 #ifndef local_atomic_exchange
     66static inline size_t atomic_preinc(atomic_t *val)
     67{
     68        return atomic_fetch_add(&val->count, 1) + 1;
     69}
     70
     71static inline size_t atomic_postdec(atomic_t *val)
     72{
     73        return atomic_fetch_sub(&val->count, 1);
     74}
     75
     76static inline size_t atomic_postinc(atomic_t *val)
     77{
     78        return atomic_fetch_add(&val->count, 1);
     79}
     80
     81static inline void atomic_dec(atomic_t *val)
     82{
     83        atomic_fetch_sub(&val->count, 1);
     84}
     85
     86static inline void atomic_inc(atomic_t *val)
     87{
     88        atomic_fetch_add(&val->count, 1);
     89}
     90
    6391#define local_atomic_exchange(var_addr, new_val) \
    64         __atomic_exchange_n((var_addr), (new_val), __ATOMIC_RELAXED)
    65 #endif
     92        atomic_exchange_explicit(var_addr, new_val, memory_order_relaxed)
    6693
     94static inline bool test_and_set(atomic_t *val)
     95{
     96        return atomic_exchange(&val->count, 1);
     97}
    6798
    6899
  • kernel/generic/include/typedefs.h

    rffa73c6 r4621d23  
    3939#include <_bits/errno.h>
    4040
    41 typedef struct {
    42         volatile atomic_count_t count;
    43 } atomic_t;
    44 
    4541typedef void (*function)(void);
    4642
  • kernel/generic/include/verify.h

    rffa73c6 r4621d23  
    3939#ifdef CONFIG_VERIFY_VCC
    4040
    41 #define ATOMIC         __specification_attr("atomic_inline", "")
    42 
    4341#define READS(ptr)     __specification(reads(ptr))
    4442#define WRITES(ptr)    __specification(writes(ptr))
     
    5553
    5654#else /* CONFIG_VERIFY_VCC */
    57 
    58 #define ATOMIC
    5955
    6056#define READS(ptr)
  • kernel/generic/src/proc/scheduler.c

    rffa73c6 r4621d23  
    4040
    4141#include <assert.h>
     42#include <atomic.h>
    4243#include <proc/scheduler.h>
    4344#include <proc/thread.h>
  • uspace/lib/c/include/atomic.h

    rffa73c6 r4621d23  
    4242typedef size_t atomic_count_t;
    4343typedef ssize_t atomic_signed_t;
     44
     45#define PRIua  "zu"          /**< Format for atomic_count_t. */
    4446
    4547typedef struct atomic {
Note: See TracChangeset for help on using the changeset viewer.