From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 5/5] mwait-idle: correct/improve BXT support Date: Wed, 08 Jun 2016 07:51:38 -0600 Message-ID: <57583F0A02000078000F320D@prv-mh.provo.novell.com> References: <57583E0D02000078000F31F2@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartBF89BDFA.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAdta-0006vF-RF for xen-devel@lists.xenproject.org; Wed, 08 Jun 2016 13:51:46 +0000 In-Reply-To: <57583E0D02000078000F31F2@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper 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. --=__PartBF89BDFA.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Linux commit 5dcef69486 ("intel_idle: add BXT support") added an 8-element lookup array with just a 2-bit value used for lookups. As per the SDM that bit field is really 3 bits wide. Since the top two array entries are zero, deal with the resulting invalid (zero) values by moving the zero-MSR-value check into irtl_2_usec() and having that function's caller check its result instead. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/mwait-idle.c +++ b/xen/arch/x86/cpu/mwait-idle.c @@ -922,7 +922,10 @@ static unsigned long long __init irtl_2_ { unsigned long long ns; =20 - ns =3D irtl_ns_units[(irtl >> 10) & 0x3]; + if (!irtl) + return 0; + + ns =3D irtl_ns_units[(irtl >> 10) & 0x7]; =20 return (irtl & 0x3FF) * ns / 1000; } @@ -935,43 +938,39 @@ static unsigned long long __init irtl_2_ static void __init bxt_idle_state_table_update(void) { unsigned long long msr; + unsigned int usec; =20 rdmsrl(MSR_PKGC6_IRTL, msr); - if (msr) { - unsigned int usec =3D irtl_2_usec(msr); - + usec =3D irtl_2_usec(msr); + if (usec) { bxt_cstates[2].exit_latency =3D usec; bxt_cstates[2].target_residency =3D usec; } =20 rdmsrl(MSR_PKGC7_IRTL, msr); - if (msr) { - unsigned int usec =3D irtl_2_usec(msr); - + usec =3D irtl_2_usec(msr); + if (usec) { bxt_cstates[3].exit_latency =3D usec; bxt_cstates[3].target_residency =3D usec; } =20 rdmsrl(MSR_PKGC8_IRTL, msr); - if (msr) { - unsigned int usec =3D irtl_2_usec(msr); - + usec =3D irtl_2_usec(msr); + if (usec) { bxt_cstates[4].exit_latency =3D usec; bxt_cstates[4].target_residency =3D usec; } =20 rdmsrl(MSR_PKGC9_IRTL, msr); - if (msr) { - unsigned int usec =3D irtl_2_usec(msr); - + usec =3D irtl_2_usec(msr); + if (usec) { bxt_cstates[5].exit_latency =3D usec; bxt_cstates[5].target_residency =3D usec; } =20 rdmsrl(MSR_PKGC10_IRTL, msr); - if (msr) { - unsigned int usec =3D irtl_2_usec(msr); - + usec =3D irtl_2_usec(msr); + if (usec) { bxt_cstates[6].exit_latency =3D usec; bxt_cstates[6].target_residency =3D usec; } --=__PartBF89BDFA.1__= Content-Type: text/plain; name="x86-mwait-idle-BXT-time-unit.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mwait-idle-BXT-time-unit.patch" mwait-idle: correct/improve BXT support=0A=0ALinux commit 5dcef69486 = ("intel_idle: add BXT support") added an=0A8-element lookup array with = just a 2-bit value used for lookups. As per=0Athe SDM that bit field is = really 3 bits wide. Since the top two array=0Aentries are zero, deal with = the resulting invalid (zero) values by=0Amoving the zero-MSR-value check = into irtl_2_usec() and having that=0Afunction's caller check its result = instead.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/cpu/mwait-idle.c=0A+++ b/xen/arch/x86/cpu/mwait-idle.c=0A@@ = -922,7 +922,10 @@ static unsigned long long __init irtl_2_=0A {=0A = unsigned long long ns;=0A =0A- ns =3D irtl_ns_units[(irtl >> 10) & = 0x3];=0A+ if (!irtl)=0A+ return 0;=0A+=0A+ ns =3D = irtl_ns_units[(irtl >> 10) & 0x7];=0A =0A return (irtl & 0x3FF) * ns = / 1000;=0A }=0A@@ -935,43 +938,39 @@ static unsigned long long __init = irtl_2_=0A static void __init bxt_idle_state_table_update(void)=0A {=0A = unsigned long long msr;=0A+ unsigned int usec;=0A =0A rdmsrl(MSR_= PKGC6_IRTL, msr);=0A- if (msr) {=0A- unsigned int usec =3D = irtl_2_usec(msr);=0A-=0A+ usec =3D irtl_2_usec(msr);=0A+ if (usec) = {=0A bxt_cstates[2].exit_latency =3D usec;=0A = bxt_cstates[2].target_residency =3D usec;=0A }=0A =0A rdmsrl(MSR_= PKGC7_IRTL, msr);=0A- if (msr) {=0A- unsigned int usec =3D = irtl_2_usec(msr);=0A-=0A+ usec =3D irtl_2_usec(msr);=0A+ if (usec) = {=0A bxt_cstates[3].exit_latency =3D usec;=0A = bxt_cstates[3].target_residency =3D usec;=0A }=0A =0A rdmsrl(MSR_= PKGC8_IRTL, msr);=0A- if (msr) {=0A- unsigned int usec =3D = irtl_2_usec(msr);=0A-=0A+ usec =3D irtl_2_usec(msr);=0A+ if (usec) = {=0A bxt_cstates[4].exit_latency =3D usec;=0A = bxt_cstates[4].target_residency =3D usec;=0A }=0A =0A rdmsrl(MSR_= PKGC9_IRTL, msr);=0A- if (msr) {=0A- unsigned int usec =3D = irtl_2_usec(msr);=0A-=0A+ usec =3D irtl_2_usec(msr);=0A+ if (usec) = {=0A bxt_cstates[5].exit_latency =3D usec;=0A = bxt_cstates[5].target_residency =3D usec;=0A }=0A =0A rdmsrl(MSR_= PKGC10_IRTL, msr);=0A- if (msr) {=0A- unsigned int usec =3D = irtl_2_usec(msr);=0A-=0A+ usec =3D irtl_2_usec(msr);=0A+ if (usec) = {=0A bxt_cstates[6].exit_latency =3D usec;=0A = bxt_cstates[6].target_residency =3D usec;=0A }=0A --=__PartBF89BDFA.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --=__PartBF89BDFA.1__=--