All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/20] KVM: arm/arm64: Optimize arch timer register handling
@ 2017-09-23  0:41 ` Christoffer Dall
  0 siblings, 0 replies; 110+ messages in thread
From: Christoffer Dall @ 2017-09-23  0:41 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel
  Cc: kvm, Marc Zyngier, Will Deacon, Catalin Marinas, Christoffer Dall

We currently spend a measurable amount of time on each entry/exit to the
guest dealing with arch timer registers, even when the timer is not
pending and not doing anything (on certain architectures).

We can do much better by moving the arch timer save/restore to the
vcpu_load and vcpu_put functions, but this means that if we don't read
back the timer state on every exit from the guest, then we have to be
able to start taking timer interrupts for the virtual timer in KVM and
handle that properly.

That has a number of entertaining consequences, such as having to make
sure we don't deadlock between any of the vgic code and interrupt
injection happening from an ISR.  On the plus side, being able to inject
virtual interrupts corresponding to a physical interrupt directly from
an ISR is probably a good system design change overall.

We also have to change the use of the physical vs. virtual counter in
the arm64 kernel to avoid having to save/restore the CNTVOFF_EL2
register on every return to the hypervisor.  The only reason I could
find for using the virtual counter for the kernel on systems with access
to the physical counter is to detect if firmware did not properly clear
CNTVOFF_EL2, and this change has to weighed against the existing check
(assuming I got this right).

On a non-VHE system (AMD Seattle) I have measured this to improve the
world-switch time by about ~100 cycles, but on an EL2 kernel (emulating
VHE behavior on the same hardware) this gives us around ~250 cycles
worth of improvement, and on Thunder-X we seem to get ~650 cycles
improvement, because we can avoid the extra configuration of trapping
accesses to the physical timer from EL1 on every switch.

These patches require that the GICv2 hardware (on such systems) is
properly reported by firmware to have the extra CPU interface page for
the deactivate register.

Code is also available here:
git://git.kernel.org/pub/scm/linux/kernel/git/cdall/linux.git timer-optimize-v3

Based on v4.14-rc1

Some recent numbers I ran on Thunder-X with v4.14-rc1 with/without these
patches (averaged over a few hundred thousand executions) for a base
hypercall cost:

Without this series, avg. cycles: 12,476
Without this series, min. cycles: 12,052

With this series, avg. cycles: 11,782
With this series, min. cycles: 11,435

Improvement ~650 cycles (over 5%)

Changes since v2:
 - Removed RFC tag
 - Included Marc's patch to support EOI/deactivate on broken firmware
   systems
 - Simplified patch 6 (was patch 5 in RFC v2)
 - Clarify percpu_devid interrupts in patch 12 (was patch 11)

Thanks,
  Christoffer

Christoffer Dall (19):
  arm64: Use physical counter for in-kernel reads
  arm64: Use the physical counter when available for read_cycles
  KVM: arm/arm64: Guard kvm_vgic_map_is_active against !vgic_initialized
  KVM: arm/arm64: Support calling vgic_update_irq_pending from irq
    context
  KVM: arm/arm64: Check that system supports split eoi/deactivate
  KVM: arm/arm64: Make timer_arm and timer_disarm helpers more generic
  KVM: arm/arm64: Rename soft timer to bg_timer
  KVM: arm/arm64: Use separate timer for phys timer emulation
  KVM: arm/arm64: Move timer/vgic flush/sync under disabled irq
  KVM: arm/arm64: Move timer save/restore out of the hyp code
  genirq: Document vcpu_info usage for percpu_devid interrupts
  KVM: arm/arm64: Set VCPU affinity for virt timer irq
  KVM: arm/arm64: Avoid timer save/restore in vcpu entry/exit
  KVM: arm/arm64: Support EL1 phys timer register access in set/get reg
  KVM: arm/arm64: Use kvm_arm_timer_set/get_reg for guest register traps
  KVM: arm/arm64: Move phys_timer_emulate function
  KVM: arm/arm64: Avoid phys timer emulation in vcpu entry/exit
  KVM: arm/arm64: Get rid of kvm_timer_flush_hwstate
  KVM: arm/arm64: Rework kvm_timer_should_fire

Marc Zyngier (1):
  irqchip/gic: Deal with broken firmware exposing only 4kB of GICv2 CPU
    interface

 Documentation/admin-guide/kernel-parameters.txt |   7 +
 arch/arm/include/asm/kvm_asm.h                  |   2 +
 arch/arm/include/asm/kvm_hyp.h                  |   4 +-
 arch/arm/include/uapi/asm/kvm.h                 |   6 +
 arch/arm/kvm/hyp/switch.c                       |   7 +-
 arch/arm64/include/asm/arch_timer.h             |  18 +-
 arch/arm64/include/asm/kvm_asm.h                |   2 +
 arch/arm64/include/asm/kvm_hyp.h                |   4 +-
 arch/arm64/include/asm/timex.h                  |   2 +-
 arch/arm64/include/uapi/asm/kvm.h               |   6 +
 arch/arm64/kvm/hyp/switch.c                     |   6 +-
 arch/arm64/kvm/sys_regs.c                       |  41 +--
 drivers/clocksource/arm_arch_timer.c            |  33 +-
 drivers/irqchip/irq-gic.c                       |  74 +++-
 include/kvm/arm_arch_timer.h                    |  19 +-
 kernel/irq/manage.c                             |   3 +-
 virt/kvm/arm/arch_timer.c                       | 446 ++++++++++++++++--------
 virt/kvm/arm/arm.c                              |  45 ++-
 virt/kvm/arm/hyp/timer-sr.c                     |  74 ++--
 virt/kvm/arm/vgic/vgic-its.c                    |  17 +-
 virt/kvm/arm/vgic/vgic-mmio-v2.c                |  22 +-
 virt/kvm/arm/vgic/vgic-mmio-v3.c                |  17 +-
 virt/kvm/arm/vgic/vgic-mmio.c                   |  44 ++-
 virt/kvm/arm/vgic/vgic-v2.c                     |   5 +-
 virt/kvm/arm/vgic/vgic-v3.c                     |  12 +-
 virt/kvm/arm/vgic/vgic.c                        |  63 ++--
 virt/kvm/arm/vgic/vgic.h                        |   3 +-
 27 files changed, 648 insertions(+), 334 deletions(-)

-- 
2.9.0

^ permalink raw reply	[flat|nested] 110+ messages in thread

end of thread, other threads:[~2017-10-19  8:44 UTC | newest]

Thread overview: 110+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-23  0:41 [PATCH v3 00/20] KVM: arm/arm64: Optimize arch timer register handling Christoffer Dall
2017-09-23  0:41 ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 01/20] irqchip/gic: Deal with broken firmware exposing only 4kB of GICv2 CPU interface Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 02/20] arm64: Use physical counter for in-kernel reads Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 16:10   ` Marc Zyngier
2017-10-09 16:10     ` Marc Zyngier
2017-10-17 15:33   ` Will Deacon
2017-10-17 15:33     ` Will Deacon
2017-10-18 10:00     ` Christoffer Dall
2017-10-18 10:00       ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 03/20] arm64: Use the physical counter when available for read_cycles Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 16:21   ` Marc Zyngier
2017-10-09 16:21     ` Marc Zyngier
2017-10-18 11:34     ` Christoffer Dall
2017-10-18 11:34       ` Christoffer Dall
2017-10-18 15:52       ` Marc Zyngier
2017-10-18 15:52         ` Marc Zyngier
2017-09-23  0:41 ` [PATCH v3 04/20] KVM: arm/arm64: Guard kvm_vgic_map_is_active against !vgic_initialized Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 16:22   ` Marc Zyngier
2017-10-09 16:22     ` Marc Zyngier
2017-09-23  0:41 ` [PATCH v3 05/20] KVM: arm/arm64: Support calling vgic_update_irq_pending from irq context Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 16:37   ` Marc Zyngier
2017-10-09 16:37     ` Marc Zyngier
2017-10-18 11:54     ` Christoffer Dall
2017-10-18 11:54       ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 06/20] KVM: arm/arm64: Check that system supports split eoi/deactivate Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 16:47   ` Marc Zyngier
2017-10-09 16:47     ` Marc Zyngier
2017-10-18 13:41     ` Christoffer Dall
2017-10-18 13:41       ` Christoffer Dall
2017-10-18 16:03       ` Marc Zyngier
2017-10-18 16:03         ` Marc Zyngier
2017-10-18 19:16         ` Christoffer Dall
2017-10-18 19:16           ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 07/20] KVM: arm/arm64: Make timer_arm and timer_disarm helpers more generic Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:05   ` Marc Zyngier
2017-10-09 17:05     ` Marc Zyngier
2017-10-18 16:47     ` Christoffer Dall
2017-10-18 16:47       ` Christoffer Dall
2017-10-18 16:53       ` Marc Zyngier
2017-10-18 16:53         ` Marc Zyngier
2017-09-23  0:41 ` [PATCH v3 08/20] KVM: arm/arm64: Rename soft timer to bg_timer Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:06   ` Marc Zyngier
2017-10-09 17:06     ` Marc Zyngier
2017-09-23  0:41 ` [PATCH v3 09/20] KVM: arm/arm64: Use separate timer for phys timer emulation Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:23   ` Marc Zyngier
2017-10-09 17:23     ` Marc Zyngier
2017-10-19  7:38     ` Christoffer Dall
2017-10-19  7:38       ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 10/20] KVM: arm/arm64: Move timer/vgic flush/sync under disabled irq Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:34   ` Marc Zyngier
2017-10-09 17:34     ` Marc Zyngier
2017-09-23  0:41 ` [PATCH v3 11/20] KVM: arm/arm64: Move timer save/restore out of the hyp code Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:47   ` Marc Zyngier
2017-10-09 17:47     ` Marc Zyngier
2017-10-19  7:46     ` Christoffer Dall
2017-10-19  7:46       ` Christoffer Dall
2017-09-23  0:41 ` [PATCH v3 12/20] genirq: Document vcpu_info usage for percpu_devid interrupts Christoffer Dall
2017-09-23  0:41   ` Christoffer Dall
2017-10-09 17:48   ` Marc Zyngier
2017-10-09 17:48     ` Marc Zyngier
2017-09-23  0:42 ` [PATCH v3 13/20] KVM: arm/arm64: Set VCPU affinity for virt timer irq Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-09 17:52   ` Marc Zyngier
2017-10-09 17:52     ` Marc Zyngier
2017-09-23  0:42 ` [PATCH v3 14/20] KVM: arm/arm64: Avoid timer save/restore in vcpu entry/exit Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  8:47   ` Marc Zyngier
2017-10-10  8:47     ` Marc Zyngier
2017-10-19  8:15     ` Christoffer Dall
2017-10-19  8:15       ` Christoffer Dall
2017-09-23  0:42 ` [PATCH v3 15/20] KVM: arm/arm64: Support EL1 phys timer register access in set/get reg Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:10   ` Marc Zyngier
2017-10-10  9:10     ` Marc Zyngier
2017-10-19  8:32     ` Christoffer Dall
2017-10-19  8:32       ` Christoffer Dall
2017-09-23  0:42 ` [PATCH v3 16/20] KVM: arm/arm64: Use kvm_arm_timer_set/get_reg for guest register traps Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:12   ` Marc Zyngier
2017-10-10  9:12     ` Marc Zyngier
2017-09-23  0:42 ` [PATCH v3 17/20] KVM: arm/arm64: Move phys_timer_emulate function Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:21   ` Marc Zyngier
2017-10-10  9:21     ` Marc Zyngier
2017-09-23  0:42 ` [PATCH v3 18/20] KVM: arm/arm64: Avoid phys timer emulation in vcpu entry/exit Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:45   ` Marc Zyngier
2017-10-10  9:45     ` Marc Zyngier
2017-10-19  8:44     ` Christoffer Dall
2017-10-19  8:44       ` Christoffer Dall
2017-09-23  0:42 ` [PATCH v3 19/20] KVM: arm/arm64: Get rid of kvm_timer_flush_hwstate Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:46   ` Marc Zyngier
2017-10-10  9:46     ` Marc Zyngier
2017-09-23  0:42 ` [PATCH v3 20/20] KVM: arm/arm64: Rework kvm_timer_should_fire Christoffer Dall
2017-09-23  0:42   ` Christoffer Dall
2017-10-10  9:59   ` Marc Zyngier
2017-10-10  9:59     ` Marc Zyngier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.