Skip to content

Commit fadaf14

Browse files
lifeixlijinxia
authored andcommitted
hv: refine atomic_xadd
1. rename atomic_xadd_int to atomic_xadd, add atomic_xadd64. 2. add atomic_add/sbu64_return, atomic_inc/dec64_return. Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent bd3f3b0 commit fadaf14

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int create_vcpu(int cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
8080
* vcpu->vcpu_id = vm->hw.created_vcpus;
8181
* vm->hw.created_vcpus++;
8282
*/
83-
vcpu->vcpu_id = atomic_xadd_int(&vm->hw.created_vcpus, 1);
83+
vcpu->vcpu_id = atomic_xadd(&vm->hw.created_vcpus, 1);
8484
/* vm->hw.vcpu_array[vcpu->vcpu_id] = vcpu; */
8585
atomic_store_rel_64(
8686
(unsigned long *)&vm->hw.vcpu_array[vcpu->vcpu_id],

hypervisor/debug/logmsg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DEFINE_CPU_DATA(struct shared_buf *, earlylog_sbuf);
5252

5353
struct logmsg {
5454
uint32_t flags;
55-
unsigned int seq;
55+
int seq;
5656
spinlock_t lock;
5757
};
5858

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct vm_attr {
4747
struct vm_hw_info {
4848
int num_vcpus; /* Number of total virtual cores */
4949
int exp_num_vcpus; /* Number of real expected virtual cores */
50-
uint32_t created_vcpus; /* Number of created vcpus */
50+
int created_vcpus; /* Number of created vcpus */
5151
struct vcpu **vcpu_array; /* vcpu array of this VM */
5252
uint64_t gpa_lowtop; /* top lowmem gpa of this VM */
5353
};

hypervisor/include/lib/atomic.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,29 @@ static inline int atomic_cmpxchg_int(unsigned int *p,
226226
#define atomic_load_acq_64 atomic_load_acq_long
227227
#define atomic_store_rel_64 atomic_store_rel_long
228228

229-
/*
230-
* #define atomic_xadd_int(P, V) \
231-
* (return (*(unsigned long *)(P)); *(unsigned long *)(P) += (V);)
232-
*/
233-
static inline int atomic_xadd_int(unsigned int *p, unsigned int v)
234-
{
235-
__asm __volatile(BUS_LOCK "xaddl %0,%1"
236-
: "+r" (v), "+m" (*p)
237-
:
238-
: "cc", "memory");
239-
return v;
240-
}
241-
242-
static inline int atomic_add_return(int v, unsigned int *p)
243-
{
244-
return v + atomic_xadd_int(p, v);
245-
}
246-
247-
static inline int atomic_sub_return(int v, unsigned int *p)
248-
{
249-
return atomic_xadd_int(p, -v) - v;
250-
}
251-
252-
#define atomic_inc_return(v) atomic_add_return(1, (v))
253-
#define atomic_dec_return(v) atomic_sub_return(1, (v))
229+
#define build_atomic_xadd(name, size, type, ptr, v) \
230+
static inline type name(type *ptr, type v) \
231+
{ \
232+
asm volatile(BUS_LOCK "xadd" size " %0,%1" \
233+
: "+r" (v), "+m" (*p) \
234+
: \
235+
: "cc", "memory"); \
236+
return v; \
237+
}
238+
build_atomic_xadd(atomic_xadd, "l", int, p, v)
239+
build_atomic_xadd(atomic_xadd64, "q", long, p, v)
240+
241+
#define atomic_add_return(p, v) ( atomic_xadd(p, v) + v )
242+
#define atomic_sub_return(p, v) ( atomic_xadd(p, -v) - v )
243+
244+
#define atomic_inc_return(v) atomic_add_return((v), 1)
245+
#define atomic_dec_return(v) atomic_sub_return((v), 1)
246+
247+
#define atomic_add64_return(p, v) ( atomic_xadd64(p, v) + v )
248+
#define atomic_sub64_return(p, v) ( atomic_xadd64(p, -v) - v )
249+
250+
#define atomic_inc64_return(v) atomic_add64_return((v), 1)
251+
#define atomic_dec64_return(v) atomic_sub64_return((v), 1)
254252

255253
static inline int
256254
atomic_cmpset_long(unsigned long *dst, unsigned long expect, unsigned long src)

0 commit comments

Comments
 (0)