Skip to contentSkip to conversation

x86/hyper-v: implement EOI assist

PATCH In review Vitaly Kuznetsov 3 participants 4 messages Apr 3, 2019 – Apr 16, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hyper-v: implement EOI assist

Hyper-V TLFS suggests an optimization to avoid imminent VMExit on EOI:
"The OS performs an EOI by atomically writing zero to the EOI Assist field of the virtual VP assist page and checking whether the "No EOI required" field was previously zero. If it was, the OS must write to the HV_X64_APIC_EOI MSR thereby triggering an intercept into the hypervisor."

Implement the optimization in Linux.

---
 arch/x86/hyperv/hv_apic.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/hyperv/hv_apic.c +5 -0
index 8eb6fbee8e13..5c056b8aebef 100644
@@ -86,6 +86,11 @@ static void hv_apic_write(u32 reg, u32 val)
 
 static void hv_apic_eoi_write(u32 reg, u32 val)
 {
+	struct hv_vp_assist_page *hvp = hv_vp_assist_page[smp_processor_id()];
+
+	if (hvp && (xchg(&hvp->apic_assist, 0) & 0x1))
+		return;
+
 	wrmsr(HV_X64_MSR_EOI, val, 0);
 }
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 8 lines · Vitaly Kuznetsov

Hyper-V TLFS suggests an optimization to avoid imminent VMExit on EOI:
"The OS performs an EOI by atomically writing zero to the EOI Assist field of the virtual VP assist page and checking whether the "No EOI required" field was previously zero. If it was, the OS must write to the HV_X64_APIC_EOI MSR thereby triggering an intercept into the hypervisor."

Implement the optimization in Linux.

Simon, Long,

did you get a chance to run some tests with this?

Signature · 1 line
Vitaly
Tested-by
#2 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Subject: Re: [PATCH] x86/hyper-v: implement EOI assist

Quoted 3 lines · Vitaly Kuznetsov

Hyper-V TLFS suggests an optimization to avoid imminent VMExit on EOI:
"The OS performs an EOI by atomically writing zero to the EOI Assist field of the virtual VP assist page and checking whether the "No EOI

required"

Quoted 2 lines

field was previously zero. If it was, the OS must write to the HV_X64_APIC_EOI MSR thereby triggering an intercept into the

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hypervisor."

Quoted 3 lines

Implement the optimization in Linux.

Simon, Long,

did you get a chance to run some tests with this?

I have ran some tests on Azure L80s_v2.

With 10 NVMe disks on raid0 and formatted to EXT4, I'm getting 2.6m max IOPS with the patch, compared to 2.55m IOPS before.

The VM has been running stable. Thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--
Vitaly

#3 lore raw

[tip:x86/platform] x86/hyper-v: Implement EOI assist

In reply to Vitaly Kuznetsov
x86/hyper-v: Implement EOI assist
Commit-ID:  ba696429d290690db967e5f49463df4b2c1314a4
Gitweb:     https://git.kernel.org/tip/ba696429d290690db967e5f49463df4b2c1314a4
Author:     Vitaly Kuznetsov <[email protected]>
AuthorDate: Wed, 3 Apr 2019 19:03:09 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 16 Apr 2019 12:28:23 +0200

x86/hyper-v: Implement EOI assist

Hyper-V TLFS suggests an optimization to avoid imminent VMExit on EOI:
"The OS performs an EOI by atomically writing zero to the EOI Assist field of the virtual VP assist page and checking whether the "No EOI required" field was previously zero. If it was, the OS must write to the HV_X64_APIC_EOI MSR thereby triggering an intercept into the hypervisor."

Implement the optimization in Linux.

Cc Borislav Petkov <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc K. Y. Srinivasan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Michael Kelley (EOSG) <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Sasha Levin <[email protected]>
Cc Simon Xiao <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/hyperv/hv_apic.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/hyperv/hv_apic.c +5 -0
index 8eb6fbee8e13..5c056b8aebef 100644
@@ -86,6 +86,11 @@ static void hv_apic_write(u32 reg, u32 val)
 
 static void hv_apic_eoi_write(u32 reg, u32 val)
 {
+	struct hv_vp_assist_page *hvp = hv_vp_assist_page[smp_processor_id()];
+
+	if (hvp && (xchg(&hvp->apic_assist, 0) & 0x1))
+		return;
+
 	wrmsr(HV_X64_MSR_EOI, val, 0);
 }