From: "Jan Beulich" Subject: [PATCH] x86/idle: reduce contention on ACPI register accesses Date: Mon, 11 Nov 2013 08:06:13 +0000 Message-ID: <52809E0502000078001019FC@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartD0E30FE5.0__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VfmVn-0002Kj-OK for xen-devel@lists.xenproject.org; Mon, 11 Nov 2013 08:06:20 +0000 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: Keir Fraser 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. --=__PartD0E30FE5.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Other than when they're located in I/O port space, accessing them when in MMIO space (currently) implies usage of some sort of global lock: In -unstable this would be due to the use of vmap(), is older trees the necessary locking was introduced by 2ee9cbf9 ("ACPI: fix acpi_os_map_memory()"). This contention was observed to result in Dom0 kernel soft lockups during the loading of the ACPI processor driver there on systems with very many CPU cores. There are a couple of things being done for this: - re-order elements of an if() condition so that the register access only happens when we really need it - turn off arbitration disabling only when the first CPU leaves C3 (paralleling how arbitration disabling gets turned on) - only set the (global) bus master reload flag once (when the first target CPU gets processed) Signed-off-by: Jan Beulich --- a/xen/arch/x86/acpi/cpu_idle.c +++ b/xen/arch/x86/acpi/cpu_idle.c @@ -439,8 +439,8 @@ static void acpi_processor_idle(void) (next_state =3D cpuidle_current_governor->select(power)) > 0 ) { cx =3D &power->states[next_state]; - if ( power->flags.bm_check && acpi_idle_bm_check() - && cx->type =3D=3D ACPI_STATE_C3 ) + if ( cx->type =3D=3D ACPI_STATE_C3 && power->flags.bm_check && + acpi_idle_bm_check() ) cx =3D power->safe_state; if ( cx->idx > max_cstate ) cx =3D &power->states[max_cstate]; @@ -563,8 +563,8 @@ static void acpi_processor_idle(void) { /* Enable bus master arbitration */ spin_lock(&c3_cpu_status.lock); - acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); - c3_cpu_status.count--; + if ( c3_cpu_status.count-- =3D=3D num_online_cpus() ) + acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); spin_unlock(&c3_cpu_status.lock); } =20 @@ -821,12 +821,10 @@ static int check_cx(struct acpi_processo return -EINVAL; =20 /* All the logic here assumes flags.bm_check is same across all = CPUs */ - if ( bm_check_flag =3D=3D -1 ) + if ( bm_check_flag < 0 ) { /* Determine whether bm_check is needed based on CPU */ acpi_processor_power_init_bm_check(&(power->flags)); - bm_check_flag =3D power->flags.bm_check; - bm_control_flag =3D power->flags.bm_control; } else { @@ -853,14 +851,13 @@ static int check_cx(struct acpi_processo } } /* - * On older chipsets, BM_RLD needs to be set - * in order for Bus Master activity to wake the - * system from C3. Newer chipsets handle DMA - * during C3 automatically and BM_RLD is a NOP. - * In either case, the proper way to - * handle BM_RLD is to set it and leave it set. + * On older chipsets, BM_RLD needs to be set in order for Bus + * Master activity to wake the system from C3, hence + * acpi_set_register() is always being called once below. = Newer + * chipsets handle DMA during C3 automatically and BM_RLD is = a + * NOP. In either case, the proper way to handle BM_RLD is = to + * set it and leave it set. */ - acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1); } else { @@ -875,7 +872,13 @@ static int check_cx(struct acpi_processo " for C3 to be enabled on SMP systems\n")); return -EINVAL; } - acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0); + } + + if ( bm_check_flag < 0 ) + { + bm_check_flag =3D power->flags.bm_check; + bm_control_flag =3D power->flags.bm_control; + acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, bm_check_flag); } =20 break; --=__PartD0E30FE5.0__= Content-Type: text/plain; name="x86-cpuidle-MMIO-contention.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-cpuidle-MMIO-contention.patch" x86/idle: reduce contention on ACPI register accesses=0A=0AOther than when = they're located in I/O port space, accessing them when=0Ain MMIO space = (currently) implies usage of some sort of global lock: In=0A-unstable this = would be due to the use of vmap(), is older trees the=0Anecessary locking = was introduced by 2ee9cbf9 ("ACPI: fix=0Aacpi_os_map_memory()"). This = contention was observed to result in Dom0=0Akernel soft lockups during the = loading of the ACPI processor driver=0Athere on systems with very many CPU = cores.=0A=0AThere are a couple of things being done for this:=0A- re-order = elements of an if() condition so that the register access=0A only happens = when we really need it=0A- turn off arbitration disabling only when the = first CPU leaves C3=0A (paralleling how arbitration disabling gets turned = on)=0A- only set the (global) bus master reload flag once (when the = first=0A target CPU gets processed)=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@@ -439,8 +439,8 @@ static void acpi_proce= ssor_idle(void)=0A (next_state =3D cpuidle_current_governor->selec= t(power)) > 0 )=0A {=0A cx =3D &power->states[next_state];=0A- = if ( power->flags.bm_check && acpi_idle_bm_check()=0A- = && cx->type =3D=3D ACPI_STATE_C3 )=0A+ if ( cx->type =3D=3D = ACPI_STATE_C3 && power->flags.bm_check &&=0A+ acpi_idle_bm_chec= k() )=0A cx =3D power->safe_state;=0A if ( cx->idx > = max_cstate )=0A cx =3D &power->states[max_cstate];=0A@@ -563,8 = +563,8 @@ static void acpi_processor_idle(void)=0A {=0A = /* Enable bus master arbitration */=0A spin_lock(&c3_cpu_statu= s.lock);=0A- acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);=0A- = c3_cpu_status.count--;=0A+ if ( c3_cpu_status.count--= =3D=3D num_online_cpus() )=0A+ acpi_set_register(ACPI_BITRE= G_ARB_DISABLE, 0);=0A spin_unlock(&c3_cpu_status.lock);=0A = }=0A =0A@@ -821,12 +821,10 @@ static int check_cx(struct acpi_processo= =0A return -EINVAL;=0A =0A /* All the logic here = assumes flags.bm_check is same across all CPUs */=0A- if ( = bm_check_flag =3D=3D -1 )=0A+ if ( bm_check_flag < 0 )=0A = {=0A /* Determine whether bm_check is needed based on CPU = */=0A acpi_processor_power_init_bm_check(&(power->flags));=0A- = bm_check_flag =3D power->flags.bm_check;=0A- = bm_control_flag =3D power->flags.bm_control;=0A }=0A = else=0A {=0A@@ -853,14 +851,13 @@ static int check_cx(struct = acpi_processo=0A }=0A }=0A /*=0A- = * On older chipsets, BM_RLD needs to be set=0A- * = in order for Bus Master activity to wake the=0A- * system from = C3. Newer chipsets handle DMA=0A- * during C3 automatically = and BM_RLD is a NOP.=0A- * In either case, the proper way = to=0A- * handle BM_RLD is to set it and leave it set.=0A+ = * On older chipsets, BM_RLD needs to be set in order for Bus=0A+ = * Master activity to wake the system from C3, hence=0A+ = * acpi_set_register() is always being called once below. Newer=0A+ = * chipsets handle DMA during C3 automatically and BM_RLD is a=0A+ = * NOP. In either case, the proper way to handle BM_RLD is = to=0A+ * set it and leave it set.=0A */=0A- = acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);=0A }=0A = else=0A {=0A@@ -875,7 +872,13 @@ static int check_cx(struct = acpi_processo=0A " for C3 to be enabled on SMP = systems\n"));=0A return -EINVAL;=0A }=0A- = acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);=0A+ = }=0A+=0A+ if ( bm_check_flag < 0 )=0A+ {=0A+ = bm_check_flag =3D power->flags.bm_check;=0A+ bm_control_flag = =3D power->flags.bm_control;=0A+ acpi_set_register(ACPI_BITREG_B= US_MASTER_RLD, bm_check_flag);=0A }=0A =0A break;=0A --=__PartD0E30FE5.0__= 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 --=__PartD0E30FE5.0__=--