From 336a8883db884aa7cf1a3023e8d5403a0980f713 Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 16 May 2018 16:55:29 +0800 Subject: [PATCH] hv: remove atomic_add/subtract API add atomic_inc(64)/dec(64) API. Signed-off-by: Li, Fei1 Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 2 +- hypervisor/include/lib/atomic.h | 57 ++++++++++---------------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index b12b3f964..73bf3de80 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -225,7 +225,7 @@ int destroy_vcpu(struct vcpu *vcpu) (unsigned long *)&vcpu->vm->hw.vcpu_array[vcpu->vcpu_id], (unsigned long)NULL); - atomic_subtract_int(&vcpu->vm->hw.created_vcpus, 1); + atomic_dec(&vcpu->vm->hw.created_vcpus); vlapic_free(vcpu); free(vcpu->arch_vcpu.vmcs); diff --git a/hypervisor/include/lib/atomic.h b/hypervisor/include/lib/atomic.h index 9a30963ec..2b53dcc18 100644 --- a/hypervisor/include/lib/atomic.h +++ b/hypervisor/include/lib/atomic.h @@ -54,27 +54,26 @@ static inline void atomic_clear_int(unsigned int *p, unsigned int v) : "cc", "memory"); } -/* - * #define atomic_add_int(P, V) (*(unsigned int *)(P) += (V)) - */ -static inline void atomic_add_int(unsigned int *p, unsigned int v) -{ - __asm __volatile(BUS_LOCK "addl %1,%0" - : "+m" (*p) - : "r" (v) - : "cc", "memory"); +#define build_atomic_inc(name, size, type, ptr) \ +static inline void name(type *ptr) \ +{ \ + asm volatile(BUS_LOCK "inc" size " %0" \ + : "=m" (*ptr) \ + : "m" (*ptr)); \ } +build_atomic_inc(atomic_inc, "l", int, p) +build_atomic_inc(atomic_inc64, "q", long, p) -/* - * #define atomic_subtract_int(P, V) (*(unsigned int *)(P) -= (V)) - */ -static inline void atomic_subtract_int(unsigned int *p, unsigned int v) -{ - __asm __volatile(BUS_LOCK "subl %1,%0" - : "+m" (*p) - : "r" (v) - : "cc", "memory"); +#define build_atomic_dec(name, size, type, ptr) \ +static inline void name(type *ptr) \ +{ \ + asm volatile(BUS_LOCK "dec" size " %0" \ + : "=m" (*ptr) \ + : "m" (*ptr)); \ } +build_atomic_dec(atomic_dec, "l", int, p) +build_atomic_dec(atomic_dec64, "q", long, p) + /* * #define atomic_swap_int(P, V) \ @@ -117,28 +116,6 @@ static inline void atomic_clear_long(unsigned long *p, unsigned long v) : "cc", "memory"); } -/* - * #define atomic_add_long(P, V) (*(unsigned long *)(P) += (V)) - */ -static inline void atomic_add_long(unsigned long *p, unsigned long v) -{ - __asm __volatile(BUS_LOCK "addq %1,%0" - : "+m" (*p) - : "r" (v) - : "cc", "memory"); -} - -/* - * #define atomic_subtract_long(P, V) (*(unsigned long *)(P) -= (V)) - */ -static inline void atomic_subtract_long(unsigned long *p, unsigned long v) -{ - __asm __volatile(BUS_LOCK "subq %1,%0" - : "+m" (*p) - : "r" (v) - : "cc", "memory"); -} - /* * #define atomic_swap_long(P, V) \ * (return (*(unsigned long *)(P)); *(unsigned long *)(P) = (V);)