Skip to content

Commit 647797f

Browse files
lifeixacrnsi
authored andcommitted
hv: ptdev: refine ptdev active flag
Since spinlock ptdev_lock is used to protect ptdev entry, there's no need to use atomic operation to protect ptdev active flag in split of it's wrong used to protect ptdev entry. And refine active flag data type to bool. Tracked-On: #1842 Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent cb8bbf7 commit 647797f

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

hypervisor/common/ptdev.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@
88
#include <softirq.h>
99
#include <ptdev.h>
1010
#include <irq.h>
11-
#include <atomic.h>
1211
#include <logmsg.h>
1312

1413
#define PTIRQ_BITMAP_ARRAY_SIZE INT_DIV_ROUNDUP(CONFIG_MAX_PT_IRQ_ENTRIES, 64U)
1514
struct ptirq_remapping_info ptirq_entries[CONFIG_MAX_PT_IRQ_ENTRIES];
1615
static uint64_t ptirq_entry_bitmaps[PTIRQ_BITMAP_ARRAY_SIZE];
1716
spinlock_t ptdev_lock;
1817

19-
bool is_entry_active(const struct ptirq_remapping_info *entry)
20-
{
21-
return atomic_load32(&entry->active) == ACTIVE_FLAG;
22-
}
23-
2418
static inline uint16_t ptirq_alloc_entry_id(void)
2519
{
2620
uint16_t id = (uint16_t)ffz64_ex(ptirq_entry_bitmaps, CONFIG_MAX_PT_IRQ_ENTRIES);
@@ -100,7 +94,7 @@ struct ptirq_remapping_info *ptirq_alloc_entry(struct acrn_vm *vm, uint32_t intr
10094

10195
initialize_timer(&entry->intr_delay_timer, ptirq_intr_delay_callback, entry, 0UL, 0, 0UL);
10296

103-
atomic_clear32(&entry->active, ACTIVE_FLAG);
97+
entry->active = false;
10498
} else {
10599
pr_err("Alloc ptdev irq entry failed");
106100
}
@@ -167,15 +161,15 @@ int32_t ptirq_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_i
167161
pr_err("request irq failed, please check!, phys-irq=%d", phys_irq);
168162
} else {
169163
entry->allocated_pirq = (uint32_t)retval;
170-
atomic_set32(&entry->active, ACTIVE_FLAG);
164+
entry->active = true;
171165
}
172166

173167
return retval;
174168
}
175169

176170
void ptirq_deactivate_entry(struct ptirq_remapping_info *entry)
177171
{
178-
atomic_clear32(&entry->active, ACTIVE_FLAG);
172+
entry->active = false;
179173
free_irq(entry->allocated_pirq);
180174
}
181175

hypervisor/include/common/ptdev.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <pci.h>
1212
#include <timer.h>
1313

14-
#define ACTIVE_FLAG 0x1U /* any non zero should be okay */
15-
1614
#define PTDEV_INTR_MSI (1U << 0U)
1715
#define PTDEV_INTR_INTX (1U << 1U)
1816

@@ -133,7 +131,7 @@ struct ptirq_remapping_info {
133131
union source_id phys_sid;
134132
union source_id virt_sid;
135133
struct acrn_vm *vm;
136-
uint32_t active; /* 1=active, 0=inactive and to free*/
134+
bool active; /* true=active, false=inactive*/
137135
uint32_t allocated_pirq;
138136
uint32_t polarity; /* 0=active high, 1=active low*/
139137
struct list_head softirq_node;
@@ -144,10 +142,14 @@ struct ptirq_remapping_info {
144142
ptirq_arch_release_fn_t release_cb;
145143
};
146144

145+
static inline bool is_entry_active(const struct ptirq_remapping_info *entry)
146+
{
147+
return entry->active;
148+
}
149+
147150
extern struct ptirq_remapping_info ptirq_entries[CONFIG_MAX_PT_IRQ_ENTRIES];
148151
extern spinlock_t ptdev_lock;
149152

150-
bool is_entry_active(const struct ptirq_remapping_info *entry);
151153
void ptirq_softirq(uint16_t pcpu_id);
152154
void ptdev_init(void);
153155
void ptdev_release_all_entries(const struct acrn_vm *vm);

0 commit comments

Comments
 (0)