mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-09 12:08:30 +00:00
hv: refine bitops
Rename bitmap_clr to bitmap_clear Rename bitmap_isset to bitmap_test Remove bitmap_setof Signed-off-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
95c289b15f
commit
57d0bf3b7c
@ -685,7 +685,7 @@ void cpu_dead(uint32_t logical_id)
|
|||||||
/* Set state to show CPU is halted */
|
/* Set state to show CPU is halted */
|
||||||
cpu_set_current_state(logical_id, CPU_STATE_HALTED);
|
cpu_set_current_state(logical_id, CPU_STATE_HALTED);
|
||||||
|
|
||||||
bitmap_clr(get_cpu_id(), &pcpu_active_bitmap);
|
bitmap_clear(get_cpu_id(), &pcpu_active_bitmap);
|
||||||
|
|
||||||
/* Halt the CPU */
|
/* Halt the CPU */
|
||||||
do {
|
do {
|
||||||
|
@ -98,7 +98,7 @@ inline uint64_t vcpumask2pcpumask(struct vm *vm, uint64_t vdmask)
|
|||||||
struct vcpu *vcpu;
|
struct vcpu *vcpu;
|
||||||
|
|
||||||
while ((vcpu_id = bitmap_ffs(&vdmask)) >= 0) {
|
while ((vcpu_id = bitmap_ffs(&vdmask)) >= 0) {
|
||||||
bitmap_clr(vcpu_id, &vdmask);
|
bitmap_clear(vcpu_id, &vdmask);
|
||||||
vcpu = vcpu_from_vid(vm, vcpu_id);
|
vcpu = vcpu_from_vid(vm, vcpu_id);
|
||||||
ASSERT(vcpu, "vcpu_from_vid failed");
|
ASSERT(vcpu, "vcpu_from_vid failed");
|
||||||
bitmap_set(vcpu->pcpu_id, &dmask);
|
bitmap_set(vcpu->pcpu_id, &dmask);
|
||||||
|
@ -849,7 +849,7 @@ vlapic_calcdest(struct vm *vm, uint64_t *dmask, uint32_t dest,
|
|||||||
*dmask = 0;
|
*dmask = 0;
|
||||||
amask = vm_active_cpus(vm);
|
amask = vm_active_cpus(vm);
|
||||||
while ((vcpu_id = bitmap_ffs(&amask)) >= 0) {
|
while ((vcpu_id = bitmap_ffs(&amask)) >= 0) {
|
||||||
bitmap_clr(vcpu_id, &amask);
|
bitmap_clear(vcpu_id, &amask);
|
||||||
|
|
||||||
vlapic = vm_lapic_from_vcpu_id(vm, vcpu_id);
|
vlapic = vm_lapic_from_vcpu_id(vm, vcpu_id);
|
||||||
dfr = vlapic->apic_page->dfr;
|
dfr = vlapic->apic_page->dfr;
|
||||||
@ -953,7 +953,7 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bool phys;
|
bool phys;
|
||||||
uint64_t dmask;
|
uint64_t dmask = 0;
|
||||||
uint64_t icrval;
|
uint64_t icrval;
|
||||||
uint32_t dest, vec, mode;
|
uint32_t dest, vec, mode;
|
||||||
struct lapic *lapic;
|
struct lapic *lapic;
|
||||||
@ -984,22 +984,21 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic)
|
|||||||
vlapic_calcdest(vlapic->vm, &dmask, dest, phys, false);
|
vlapic_calcdest(vlapic->vm, &dmask, dest, phys, false);
|
||||||
break;
|
break;
|
||||||
case APIC_DEST_SELF:
|
case APIC_DEST_SELF:
|
||||||
bitmap_setof(vlapic->vcpu->vcpu_id, &dmask);
|
bitmap_set(vlapic->vcpu->vcpu_id, &dmask);
|
||||||
break;
|
break;
|
||||||
case APIC_DEST_ALLISELF:
|
case APIC_DEST_ALLISELF:
|
||||||
dmask = vm_active_cpus(vlapic->vm);
|
dmask = vm_active_cpus(vlapic->vm);
|
||||||
break;
|
break;
|
||||||
case APIC_DEST_ALLESELF:
|
case APIC_DEST_ALLESELF:
|
||||||
dmask = vm_active_cpus(vlapic->vm);
|
dmask = vm_active_cpus(vlapic->vm);
|
||||||
bitmap_clr(vlapic->vcpu->vcpu_id, &dmask);
|
bitmap_clear(vlapic->vcpu->vcpu_id, &dmask);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dmask = 0; /* satisfy gcc */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((i = bitmap_ffs(&dmask)) >= 0) {
|
while ((i = bitmap_ffs(&dmask)) >= 0) {
|
||||||
bitmap_clr(i, &dmask);
|
bitmap_clear(i, &dmask);
|
||||||
target_vcpu = vcpu_from_vid(vlapic->vm, i);
|
target_vcpu = vcpu_from_vid(vlapic->vm, i);
|
||||||
if (target_vcpu == NULL)
|
if (target_vcpu == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1523,7 +1522,7 @@ vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,
|
|||||||
vlapic_calcdest(vm, &dmask, dest, phys, lowprio);
|
vlapic_calcdest(vm, &dmask, dest, phys, lowprio);
|
||||||
|
|
||||||
while ((vcpu_id = bitmap_ffs(&dmask)) >= 0) {
|
while ((vcpu_id = bitmap_ffs(&dmask)) >= 0) {
|
||||||
bitmap_clr(vcpu_id, &dmask);
|
bitmap_clear(vcpu_id, &dmask);
|
||||||
target_vcpu = vcpu_from_vid(vm, vcpu_id);
|
target_vcpu = vcpu_from_vid(vm, vcpu_id);
|
||||||
if (target_vcpu == NULL)
|
if (target_vcpu == NULL)
|
||||||
return;
|
return;
|
||||||
@ -1657,7 +1656,7 @@ int
|
|||||||
vlapic_set_local_intr(struct vm *vm, int cpu_id, int vector)
|
vlapic_set_local_intr(struct vm *vm, int cpu_id, int vector)
|
||||||
{
|
{
|
||||||
struct vlapic *vlapic;
|
struct vlapic *vlapic;
|
||||||
uint64_t dmask;
|
uint64_t dmask = 0;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (cpu_id < -1 || cpu_id >= phy_cpu_num)
|
if (cpu_id < -1 || cpu_id >= phy_cpu_num)
|
||||||
@ -1666,10 +1665,10 @@ vlapic_set_local_intr(struct vm *vm, int cpu_id, int vector)
|
|||||||
if (cpu_id == -1)
|
if (cpu_id == -1)
|
||||||
dmask = vm_active_cpus(vm);
|
dmask = vm_active_cpus(vm);
|
||||||
else
|
else
|
||||||
bitmap_setof(cpu_id, &dmask);
|
bitmap_set(cpu_id, &dmask);
|
||||||
error = 0;
|
error = 0;
|
||||||
while ((cpu_id = bitmap_ffs(&dmask)) >= 0) {
|
while ((cpu_id = bitmap_ffs(&dmask)) >= 0) {
|
||||||
bitmap_clr(cpu_id, &dmask);
|
bitmap_clear(cpu_id, &dmask);
|
||||||
vlapic = vm_lapic_from_vcpu_id(vm, cpu_id);
|
vlapic = vm_lapic_from_vcpu_id(vm, cpu_id);
|
||||||
error = vlapic_trigger_lvt(vlapic, vector);
|
error = vlapic_trigger_lvt(vlapic, vector);
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -233,7 +233,7 @@ int shutdown_vm(struct vm *vm)
|
|||||||
if (vm->iommu_domain)
|
if (vm->iommu_domain)
|
||||||
destroy_iommu_domain(vm->iommu_domain);
|
destroy_iommu_domain(vm->iommu_domain);
|
||||||
|
|
||||||
bitmap_clr(vm->attr.id, &vmid_bitmap);
|
bitmap_clear(vm->attr.id, &vmid_bitmap);
|
||||||
|
|
||||||
if (vm->vpic)
|
if (vm->vpic)
|
||||||
vpic_cleanup(vm);
|
vpic_cleanup(vm);
|
||||||
|
@ -37,7 +37,7 @@ static DEFINE_CPU_DATA(uint64_t, softirq_pending);
|
|||||||
|
|
||||||
void disable_softirq(int cpu_id)
|
void disable_softirq(int cpu_id)
|
||||||
{
|
{
|
||||||
bitmap_clr(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, cpu_id));
|
bitmap_clear(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, cpu_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable_softirq(int cpu_id)
|
void enable_softirq(int cpu_id)
|
||||||
@ -96,7 +96,7 @@ void exec_softirq(void)
|
|||||||
if ((softirq_id < 0) || (softirq_id >= SOFTIRQ_MAX))
|
if ((softirq_id < 0) || (softirq_id >= SOFTIRQ_MAX))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bitmap_clr(softirq_id, bitmap);
|
bitmap_clear(softirq_id, bitmap);
|
||||||
|
|
||||||
switch (softirq_id) {
|
switch (softirq_id) {
|
||||||
case SOFTIRQ_TIMER:
|
case SOFTIRQ_TIMER:
|
||||||
|
@ -87,7 +87,7 @@ void set_pcpu_used(int pcpu_id)
|
|||||||
|
|
||||||
void free_pcpu(int pcpu_id)
|
void free_pcpu(int pcpu_id)
|
||||||
{
|
{
|
||||||
bitmap_clr(pcpu_id, &pcpu_used_bitmap);
|
bitmap_clear(pcpu_id, &pcpu_used_bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_vcpu_to_runqueue(struct vcpu *vcpu)
|
void add_vcpu_to_runqueue(struct vcpu *vcpu)
|
||||||
|
@ -129,51 +129,51 @@ ffsl(long mask)
|
|||||||
static inline void
|
static inline void
|
||||||
bitmap_set(int mask, unsigned long *bits)
|
bitmap_set(int mask, unsigned long *bits)
|
||||||
{
|
{
|
||||||
/* (*bits) |= (1UL<<mask); */
|
/* (*bits) |= (1UL<<mask); */
|
||||||
__asm __volatile(BUS_LOCK "orq %1,%0"
|
asm volatile(BUS_LOCK "orq %1,%0"
|
||||||
: "+m" (*bits)
|
: "+m" (*bits)
|
||||||
: "r" (1UL<<mask)
|
: "r" (1UL<<mask)
|
||||||
: "cc", "memory");
|
: "cc", "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
bitmap_clr(int mask, unsigned long *bits)
|
bitmap_clear(int mask, unsigned long *bits)
|
||||||
{
|
{
|
||||||
/* (*bits) &= ~(1UL<<mask); */
|
/* (*bits) &= ~(1UL<<mask); */
|
||||||
__asm __volatile(BUS_LOCK "andq %1,%0"
|
asm volatile(BUS_LOCK "andq %1,%0"
|
||||||
: "+m" (*bits)
|
: "+m" (*bits)
|
||||||
: "r" (~(1UL<<mask))
|
: "r" (~(1UL<<mask))
|
||||||
: "cc", "memory");
|
: "cc", "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline bool
|
||||||
bitmap_isset(int mask, unsigned long *bits)
|
bitmap_test(int mask, unsigned long *bits)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* return (*bits) & (1UL<<mask);
|
* return !!((*bits) & (1UL<<mask));
|
||||||
*/
|
*/
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
__asm __volatile("btq %2,%1\n\tsbbl %0, %0"
|
asm volatile("btq %2,%1\n\tsbbl %0, %0"
|
||||||
: "=r" (ret), "=m" (*bits)
|
|
||||||
: "r" ((long)(mask) & 0x3f)
|
|
||||||
: "cc", "memory");
|
|
||||||
return (!!ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
bitmap_test_and_set(int mask, unsigned long *bits)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
__asm __volatile(BUS_LOCK "btsq %2,%1\n\tsbbl %0,%0"
|
|
||||||
: "=r" (ret), "=m" (*bits)
|
: "=r" (ret), "=m" (*bits)
|
||||||
: "r" ((long)(mask & 0x3f))
|
: "r" ((long)(mask & 0x3f))
|
||||||
: "cc", "memory");
|
: "cc", "memory");
|
||||||
return (!!ret);
|
return (!!ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline bool
|
||||||
|
bitmap_test_and_set(int mask, unsigned long *bits)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
asm volatile(BUS_LOCK "btsq %2,%1\n\tsbbl %0,%0"
|
||||||
|
: "=r" (ret), "=m" (*bits)
|
||||||
|
: "r" ((long)(mask & 0x3f))
|
||||||
|
: "cc", "memory");
|
||||||
|
return (!!ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
bitmap_test_and_clear(int mask, unsigned long *bits)
|
bitmap_test_and_clear(int mask, unsigned long *bits)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -183,28 +183,13 @@ bitmap_test_and_clear(int mask, unsigned long *bits)
|
|||||||
*/
|
*/
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
__asm __volatile(BUS_LOCK "btrq %2,%1\n\tsbbl %0,%0"
|
asm volatile(BUS_LOCK "btrq %2,%1\n\tsbbl %0,%0"
|
||||||
: "=r" (ret), "=m" (*bits)
|
: "=r" (ret), "=m" (*bits)
|
||||||
: "r" ((long)(mask) & 0x3f)
|
: "r" ((long)(mask & 0x3f))
|
||||||
: "cc", "memory");
|
: "cc", "memory");
|
||||||
return (!!ret);
|
return (!!ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
bitmap_setof(int mask, unsigned long *bits)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* *bits = 0;
|
|
||||||
* (*bits) |= (1UL<<mask);
|
|
||||||
*/
|
|
||||||
|
|
||||||
__asm __volatile(BUS_LOCK "xchgq %1,%0"
|
|
||||||
: "+m" (*bits)
|
|
||||||
: "r" ((1UL<<mask))
|
|
||||||
: "cc", "memory");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
bitmap_ffs(unsigned long *bits)
|
bitmap_ffs(unsigned long *bits)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user