android_kernel_xiaomi_sm8350/arch/powerpc/sysdev
Paul Mackerras 371fefd6f2 KVM: PPC: Allow book3s_hv guests to use SMT processor modes
This lifts the restriction that book3s_hv guests can only run one
hardware thread per core, and allows them to use up to 4 threads
per core on POWER7.  The host still has to run single-threaded.

This capability is advertised to qemu through a new KVM_CAP_PPC_SMT
capability.  The return value of the ioctl querying this capability
is the number of vcpus per virtual CPU core (vcore), currently 4.

To use this, the host kernel should be booted with all threads
active, and then all the secondary threads should be offlined.
This will put the secondary threads into nap mode.  KVM will then
wake them from nap mode and use them for running guest code (while
they are still offline).  To wake the secondary threads, we send
them an IPI using a new xics_wake_cpu() function, implemented in
arch/powerpc/sysdev/xics/icp-native.c.  In other words, at this stage
we assume that the platform has a XICS interrupt controller and
we are using icp-native.c to drive it.  Since the woken thread will
need to acknowledge and clear the IPI, we also export the base
physical address of the XICS registers using kvmppc_set_xics_phys()
for use in the low-level KVM book3s code.

When a vcpu is created, it is assigned to a virtual CPU core.
The vcore number is obtained by dividing the vcpu number by the
number of threads per core in the host.  This number is exported
to userspace via the KVM_CAP_PPC_SMT capability.  If qemu wishes
to run the guest in single-threaded mode, it should make all vcpu
numbers be multiples of the number of threads per core.

We distinguish three states of a vcpu: runnable (i.e., ready to execute
the guest), blocked (that is, idle), and busy in host.  We currently
implement a policy that the vcore can run only when all its threads
are runnable or blocked.  This way, if a vcpu needs to execute elsewhere
in the kernel or in qemu, it can do so without being starved of CPU
by the other vcpus.

When a vcore starts to run, it executes in the context of one of the
vcpu threads.  The other vcpu threads all go to sleep and stay asleep
until something happens requiring the vcpu thread to return to qemu,
or to wake up to run the vcore (this can happen when another vcpu
thread goes from busy in host state to blocked).

It can happen that a vcpu goes from blocked to runnable state (e.g.
because of an interrupt), and the vcore it belongs to is already
running.  In that case it can start to run immediately as long as
the none of the vcpus in the vcore have started to exit the guest.
We send the next free thread in the vcore an IPI to get it to start
to execute the guest.  It synchronizes with the other threads via
the vcore->entry_exit_count field to make sure that it doesn't go
into the guest if the other vcpus are exiting by the time that it
is ready to actually enter the guest.

Note that there is no fixed relationship between the hardware thread
number and the vcpu number.  Hardware threads are assigned to vcpus
as they become runnable, so we will always use the lower-numbered
hardware threads in preference to higher-numbered threads if not all
the vcpus in the vcore are runnable, regardless of which vcpus are
runnable.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-07-12 13:16:57 +03:00
..
bestcomm Fix common misspellings 2011-03-31 11:26:23 -03:00
qe_lib powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
xics KVM: PPC: Allow book3s_hv guests to use SMT processor modes 2011-07-12 13:16:57 +03:00
6xx-suspend.S
axonram.c powerpc: Remove ioremap_flags 2011-05-19 14:30:43 +10:00
cpm1.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
cpm2_pic.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
cpm2_pic.h
cpm2.c
cpm_common.c
dart_iommu.c
dart.h
dcr-low.S
dcr.c
fsl_85xx_cache_ctlr.h
fsl_85xx_cache_sram.c powerpc: Remove ioremap_flags 2011-05-19 14:30:43 +10:00
fsl_85xx_l2ctlr.c Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc 2011-03-18 06:31:43 -07:00
fsl_gtm.c
fsl_lbc.c powerpc/85xx: fix race bug of calling request_irq after enable elbc interrupts 2011-06-03 00:09:09 -05:00
fsl_msi.c Merge branch 'merge' into next 2011-05-19 17:00:06 +10:00
fsl_msi.h
fsl_pci.c powerpc/85xx: Don't add disabled PCIe devices 2011-04-12 06:29:21 -05:00
fsl_pci.h powerpc/fsl_pci: Add support for FSL PCIe controllers v2.x 2011-03-15 09:29:56 -05:00
fsl_pmc.c dt/powerpc: Eliminate users of of_platform_{,un}register_driver 2011-02-28 01:36:39 -07:00
fsl_rio.c powerpc/e500: fix breakage with fsl_rio_mcheck_exception 2011-06-22 06:15:16 -05:00
fsl_soc.c
fsl_soc.h
grackle.c
i8259.c powerpc: Remove i8259 irq_host_ops->unmap 2011-05-19 15:31:41 +10:00
indirect_pci.c Fix common misspellings 2011-03-31 11:26:23 -03:00
ipic.c Merge remote branch 'origin/master' into merge 2011-05-20 15:36:52 +10:00
ipic.h
Kconfig powerpc/4xx: Adding PCIe MSI support 2011-05-26 15:00:37 +10:00
Makefile powerpc/4xx: Adding PCIe MSI support 2011-05-26 15:00:37 +10:00
micropatch.c
mmio_nvram.c powerpc/nvram: Search for nvram using compatible 2011-04-20 17:01:20 +10:00
mpc5xxx_clocks.c
mpc8xx_pic.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
mpc8xx_pic.h
mpc8xxx_gpio.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
mpic_msi.c
mpic_pasemi_msi.c powerpc: Convert to new irq_* function names 2011-03-29 14:48:12 +02:00
mpic_u3msi.c powerpc: Convert to new irq_* function names 2011-03-29 14:48:12 +02:00
mpic.c arch/powerpc: use printk_ratelimited instead of printk_ratelimit 2011-06-29 15:31:01 +10:00
mpic.h powerpc: mpic irq_data conversion. 2011-03-10 11:03:56 +11:00
msi_bitmap.c
mv64x60_dev.c powerpc/mv64x60: Suspected typo in assignment 2011-03-02 16:50:05 +11:00
mv64x60_pci.c
mv64x60_pic.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
mv64x60_udbg.c
mv64x60.h
of_rtc.c
pmi.c dt/powerpc: Eliminate users of of_platform_{,un}register_driver 2011-02-28 01:36:39 -07:00
ppc4xx_cpm.c
ppc4xx_gpio.c
ppc4xx_msi.c powerpc/4xx: Adding PCIe MSI support 2011-05-26 15:00:37 +10:00
ppc4xx_pci.c
ppc4xx_pci.h Fix common misspellings 2011-03-31 11:26:23 -03:00
ppc4xx_soc.c
rtc_cmos_setup.c
scom.c powerpc: Add SCOM infrastructure 2011-04-20 17:01:19 +10:00
simple_gpio.c
simple_gpio.h
tsi108_dev.c
tsi108_pci.c powerpc: Convert to new irq_* function names 2011-03-29 14:48:12 +02:00
uic.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
xilinx_intc.c powerpc/irq: Stop exporting irq_map 2011-05-04 15:02:15 +10:00
xilinx_pci.c