From: "Jan Beulich" Subject: [PATCH 1/2] x86: suppress event check IPI to MWAITing CPUs Date: Thu, 11 Sep 2014 10:40:09 +0100 Message-ID: <54118A190200007800033BC9@mail.emea.novell.com> References: <541189280200007800033BB5@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartA99CE1E9.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XS0rL-0004Wp-E8 for xen-devel@lists.xenproject.org; Thu, 11 Sep 2014 09:40:11 +0000 In-Reply-To: <541189280200007800033BB5@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Keir Fraser , Ian Jackson , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartA99CE1E9.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Mass wakeups (via vlapic_ipi()) can take enormous amounts of time, especially when many of the remote pCPU-s are in deep C-states. For 64-vCPU Windows Server 2012 R2 guests on Ivybridge hardware, accumulated times of over 2ms were observed (average 1.1ms). Considering that Windows broadcasts IPIs from its timer interrupt, which at least at certain times can run at 1kHz, it is clear that this can't result in good guest behavior. In fact, on said hardware guests with significantly beyond 40 vCPU-s simply hung when e.g. ServerManager gets started. Recognizing that writes to softirq_pending() already have the effect of waking remote CPUs from MWAITing (due to being co-located on the same cache line with mwait_wakeup()), we can avoid sending IPIs to CPUs we know are in a (deep) C-state entered via MWAIT. With this, average broadcast times for a 64-vCPU guest went down to a measured maximum of 255us (which is still quite a lot). One aspect worth noting is that cpumask_raise_softirq() gets brought in sync here with cpu_raise_softirq() in that now both don't attempt to raise a self-IPI on the processing CPU. Signed-off-by: Jan Beulich --- a/xen/arch/x86/acpi/cpu_idle.c +++ b/xen/arch/x86/acpi/cpu_idle.c @@ -330,6 +330,16 @@ void cpuidle_wakeup_mwait(cpumask_t *mas cpumask_andnot(mask, mask, &target); } =20 +bool_t arch_skip_send_event_check(unsigned int cpu) +{ + /* + * This relies on softirq_pending() and mwait_wakeup() to access data + * on the same cache line. + */ + smp_mb(); + return !!cpumask_test_cpu(cpu, &cpuidle_mwait_flags); +} + void mwait_idle_with_hints(unsigned int eax, unsigned int ecx) { unsigned int cpu =3D smp_processor_id(); @@ -349,7 +359,7 @@ void mwait_idle_with_hints(unsigned int=20 * Timer deadline passing is the event on which we will be woken via * cpuidle_mwait_wakeup. So check it now that the location is armed. */ - if ( expires > NOW() || expires =3D=3D 0 ) + if ( (expires > NOW() || expires =3D=3D 0) && !softirq_pending(cpu) ) { cpumask_set_cpu(cpu, &cpuidle_mwait_flags); __mwait(eax, ecx); --- a/xen/common/softirq.c +++ b/xen/common/softirq.c @@ -70,12 +70,14 @@ void open_softirq(int nr, softirq_handle =20 void cpumask_raise_softirq(const cpumask_t *mask, unsigned int nr) { - int cpu; + unsigned int cpu, this_cpu =3D smp_processor_id(); cpumask_t send_mask; =20 cpumask_clear(&send_mask); for_each_cpu(cpu, mask) - if ( !test_and_set_bit(nr, &softirq_pending(cpu)) ) + if ( !test_and_set_bit(nr, &softirq_pending(cpu)) && + cpu !=3D this_cpu && + !arch_skip_send_event_check(cpu) ) cpumask_set_cpu(cpu, &send_mask); =20 smp_send_event_check_mask(&send_mask); @@ -84,7 +86,8 @@ void cpumask_raise_softirq(const cpumask void cpu_raise_softirq(unsigned int cpu, unsigned int nr) { if ( !test_and_set_bit(nr, &softirq_pending(cpu)) - && (cpu !=3D smp_processor_id()) ) + && (cpu !=3D smp_processor_id()) + && !arch_skip_send_event_check(cpu) ) smp_send_event_check_cpu(cpu); } =20 --- a/xen/include/asm-arm/softirq.h +++ b/xen/include/asm-arm/softirq.h @@ -3,6 +3,8 @@ =20 #define NR_ARCH_SOFTIRQS 0 =20 +#define arch_skip_send_event_check(cpu) 0 + #endif /* __ASM_SOFTIRQ_H__ */ /* * Local variables: --- a/xen/include/asm-x86/softirq.h +++ b/xen/include/asm-x86/softirq.h @@ -9,4 +9,6 @@ #define PCI_SERR_SOFTIRQ (NR_COMMON_SOFTIRQS + 4) #define NR_ARCH_SOFTIRQS 5 =20 +bool_t arch_skip_send_event_check(unsigned int cpu); + #endif /* __ASM_SOFTIRQ_H__ */ --=__PartA99CE1E9.1__= Content-Type: text/plain; name="x86-suppress-event-check-IPI.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-suppress-event-check-IPI.patch" x86: suppress event check IPI to MWAITing CPUs=0A=0AMass wakeups (via = vlapic_ipi()) can take enormous amounts of time,=0Aespecially when many of = the remote pCPU-s are in deep C-states. For=0A64-vCPU Windows Server 2012 = R2 guests on Ivybridge hardware,=0Aaccumulated times of over 2ms were = observed (average 1.1ms).=0AConsidering that Windows broadcasts IPIs from = its timer interrupt,=0Awhich at least at certain times can run at 1kHz, it = is clear that this=0Acan't result in good guest behavior. In fact, on said = hardware guests=0Awith significantly beyond 40 vCPU-s simply hung when = e.g. ServerManager=0Agets started.=0A=0ARecognizing that writes to = softirq_pending() already have the effect of=0Awaking remote CPUs from = MWAITing (due to being co-located on the same=0Acache line with mwait_wakeu= p()), we can avoid sending IPIs to CPUs we=0Aknow are in a (deep) C-state = entered via MWAIT.=0A=0AWith this, average broadcast times for a 64-vCPU = guest went down to a=0Ameasured maximum of 255us (which is still quite a = lot).=0A=0AOne aspect worth noting is that cpumask_raise_softirq() gets = brought in=0Async here with cpu_raise_softirq() in that now both don't = attempt to=0Araise a self-IPI on the processing CPU.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/xen/arch/x86/acpi/cpu_idle.c=0A+= ++ b/xen/arch/x86/acpi/cpu_idle.c=0A@@ -330,6 +330,16 @@ void cpuidle_wakeu= p_mwait(cpumask_t *mas=0A cpumask_andnot(mask, mask, &target);=0A }=0A = =0A+bool_t arch_skip_send_event_check(unsigned int cpu)=0A+{=0A+ /*=0A+ = * This relies on softirq_pending() and mwait_wakeup() to access = data=0A+ * on the same cache line.=0A+ */=0A+ smp_mb();=0A+ = return !!cpumask_test_cpu(cpu, &cpuidle_mwait_flags);=0A+}=0A+=0A void = mwait_idle_with_hints(unsigned int eax, unsigned int ecx)=0A {=0A = unsigned int cpu =3D smp_processor_id();=0A@@ -349,7 +359,7 @@ void = mwait_idle_with_hints(unsigned int =0A * Timer deadline passing is = the event on which we will be woken via=0A * cpuidle_mwait_wakeup. So = check it now that the location is armed.=0A */=0A- if ( expires > = NOW() || expires =3D=3D 0 )=0A+ if ( (expires > NOW() || expires =3D=3D = 0) && !softirq_pending(cpu) )=0A {=0A cpumask_set_cpu(cpu, = &cpuidle_mwait_flags);=0A __mwait(eax, ecx);=0A--- a/xen/common/sof= tirq.c=0A+++ b/xen/common/softirq.c=0A@@ -70,12 +70,14 @@ void open_softirq= (int nr, softirq_handle=0A =0A void cpumask_raise_softirq(const cpumask_t = *mask, unsigned int nr)=0A {=0A- int cpu;=0A+ unsigned int cpu, = this_cpu =3D smp_processor_id();=0A cpumask_t send_mask;=0A =0A = cpumask_clear(&send_mask);=0A for_each_cpu(cpu, mask)=0A- if ( = !test_and_set_bit(nr, &softirq_pending(cpu)) )=0A+ if ( !test_and_se= t_bit(nr, &softirq_pending(cpu)) &&=0A+ cpu !=3D this_cpu = &&=0A+ !arch_skip_send_event_check(cpu) )=0A = cpumask_set_cpu(cpu, &send_mask);=0A =0A smp_send_event_check_mask(&sen= d_mask);=0A@@ -84,7 +86,8 @@ void cpumask_raise_softirq(const cpumask=0A = void cpu_raise_softirq(unsigned int cpu, unsigned int nr)=0A {=0A if ( = !test_and_set_bit(nr, &softirq_pending(cpu))=0A- && (cpu !=3D = smp_processor_id()) )=0A+ && (cpu !=3D smp_processor_id())=0A+ = && !arch_skip_send_event_check(cpu) )=0A smp_send_event_check_c= pu(cpu);=0A }=0A =0A--- a/xen/include/asm-arm/softirq.h=0A+++ b/xen/include= /asm-arm/softirq.h=0A@@ -3,6 +3,8 @@=0A =0A #define NR_ARCH_SOFTIRQS = 0=0A =0A+#define arch_skip_send_event_check(cpu) 0=0A+=0A #endif /* = __ASM_SOFTIRQ_H__ */=0A /*=0A * Local variables:=0A--- a/xen/include/asm-x= 86/softirq.h=0A+++ b/xen/include/asm-x86/softirq.h=0A@@ -9,4 +9,6 @@=0A = #define PCI_SERR_SOFTIRQ (NR_COMMON_SOFTIRQS + 4)=0A #define = NR_ARCH_SOFTIRQS 5=0A =0A+bool_t arch_skip_send_event_check(unsigned = int cpu);=0A+=0A #endif /* __ASM_SOFTIRQ_H__ */=0A --=__PartA99CE1E9.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartA99CE1E9.1__=--