Hi all,
As mentioned in the KVM forum talk from 2019
(https://kvmforum2019.sched.com/event/Tmwf/kvmstat-and-beyond-past-present-and-future-of-performance-monitoring-christian-borntrager-ibm page 10),
there is few event counters for kvm_stat in the arm64 version of kvm when
you compare it to something like the x86 version.
Those counters are used in kvm_stat by kernel/driver developers to
have a rough idea of the impact of their patches on the general performance.
An example would be to make sure a patch don't increase to much the amount
of interruptions. Those patches aim to add more counters to make the use of
kvm_stat more relevant when measuring performance impact.
I am new in working on kernel-related things and I am learning kvm as I go.
Some of the counter I added early (memory_slot_unmaped, stage2_unmap_vm)
no longer seems relevant because while they do interesting things, they
happens in very specific scenarios. Instead of just deleting them, I prefer
to ask weither a little-used counter or no counter is the best.
I can also use some suggestion on how to test those counters as some like
remote_tlb_flush which mostly happen when fixing up a race condition; or
what uncovered event could be worth adding in a future patch set.
Yoan Picchi (7):
KVM: arm64: Add two page mapping counters for kvm_stat
KVM: arm64: Add remote_tlb_flush counter for kvm_stat
KVM: arm64: Add cached_page_invalidated counter for kvm_stat
KVM: arm64: Add flush_all_cache_lines counter for kvm_stat
KVM: arm64: Add memory_slot_unmaped counter for kvm_stat
KVM: arm64: Add stage2_unmap_vm counter for kvm_stat
KVM: arm64: Add irq_inject counter for kvm_stat
arch/arm64/include/asm/kvm_host.h | 8 ++++++++
arch/arm64/kvm/arm.c | 2 ++
arch/arm64/kvm/guest.c | 9 +++++++++
arch/arm64/kvm/mmu.c | 27 ++++++++++++++++++++++++++-
arch/arm64/kvm/vgic/vgic.c | 2 ++
5 files changed, 47 insertions(+), 1 deletion(-)
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter for when a regular page is mapped, and another
for when a huge page is mapped.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/mmu.c | 7 +++++++
3 files changed, 11 insertions(+)
Add a counter for when a regular page is mapped, and another
for when a huge page is mapped.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/mmu.c | 7 +++++++
3 files changed, 11 insertions(+)
This looks too simple, as we don't always map a new regular_page or huge_page here.
We may just relax permission or change mapping size, etc. If we mix these operations,
the stat result seems not very valuable...
Thanks,
Keqian
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:04:48
On Tue, 23 Mar 2021 11:52:38 +0000,
Keqian Zhu [off-list ref] wrote:
Hi Yoan,
On 2021/3/20 0:17, Yoan Picchi wrote:
quoted
Add a counter for when a regular page is mapped, and another
for when a huge page is mapped.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/mmu.c | 7 +++++++
3 files changed, 11 insertions(+)
This looks too simple, as we don't always map a new regular_page or
huge_page here. We may just relax permission or change mapping
size, etc. If we mix these operations, the stat result seems not
very valuable...
I can only agree. There is no such thing as a *huge page*. We have a
whole gamut of block mappings depending on the base granule size, and
we even have concatenation of pages/blocks (not yet implemented at S2,
but there is hope...).
What is this trying to express?
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add some counter for when a dpage get invalidated. The counter isn't
in the function that actually do it though because it doesn't have
either a kvm or vcpu argument, so we would have no way to access the
counters. For this reason, the counter have been added to the calling
functions instead.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 5 ++++-
3 files changed, 6 insertions(+), 1 deletion(-)
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:19:45
On Fri, 19 Mar 2021 16:17:07 +0000,
Yoan Picchi [off-list ref] wrote:
quoted hunk
Add some counter for when a dpage get invalidated. The counter isn't
in the function that actually do it though because it doesn't have
either a kvm or vcpu argument, so we would have no way to access the
counters. For this reason, the counter have been added to the calling
functions instead.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 5 ++++-
3 files changed, 6 insertions(+), 1 deletion(-)
@@ -1166,6 +1168,7 @@ int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)*justlikeatranslationfaultandcleanthecachetothePoC.*/clean_dcache_guest_page(pfn,PAGE_SIZE);+kvm->stat.cached_page_invalidated++;handle_hva_to_gpa(kvm,hva,end,&kvm_set_spte_handler,&pfn);return0;}
Given that PoC flushing is only done on translation fault, what are
the odds that this would report a different number than that of
translation faults (assuming it was actually implemented)?
It is also interesting that you attribute the same cost to flushing a
4kB page or a 1GB block. And what does this mean when either FWB or
IDC are available?
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter that triggers when all the cache are flushed. This happens
when toggling caching for instance.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 1 +
3 files changed, 3 insertions(+)
What additional information does this give over the other d-side flush
counter?
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter for remote tlb flushes.
I think flushing the tlb is important enough of a thing so that one using
kvm_stat should be aware if their code is trigering several flushes.
Beside the event is recorded in x86 and ppc as well so there might be
even more reasons that I can't think of.
Looking at where this is called, it mostly happen when someone is
updating the dirty pages while we are doing some operation on them
(like enabling dirty pages logging)
There's one catch though, it is not always thread safe. Sometime it is
called under some lock, some other time it isn't.
We can't change the counter to an atomic_t as all the counters are
unsigned. We shouldn't add a lock as this could be adding a lock
(say, to kvm->arch) for a very minor thing and I would rather not pollute
anything without a better reason. That's why I ended up using cmpxchg
which according to LWN (https://lwn.net/Articles/695257/) is an old way
to do without atomic. It's less efficient than an atomic increment, but
this should happen very rarely anyway and is stil better than a lock.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 11 +++++++++++
2 files changed, 12 insertions(+)
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:13:48
On Fri, 19 Mar 2021 16:17:06 +0000,
Yoan Picchi [off-list ref] wrote:
Add a counter for remote tlb flushes.
I think flushing the tlb is important enough of a thing so that one using
kvm_stat should be aware if their code is trigering several flushes.
Beside the event is recorded in x86 and ppc as well so there might be
even more reasons that I can't think of.
And does this stat mean the same thing across architectures?
Looking at where this is called, it mostly happen when someone is
updating the dirty pages while we are doing some operation on them
(like enabling dirty pages logging)
How about swapping, KSM, VM teardown?
There's one catch though, it is not always thread safe. Sometime it is
called under some lock, some other time it isn't.
We can't change the counter to an atomic_t as all the counters are
unsigned. We shouldn't add a lock as this could be adding a lock
(say, to kvm->arch) for a very minor thing and I would rather not pollute
anything without a better reason. That's why I ended up using cmpxchg
which according to LWN (https://lwn.net/Articles/695257/) is an old way
to do without atomic. It's less efficient than an atomic increment, but
this should happen very rarely anyway and is stil better than a lock.
Are you actually worried about this stat being exact?
Two things:
- having a VM_STAT stuck in the middle on a set of per-vcpu stats
isn't great
- what does "remote TLB flush" means for the ARM architecture, which
uses broadcast invalidation? Slapping foreign concepts in the
architecture code doesn't strike me as the best course of action
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter for when the one want to unmap all the ram of a VM.
This mostly happens when one restart a VM so we make sure to clear
the ram and free the memory for other VMs.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 2 ++
3 files changed, 4 insertions(+)
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:35:39
On Fri, 19 Mar 2021 16:17:10 +0000,
Yoan Picchi [off-list ref] wrote:
Add a counter for when the one want to unmap all the ram of a VM.
This mostly happens when one restart a VM so we make sure to clear
the ram and free the memory for other VMs.
Again: unmapping memory from a VM doesn't make it free for anyone
else.
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter for when a memory slot is unmapped, meaning that all
memory belonging to a specific VM is made available to be mapped for
anoother VM. A memory slot is the memory that can be used to hold a
guest's pages and can be made available by Qemu for instance. For
now the memory slot are only unmapped when a vm restarts.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 1 +
3 files changed, 3 insertions(+)
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:34:57
On Fri, 19 Mar 2021 16:17:09 +0000,
Yoan Picchi [off-list ref] wrote:
Add a counter for when a memory slot is unmapped, meaning that all
memory belonging to a specific VM is made available to be mapped for
anoother VM.
No. It just means it is unmapped from the guest. The VMM still has the
pages.
quoted hunk
A memory slot is the memory that can be used to hold a
guest's pages and can be made available by Qemu for instance. For
now the memory slot are only unmapped when a vm restarts.
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 1 +
3 files changed, 3 insertions(+)
Why is that a relevant thing to track? You even increment the counter
before even checking whether this will unmap anything... :-(
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add a counter for interrupt injections. That is when kvm relay an
interrupt to the guest (for instance a timer, or a device interrupt
like from a network card)
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/arm.c | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/vgic/vgic.c | 2 ++
4 files changed, 8 insertions(+)
@@ -458,6 +458,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,raw_spin_lock_irqsave(&irq->irq_lock,flags);+kvm->stat.irq_inject++;+if(!vgic_validate_injection(irq,level,owner)){/* Nothing to see here, move along... */raw_spin_unlock_irqrestore(&irq->irq_lock,flags);
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 17:39:48
On Fri, 19 Mar 2021 16:17:11 +0000,
Yoan Picchi [off-list ref] wrote:
quoted hunk
Add a counter for interrupt injections. That is when kvm relay an
interrupt to the guest (for instance a timer, or a device interrupt
like from a network card)
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/arm.c | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/vgic/vgic.c | 2 ++
4 files changed, 8 insertions(+)
@@ -458,6 +458,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,raw_spin_lock_irqsave(&irq->irq_lock,flags);+kvm->stat.irq_inject++;+if(!vgic_validate_injection(irq,level,owner)){
So even if the injection failed, you report an injection? And what
about injection that occur via the MMIO interface? What about direct
injection? What about a level interrupt that is forever high?
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Mark.
Thanks for all the reviews. I am a beginner and you gave me a lot to
learn about.
I will reply to the other patch progressively once I understand better
the issues.
On 23/03/2021 17:37, Marc Zyngier wrote:
On Fri, 19 Mar 2021 16:17:11 +0000,
Yoan Picchi [off-list ref] wrote:
quoted
Add a counter for interrupt injections. That is when kvm relay an
interrupt to the guest (for instance a timer, or a device interrupt
like from a network card)
Signed-off-by: Yoan Picchi <redacted>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/arm.c | 2 ++
arch/arm64/kvm/guest.c | 2 ++
arch/arm64/kvm/vgic/vgic.c | 2 ++
4 files changed, 8 insertions(+)
@@ -458,6 +458,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,raw_spin_lock_irqsave(&irq->irq_lock,flags);+kvm->stat.irq_inject++;+if(!vgic_validate_injection(irq,level,owner)){
So even if the injection failed, you report an injection? And what
about injection that occur via the MMIO interface? What about direct
injection? What about a level interrupt that is forever high?
M.
This one I actually started to fix this afternoon by moving the counter
into vgic_queue_irq_unlock().
This way it is only incremented when the interrupt is inserted into a
vcpu, and it also takes care of the
vgic_mmio injections. I also fixed the issue with the interrupt line so
it only increment when the line
change of level.
I'm not sure about what you mean by direct injection yet though.
Kindly,
Yoan
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-03-23 18:38:09
On Tue, 23 Mar 2021 17:53:42 +0000,
Yoan Picchi [off-list ref] wrote:
Hi Mark.
s/k/c/, please!
Thanks for all the reviews. I am a beginner and you gave me a lot to
learn about. I will reply to the other patch progressively once I
understand better the issues.
I think you should consider what I said in my reply to the cover
letter before going all out on every counter you have introduced in
this series.
[...]
@@ -458,6 +458,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,raw_spin_lock_irqsave(&irq->irq_lock,flags);+kvm->stat.irq_inject++;+if(!vgic_validate_injection(irq,level,owner)){
So even if the injection failed, you report an injection? And what
about injection that occur via the MMIO interface? What about direct
injection? What about a level interrupt that is forever high?
M.
This one I actually started to fix this afternoon by moving the
counter into vgic_queue_irq_unlock(). This way it is only
incremented when the interrupt is inserted into a vcpu, and it also
takes care of the vgic_mmio injections. I also fixed the issue with
the interrupt line so it only increment when the line change of
level.
But if you do that, you start counting interrupts the guest itself
generates. What is the exact semantic of this counter? userspace
injected interrupts? Acked interrupts? Any interrupt?
Take my level interrupt example. The interrupt will be forever
pending, the guest will take as many interrupt as it can process, and
yet your counter will have been incremented *once*. What does your
counter mean then?
I'm not sure about what you mean by direct injection yet though.
GICv4.{0,1}, where an interrupt gets directly delivered to the guest
without (too much) SW intervention. With this, directly injected LPIs
will never result in the counter being incremented, and yet can pin
the guest to the ground under interrupt load.
Again, defining the exact behaviour of the counter would avoid me
ranting away...
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Crucially, these differences exist because there is no universal
equivalence between architecture features. A TLB invalidation on x86
doesn't do the same thing as on PPC nor arm64.
Those counters are used in kvm_stat by kernel/driver developers to
have a rough idea of the impact of their patches on the general performance.
An example would be to make sure a patch don't increase to much the amount
of interruptions. Those patches aim to add more counters to make the use of
kvm_stat more relevant when measuring performance impact.
Adding more counters only make sense if the semantic of these counters
is clearly defined. In this series, you have sprayed a bunch of x++ in
random places, without defining what you were trying to count.
I am new in working on kernel-related things and I am learning kvm as I go.
Some of the counter I added early (memory_slot_unmaped, stage2_unmap_vm)
no longer seems relevant because while they do interesting things, they
happens in very specific scenarios. Instead of just deleting them, I prefer
to ask weither a little-used counter or no counter is the best.
It works the other way around: the onus is on you to explain *why* we
should even consider a counter or another.
May I suggest that you start by picking exactly *one* metric, work out
exactly what it is supposed to count, what significance it has at the
architectural level, what it actually brings to the user? Then try and
make a good job at implementing these semantics. You will learn about
the arm64 architecture and KVM in one swift go, one area at a time.
I can also use some suggestion on how to test those counters as some like
remote_tlb_flush which mostly happen when fixing up a race condition; or
what uncovered event could be worth adding in a future patch set.
remote_tlb_flush is a great example of something that really *doesn't*
make much sense on KVM/arm64. We don't deal with remote TLBs
independently of the local ones outside of vcpu migration (which you
don't cover either).
I can only urge you to focus on the architectural meaning of the
metric you picked, and see how it maps across the hypervisor.
Finally, there is the question of the general availability of these
counters. They live in debugfs, which isn't a proper userspace
ABI. There is work going on around making this a more palatable
interface, and I'd rather see where this is going before expanding the
number of counters.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel