Bug 1734502

Summary: qemu-kvm: backport cpuidle-haltpoll support
Product: Red Hat Enterprise Linux 7 Reporter: Marcelo Tosatti <mtosatti>
Component: qemu-kvm-rhevAssignee: Marcelo Tosatti <mtosatti>
Status: CLOSED ERRATA QA Contact: Yumei Huang <yuhuang>
Severity: unspecified Docs Contact:
Priority: high    
Version: 7.8CC: chayang, hhuang, jinzhao, juzhang, klaas, mtessun, virt-maint
Target Milestone: rcKeywords: ZStream
Target Release: ---Flags: jinzhao: needinfo-
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-rhev-2.12.0-37.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1746281 1746282 1759283 (view as bug list) Environment:
Last Closed: 2020-03-31 14:34:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1665500, 1746281, 1746282, 1759283    

Description Marcelo Tosatti 2019-07-30 17:44:40 UTC
To pass SAP HANA certification its necessary to improve guest
performance.

The cpuidle haltpoll driver avoids IPIs by busy spinning in the guest, 
which allows IPI less wakeups via mwait, bringing a 10% performance.

This bugzilla is for the qemu-kvm support necessary for the cpuidle haltpoll driver.

Comment 7 Marcelo Tosatti 2019-08-27 21:53:14 UTC
Testing procedure for qemu-kvm patch:

1) Install recent kernel on both host and guest (eg: 3.10.0-1082.el7).

2) On the host, enable tracing:

cd /sys/kernel/debug/tracing
echo "kvm_msr" > set_event
echo "ecx==0x4b564d05" > events/kvm/kvm_msr/filter
echo > trace

On the destination host as well.

3) Boot guest and load cpuidle-haltpoll driver:

# modprobe cpuidle-haltpoll

On /sys/kernel/debug/tracing/trace, should see every CPU disable host halt polling:

        qemu-kvm-29062 [010] .... 16887.913508: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29050 [024] .... 16887.913517: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29051 [012] .... 16887.913520: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29052 [000] .... 16887.913527: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29054 [028] .... 16887.913527: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29055 [006] .... 16887.913527: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29057 [020] .... 16887.913528: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29058 [016] .... 16887.913528: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29053 [004] .... 16887.913529: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29056 [002] .... 16887.913532: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29059 [030] .... 16887.913534: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29061 [022] .... 16887.913538: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29060 [018] .... 16887.913542: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29066 [014] .... 16887.913544: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29063 [008] .... 16887.913548: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-29065 [012] .... 16887.913550: kvm_msr: msr_write 4b564d05 = 0x0

4) Migrate.

Should see on trace of destination host that every vCPU has MSR 0x4b564d05 written with a 0.

Repeat same process but without loading cpuidle-haltpoll driver on guest.
The MSR should contain 0x1.

Comment 8 Marcelo Tosatti 2019-08-28 00:14:55 UTC
Sorry, this won't work. Instead perform the updated steps:

(In reply to Marcelo Tosatti from comment #7)
> Testing procedure for qemu-kvm patch:
> 
> 1) Install recent kernel on both host and guest (eg: 3.10.0-1082.el7).

2) Install msr-tools from epel repository, on guest: 
yum install msr-tools.

To enable EPEL, google for "enabling EPEL on RHEL 7".

> 3) Boot guest and load cpuidle-haltpoll driver:
> 
> # modprobe cpuidle-haltpoll
 
> 4) Migrate.
> 

5) Confirm MSR 0x4b564d05 has a value of 0:

# rdmsr 0x4b564d05

Should return 0 (on guest).

Comment 16 Yumei Huang 2019-11-26 03:25:07 UTC
Verify:
qemu-kvm-rhev-2.12.0-38.el7
kernel-3.10.0-1113.el7.x86_64 (both guest and host)

Steps:
1) Enable tracing on both src and dst host

# cd /sys/kernel/debug/tracing
# echo "kvm_msr" > set_event
# echo "ecx==0x4b564d05" > events/kvm/kvm_msr/filter
# echo > trace

2) Boot guest on src host with '-cpu Opteron_G5,+kvm-poll-control'[1], load cpuidle-haltpoll driver inside guest, and run 'rdmsr 0x4b564d05'.
# modprobe cpuidle-haltpoll
# rdmsr 0x4b564d05
0

3) Check trace on src host
# cat /sys/kernel/debug/tracing/trace

        qemu-kvm-7923  [023] .... 78327.452427: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-7924  [007] .... 78327.452466: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-7925  [017] .... 78327.452499: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-7926  [004] .... 78327.452538: kvm_msr: msr_write 4b564d05 = 0x0
        qemu-kvm-7923  [015] .... 78347.070138: kvm_msr: msr_read 4b564d05 = 0x0

4) Migrate guest to dst host, then run 'rdmsr 0x4b564d05' again.
# rdmsr 0x4b564d05
0

5) Check trace on dst host
# cat /sys/kernel/debug/tracing/trace

        qemu-kvm-19519 [028] .... 71516.665124: kvm_msr: msr_read 4b564d05 = 0x0



Repeat above steps without load cpuidle-haltpoll driver, rdmsr 0x4b564d05 always returns 1 inside guest before and after migration. And trace info is as below.

Src host trace:

        qemu-kvm-7597  [016] .... 77946.621392: kvm_msr: msr_read 4b564d05 = 0x1

Dst host trace:

        qemu-kvm-19243 [004] .... 71160.351405: kvm_msr: msr_read 4b564d05 = 0x1


[1] QEMU full cli:
# /usr/libexec/qemu-kvm \
    -name 'avocado-vt-vm1' \
    -sandbox on \
    -machine q35 \
    -nodefaults \
    -device VGA,bus=pcie.0,addr=0x1  \
    -device pvpanic,ioport=0x505,id=idoP7Hxp  \
    -device pcie-root-port,id=pcie.0-root-port-2,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
    -device qemu-xhci,id=usb1,bus=pcie.0-root-port-2,addr=0x0 \
    -device pcie-root-port,id=pcie.0-root-port-3,slot=3,chassis=3,addr=0x3,bus=pcie.0 \
    -device virtio-scsi-pci,id=virtio_scsi_pci0,bus=pcie.0-root-port-3,addr=0x0 \
    -drive id=drive_image1,if=none,snapshot=off,aio=threads,cache=none,format=qcow2,file=/home/guest/rhel78-64-virtio-scsi.qcow2 \
    -device scsi-hd,id=image1,drive=drive_image1 \
    -device pcie-root-port,id=pcie.0-root-port-4,slot=4,chassis=4,addr=0x4,bus=pcie.0 \
    -device virtio-net-pci,mac=9a:70:71:72:73:74,id=idchA8Cw,vectors=4,netdev=idks9PPv,bus=pcie.0-root-port-4,addr=0x0  \
    -netdev tap,id=idks9PPv,vhost=on \
    -m 4096,slots=256,maxmem=40G  \
    -smp 4,maxcpus=16,threads=1,cores=4,sockets=4 \
    -cpu 'Opteron_G5',+kvm-poll-control \
    -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1  \
    -vnc :0  \
    -rtc base=utc,clock=host,driftfix=slew  \
    -boot order=cdn,once=c,menu=off,strict=off \
    -enable-kvm \
    -monitor stdio -serial tcp:0:1234,server,nowait \
    -qmp tcp:0:4444,server,nowait \
    -monitor unix:/tmp/monitor3,server,nowait

Comment 17 Klaas Demter 2019-12-16 10:35:33 UTC
Hi,
https://access.redhat.com/errata/RHSA-2019:3179 / https://access.redhat.com/errata/RHSA-2019:3220 / https://access.redhat.com/errata/RHSA-2019:3055 seem to suggest this is already present in current rhel/rhv versions

are there plans to add this to default virtual-guest tuned profile or is this performance increase sap hana specific?

Greetings
Klaas

Comment 19 errata-xmlrpc 2020-03-31 14:34:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:1216