Skip to content

Commit bb81f23

Browse files
committed
hw/intc/loongarch_ipi: Use alternative implemation for cpu_by_arch_id
There is arch_id and CPUState pointer in IPICore object. With function cpu_by_arch_id() it can be implemented by parsing IPICore array inside, rather than possible_cpus array. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
1 parent 999b112 commit bb81f23

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

hw/intc/loongarch_ipi.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,29 @@ static AddressSpace *get_iocsr_as(CPUState *cpu)
1717
return LOONGARCH_CPU(cpu)->env.address_space_iocsr;
1818
}
1919

20-
static int archid_cmp(const void *a, const void *b)
20+
static int loongarch_ipi_cmp(const void *a, const void *b)
2121
{
22-
CPUArchId *archid_a = (CPUArchId *)a;
23-
CPUArchId *archid_b = (CPUArchId *)b;
22+
IPICore *ipi_a = (IPICore *)a;
23+
IPICore *ipi_b = (IPICore *)b;
2424

25-
return archid_a->arch_id - archid_b->arch_id;
26-
}
27-
28-
static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id)
29-
{
30-
CPUArchId apic_id, *found_cpu;
31-
32-
apic_id.arch_id = id;
33-
found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus,
34-
ms->possible_cpus->len,
35-
sizeof(*ms->possible_cpus->cpus),
36-
archid_cmp);
37-
38-
return found_cpu;
25+
return ipi_a->arch_id - ipi_b->arch_id;
3926
}
4027

4128
static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics,
4229
int64_t arch_id, int *index, CPUState **pcs)
4330
{
44-
MachineState *machine = MACHINE(qdev_get_machine());
45-
CPUArchId *archid;
46-
CPUState *cs;
31+
IPICore ipi, *found;
4732

48-
archid = find_cpu_by_archid(machine, arch_id);
49-
if (archid && archid->cpu) {
50-
cs = archid->cpu;
33+
ipi.arch_id = arch_id;
34+
found = bsearch(&ipi, lics->cpu, lics->num_cpu, sizeof(IPICore),
35+
loongarch_ipi_cmp);
36+
if (found && found->cpu) {
5137
if (index) {
52-
*index = cs->cpu_index;
38+
*index = found - lics->cpu;
5339
}
5440

5541
if (pcs) {
56-
*pcs = cs;
42+
*pcs = found->cpu;
5743
}
5844

5945
return MEMTX_OK;

0 commit comments

Comments
 (0)