linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC PATCH] kvm: x86: reduce rtc 0x70 access vm-exit time
  2017-08-12 12:06 [RFC PATCH] kvm: x86: reduce rtc 0x70 access vm-exit time Peng Hao
@ 2017-08-12  7:35 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2017-08-12  7:35 UTC (permalink / raw)
  To: Peng Hao; +Cc: rkrcmar, kvm, linux-kernel



----- Original Message -----
> From: "Peng Hao" <peng.hao2@zte.com.cn>
> To: pbonzini@redhat.com, rkrcmar@redhat.com
> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Peng Hao" <peng.hao2@zte.com.cn>
> Sent: Saturday, August 12, 2017 2:06:51 PM
> Subject: [RFC PATCH] kvm: x86: reduce rtc 0x70 access vm-exit time
> 
> some versions of windows guest access rtc frequently because of
> rtc as system tick.guest access rtc like this: write register index
> to 0x70, then write or read data from 0x71. writing 0x70 port is
> just as index and do nothing else. So we can use coalesced mmio to
> handle this scene to reduce VM-EXIT time.
> without my patch, get the vm-exit time of accessing rtc 0x70 using
> perf tools: (guest OS : windows 7 64bit)
> IO Port Access  Samples Samples%  Time%  Min Time  Max Time  Avg time
> 0x70:POUT        86     30.99%    74.59%   9us      29us    10.75us (+-
> 3.41%)
> 
> with my patch
> IO Port Access  Samples Samples%  Time%   Min Time  Max Time   Avg time
>  0x70:POUT       106    32.02%    29.47%    0us      10us     1.57us (+-
>  7.38%)
> 
> the patch is a part of optimizing rtc 0x70 port access. Another is in
> qemu.

Looks good as a proof of concept.  However, you need documentation changes,
and you need to expose this using a capability.  Also, the "pad" field can
be renamed to "pio".

Paolo


> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
> ---
>  virt/kvm/coalesced_mmio.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
> index 571c1ce..f640c2f 100644
> --- a/virt/kvm/coalesced_mmio.c
> +++ b/virt/kvm/coalesced_mmio.c
> @@ -82,6 +82,7 @@ static int coalesced_mmio_write(struct kvm_vcpu *vcpu,
>  	ring->coalesced_mmio[ring->last].phys_addr = addr;
>  	ring->coalesced_mmio[ring->last].len = len;
>  	memcpy(ring->coalesced_mmio[ring->last].data, val, len);
> +	ring->coalesced_mmio[ring->last].pad = dev->zone.pad;
>  	smp_wmb();
>  	ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX;
>  	spin_unlock(&dev->kvm->ring_lock);
> @@ -148,8 +149,12 @@ int kvm_vm_ioctl_register_coalesced_mmio(struct kvm
> *kvm,
>  	dev->zone = *zone;
>  
>  	mutex_lock(&kvm->slots_lock);
> -	ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr,
> -				      zone->size, &dev->dev);
> +	if (zone->pad == 0)
> +		ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr,
> +						zone->size, &dev->dev);
> +	else
> +		ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, zone->addr,
> +						zone->size, &dev->dev);
>  	if (ret < 0)
>  		goto out_free_dev;
>  	list_add_tail(&dev->list, &kvm->coalesced_zones);
> @@ -173,7 +178,10 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm
> *kvm,
>  
>  	list_for_each_entry_safe(dev, tmp, &kvm->coalesced_zones, list)
>  		if (coalesced_mmio_in_range(dev, zone->addr, zone->size)) {
> -			kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev);
> +			if (zone->pad == 0)
> +				kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev);
> +			else
> +				kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &dev->dev);
>  			kvm_iodevice_destructor(&dev->dev);
>  		}
>  
> --
> 1.8.3.1
> 
> 
> 

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

* [RFC PATCH] kvm: x86: reduce rtc 0x70 access vm-exit time
@ 2017-08-12 12:06 Peng Hao
  2017-08-12  7:35 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Hao @ 2017-08-12 12:06 UTC (permalink / raw)
  To: pbonzini, rkrcmar; +Cc: kvm, linux-kernel, Peng Hao

some versions of windows guest access rtc frequently because of
rtc as system tick.guest access rtc like this: write register index
to 0x70, then write or read data from 0x71. writing 0x70 port is
just as index and do nothing else. So we can use coalesced mmio to
handle this scene to reduce VM-EXIT time.
without my patch, get the vm-exit time of accessing rtc 0x70 using
perf tools: (guest OS : windows 7 64bit)
IO Port Access  Samples Samples%  Time%  Min Time  Max Time  Avg time
0x70:POUT        86     30.99%    74.59%   9us      29us    10.75us (+- 3.41%)

with my patch
IO Port Access  Samples Samples%  Time%   Min Time  Max Time   Avg time
 0x70:POUT       106    32.02%    29.47%    0us      10us     1.57us (+- 7.38%)

the patch is a part of optimizing rtc 0x70 port access. Another is in
qemu.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
 virt/kvm/coalesced_mmio.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 571c1ce..f640c2f 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -82,6 +82,7 @@ static int coalesced_mmio_write(struct kvm_vcpu *vcpu,
 	ring->coalesced_mmio[ring->last].phys_addr = addr;
 	ring->coalesced_mmio[ring->last].len = len;
 	memcpy(ring->coalesced_mmio[ring->last].data, val, len);
+	ring->coalesced_mmio[ring->last].pad = dev->zone.pad;
 	smp_wmb();
 	ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX;
 	spin_unlock(&dev->kvm->ring_lock);
@@ -148,8 +149,12 @@ int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
 	dev->zone = *zone;
 
 	mutex_lock(&kvm->slots_lock);
-	ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr,
-				      zone->size, &dev->dev);
+	if (zone->pad == 0)
+		ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr,
+						zone->size, &dev->dev);
+	else
+		ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, zone->addr,
+						zone->size, &dev->dev);
 	if (ret < 0)
 		goto out_free_dev;
 	list_add_tail(&dev->list, &kvm->coalesced_zones);
@@ -173,7 +178,10 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
 
 	list_for_each_entry_safe(dev, tmp, &kvm->coalesced_zones, list)
 		if (coalesced_mmio_in_range(dev, zone->addr, zone->size)) {
-			kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev);
+			if (zone->pad == 0)
+				kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev);
+			else
+				kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &dev->dev);
 			kvm_iodevice_destructor(&dev->dev);
 		}
 
-- 
1.8.3.1

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

end of thread, other threads:[~2017-08-12  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-12 12:06 [RFC PATCH] kvm: x86: reduce rtc 0x70 access vm-exit time Peng Hao
2017-08-12  7:35 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).