spapr: consolidate the VCPU id numbering logic in a single place
commit5d0fb1508e2d279da74ef4a103e8def9b52c6304
authorGreg Kurz <groug@kaod.org>
Wed, 14 Feb 2018 19:40:53 +0000 (14 20:40 +0100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Fri, 16 Feb 2018 01:14:26 +0000 (16 12:14 +1100)
treec4345efc38ba0d49340bd97d65e7e4507af2899e
parent14bb4486c819ea797a151b3e0fe53d6f5c7b3fc5
spapr: consolidate the VCPU id numbering logic in a single place

Several places in the code need to calculate a VCPU id:

    (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads
    (core_id / smp_threads) * spapr->vsmt (1 user)
    index * spapr->vsmt (2 users)

or guess that the VCPU id of a given VCPU is the first thread of a virtual
core:

    index % spapr->vsmt != 0

Even if the numbering logic isn't that complex, it is rather fragile to
have these assumptions open-coded in several places. FWIW this was
proved with recent issues related to VSMT.

This patch moves the VCPU id formula to a single function to be called
everywhere the code needs to compute one. It also adds an helper to
guess if a VCPU is the first thread of a VCORE.

Signed-off-by: Greg Kurz <groug@kaod.org>
[dwg: Rename spapr_is_vcore() to spapr_is_thread0_in_vcore() for clarity]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
hw/ppc/spapr.c