From: "Jan Beulich" Subject: [PATCH 1/3] x86/mwait_idle: remove assumption of one C-state per MWAIT flag Date: Thu, 29 Aug 2013 14:11:21 +0100 Message-ID: <521F649902000078000EF705@nat28.tlf.novell.com> References: <521F631602000078000EF6F9@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part04374469.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VF20g-0005rR-Eu for xen-devel@lists.xenproject.org; Thu, 29 Aug 2013 13:11:38 +0000 In-Reply-To: <521F631602000078000EF6F9@nat28.tlf.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: Len Brown , Keir Fraser , Jun Nakajima 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. --=__Part04374469.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Remove the assumption that cstate_tables are indexed by MWAIT flag values. Each entry identifies itself via its own flags value. This change is needed to support multiple states that share the same MWAIT flags. Note that this can have an effect on what state is described by 'N' on cmdline max_cstate=3DN on some systems. Signed-off-by: Len Brown Avoided the effect of changing the meaning of "max_cstate=3D". Drop MWAIT_MAX_NUM_CSTATES (done differently in a prior patch on Linux). Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/mwait-idle.c +++ b/xen/arch/x86/cpu/mwait-idle.c @@ -116,146 +116,146 @@ static const struct cpuidle_state { */ #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF) #define MWAIT2flg(eax) ((eax & 0xFF) << 24) +#define MWAIT_HINT2CSTATE(hint) (((hint) >> MWAIT_SUBSTATE_SIZE) & = MWAIT_CSTATE_MASK) +#define MWAIT_HINT2SUBSTATE(hint) ((hint) & MWAIT_CSTATE_MASK) =20 /* * States are indexed by the cstate number, * which is also the index into the MWAIT hint array. * Thus C0 is a dummy. */ -static const struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = =3D { - { /* MWAIT C0 */ }, - { /* MWAIT C1 */ +static const struct cpuidle_state nehalem_cstates[] =3D { + { .name =3D "C1-NHM", .flags =3D MWAIT2flg(0x00), .exit_latency =3D 3, .target_residency =3D 6, }, - { /* MWAIT C2 */ + { .name =3D "C3-NHM", .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 20, .target_residency =3D 80, }, - { /* MWAIT C3 */ + { .name =3D "C6-NHM", .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 200, .target_residency =3D 800, - } + }, + {} }; =20 -static const struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] =3D = { - { /* MWAIT C0 */ }, - { /* MWAIT C1 */ +static const struct cpuidle_state snb_cstates[] =3D { + { .name =3D "C1-SNB", .flags =3D MWAIT2flg(0x00), .exit_latency =3D 1, .target_residency =3D 1, }, - { /* MWAIT C2 */ + { .name =3D "C3-SNB", .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 80, .target_residency =3D 211, }, - { /* MWAIT C3 */ + { .name =3D "C6-SNB", .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 104, .target_residency =3D 345, }, - { /* MWAIT C4 */ + { .name =3D "C7-SNB", .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 109, .target_residency =3D 345, - } + }, + {} }; =20 -static const struct cpuidle_state ivb_cstates[MWAIT_MAX_NUM_CSTATES] =3D = { - { /* MWAIT C0 */ }, - { /* MWAIT C1 */ +static const struct cpuidle_state ivb_cstates[] =3D { + { .name =3D "C1-IVB", .flags =3D MWAIT2flg(0x00), .exit_latency =3D 1, .target_residency =3D 1, }, - { /* MWAIT C2 */ + { .name =3D "C3-IVB", .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 59, .target_residency =3D 156, }, - { /* MWAIT C3 */ + { .name =3D "C6-IVB", .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 80, .target_residency =3D 300, }, - { /* MWAIT C4 */ + { .name =3D "C7-IVB", .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 87, .target_residency =3D 300, - } + }, + {} }; =20 -static const struct cpuidle_state hsw_cstates[MWAIT_MAX_NUM_CSTATES] =3D = { - { /* MWAIT C0 */ }, - { /* MWAIT C1 */ +static const struct cpuidle_state hsw_cstates[] =3D { + { .name =3D "C1-HSW", .flags =3D MWAIT2flg(0x00), .exit_latency =3D 2, .target_residency =3D 2, }, - { /* MWAIT C2 */ + { .name =3D "C3-HSW", .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 33, .target_residency =3D 100, }, - { /* MWAIT C3 */ + { .name =3D "C6-HSW", .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 133, .target_residency =3D 400, }, - { /* MWAIT C4 */ + { .name =3D "C7s-HSW", .flags =3D MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 166, .target_residency =3D 500, }, + {} }; =20 -static const struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] =3D = { - { /* MWAIT C0 */ }, - { /* MWAIT C1 */ +static const struct cpuidle_state atom_cstates[] =3D { + { .name =3D "C1-ATM", .flags =3D MWAIT2flg(0x00), .exit_latency =3D 1, .target_residency =3D 4, }, - { /* MWAIT C2 */ + { .name =3D "C2-ATM", .flags =3D MWAIT2flg(0x10), .exit_latency =3D 20, .target_residency =3D 80, }, - { /* MWAIT C3 */ }, - { /* MWAIT C4 */ + { .name =3D "C4-ATM", .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 100, .target_residency =3D 400, }, - { /* MWAIT C5 */ }, - { /* MWAIT C6 */ + { .name =3D "C6-ATM", .flags =3D MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED, .exit_latency =3D 140, .target_residency =3D 560, - } + }, + {} }; =20 static void mwait_idle(void) @@ -476,29 +476,25 @@ static int mwait_idle_cpu_init(struct no =20 dev->count =3D 1; =20 - for (cstate =3D 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) { - unsigned int num_substates; + for (cstate =3D 0; cpuidle_state_table[cstate].target_residency; = ++cstate) { + unsigned int num_substates, hint, state, substate; struct acpi_processor_cx *cx; =20 - if (cstate > max_cstate) { + hint =3D flg2MWAIT(cpuidle_state_table[cstate].flags); + state =3D MWAIT_HINT2CSTATE(hint) + 1; + substate =3D MWAIT_HINT2SUBSTATE(hint); + + if (state > max_cstate) { printk(PREFIX "max C-state %u reached\n", = max_cstate); break; } =20 /* Does the state exist in CPUID.MWAIT? */ - num_substates =3D (mwait_substates >> (cstate * 4)) - & MWAIT_SUBSTATE_MASK; - if (!num_substates) - continue; - /* Is the state not enabled? */ - if (!cpuidle_state_table[cstate].target_residency) { - /* does the driver not know about the state? */ - if (!pm_idle_save && !*cpuidle_state_table[cstate].= name) - pr_debug(PREFIX "unaware of family %#x = model %#x MWAIT %u\n", - boot_cpu_data.x86, - boot_cpu_data.x86_model, cstate); + num_substates =3D (mwait_substates >> (state * 4)) + & MWAIT_SUBSTATE_MASK; + /* if sub-state in table is not enumerated by CPUID */ + if (substate >=3D num_substates) continue; - } =20 if (dev->count >=3D ACPI_PROCESSOR_MAX_POWER) { printk(PREFIX "max C-state count of %u reached\n", @@ -506,15 +502,13 @@ static int mwait_idle_cpu_init(struct no break; } =20 - if (cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) = { - if (pm_idle_save) - continue; + if (state > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC) && + !pm_idle_save) setup_clear_cpu_cap(X86_FEATURE_TSC_RELIABLE); - } =20 cx =3D dev->states + dev->count; - cx->type =3D cstate; - cx->address =3D flg2MWAIT(cpuidle_state_table[cstate].flags= ); + cx->type =3D state; + cx->address =3D hint; cx->entry_method =3D ACPI_CSTATE_EM_FFH; cx->latency =3D cpuidle_state_table[cstate].exit_latency; cx->target_residency =3D --- a/xen/include/asm-x86/mwait.h +++ b/xen/include/asm-x86/mwait.h @@ -4,7 +4,6 @@ #define MWAIT_SUBSTATE_MASK 0xf #define MWAIT_CSTATE_MASK 0xf #define MWAIT_SUBSTATE_SIZE 4 -#define MWAIT_MAX_NUM_CSTATES 8 =20 #define CPUID_MWAIT_LEAF 5 #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1 --=__Part04374469.1__= Content-Type: text/plain; name="x86-mwait-idle-multi-C-state.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mwait-idle-multi-C-state.patch" x86/mwait_idle: remove assumption of one C-state per MWAIT flag=0A=0ARemove= the assumption that cstate_tables are indexed by MWAIT flag=0Avalues. = Each entry identifies itself via its own flags value. This=0Achange is = needed to support multiple states that share the same MWAIT=0Aflags.=0A=0AN= ote that this can have an effect on what state is described by 'N' = on=0Acmdline max_cstate=3DN on some systems.=0A=0ASigned-off-by: Len Brown = =0A=0AAvoided the effect of changing the meaning of = "max_cstate=3D".=0ADrop MWAIT_MAX_NUM_CSTATES (done differently in a prior = patch on=0ALinux).=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@@ -116,146 +116,146 @@ static const struct cpuidle_state {=0A */=0A = #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)=0A #define MWAIT2flg(eax)= ((eax & 0xFF) << 24)=0A+#define MWAIT_HINT2CSTATE(hint) (((hint) >> = MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK)=0A+#define MWAIT_HINT2SUBSTATE(hi= nt) ((hint) & MWAIT_CSTATE_MASK)=0A =0A /*=0A * States are indexed by the = cstate number,=0A * which is also the index into the MWAIT hint array.=0A = * Thus C0 is a dummy.=0A */=0A-static const struct cpuidle_state = nehalem_cstates[MWAIT_MAX_NUM_CSTATES] =3D {=0A- { /* MWAIT C0 */ = },=0A- { /* MWAIT C1 */=0A+static const struct cpuidle_state nehalem_cstat= es[] =3D {=0A+ {=0A .name =3D "C1-NHM",=0A .flags =3D = MWAIT2flg(0x00),=0A .exit_latency =3D 3,=0A = .target_residency =3D 6,=0A },=0A- { /* MWAIT C2 */=0A+ {=0A = .name =3D "C3-NHM",=0A .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 20,=0A .target_res= idency =3D 80,=0A },=0A- { /* MWAIT C3 */=0A+ {=0A = .name =3D "C6-NHM",=0A .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 200,=0A .target_res= idency =3D 800,=0A- }=0A+ },=0A+ {}=0A };=0A =0A-static const = struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] =3D {=0A- { = /* MWAIT C0 */ },=0A- { /* MWAIT C1 */=0A+static const struct cpuidle_sta= te snb_cstates[] =3D {=0A+ {=0A .name =3D "C1-SNB",=0A = .flags =3D MWAIT2flg(0x00),=0A .exit_latency =3D 1,=0A = .target_residency =3D 1,=0A },=0A- { /* MWAIT C2 */=0A+ {=0A = .name =3D "C3-SNB",=0A .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 80,=0A .target_res= idency =3D 211,=0A },=0A- { /* MWAIT C3 */=0A+ {=0A = .name =3D "C6-SNB",=0A .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 104,=0A .target_res= idency =3D 345,=0A },=0A- { /* MWAIT C4 */=0A+ {=0A = .name =3D "C7-SNB",=0A .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 109,=0A .target_res= idency =3D 345,=0A- }=0A+ },=0A+ {}=0A };=0A =0A-static const = struct cpuidle_state ivb_cstates[MWAIT_MAX_NUM_CSTATES] =3D {=0A- { = /* MWAIT C0 */ },=0A- { /* MWAIT C1 */=0A+static const struct cpuidle_sta= te ivb_cstates[] =3D {=0A+ {=0A .name =3D "C1-IVB",=0A = .flags =3D MWAIT2flg(0x00),=0A .exit_latency =3D 1,=0A = .target_residency =3D 1,=0A },=0A- { /* MWAIT C2 */=0A+ {=0A = .name =3D "C3-IVB",=0A .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 59,=0A .target_res= idency =3D 156,=0A },=0A- { /* MWAIT C3 */=0A+ {=0A = .name =3D "C6-IVB",=0A .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 80,=0A .target_res= idency =3D 300,=0A },=0A- { /* MWAIT C4 */=0A+ {=0A = .name =3D "C7-IVB",=0A .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 87,=0A .target_res= idency =3D 300,=0A- }=0A+ },=0A+ {}=0A };=0A =0A-static const = struct cpuidle_state hsw_cstates[MWAIT_MAX_NUM_CSTATES] =3D {=0A- { = /* MWAIT C0 */ },=0A- { /* MWAIT C1 */=0A+static const struct cpuidle_sta= te hsw_cstates[] =3D {=0A+ {=0A .name =3D "C1-HSW",=0A = .flags =3D MWAIT2flg(0x00),=0A .exit_latency =3D 2,=0A = .target_residency =3D 2,=0A },=0A- { /* MWAIT C2 */=0A+ {=0A = .name =3D "C3-HSW",=0A .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 33,=0A .target_res= idency =3D 100,=0A },=0A- { /* MWAIT C3 */=0A+ {=0A = .name =3D "C6-HSW",=0A .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 133,=0A .target_res= idency =3D 400,=0A },=0A- { /* MWAIT C4 */=0A+ {=0A = .name =3D "C7s-HSW",=0A .flags =3D MWAIT2flg(0x32) | = CPUIDLE_FLAG_TLB_FLUSHED,=0A .exit_latency =3D 166,=0A = .target_residency =3D 500,=0A },=0A+ {}=0A };=0A =0A-static const = struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] =3D {=0A- { = /* MWAIT C0 */ },=0A- { /* MWAIT C1 */=0A+static const struct cpuidle_sta= te atom_cstates[] =3D {=0A+ {=0A .name =3D "C1-ATM",=0A = .flags =3D MWAIT2flg(0x00),=0A .exit_latency =3D 1,=0A = .target_residency =3D 4,=0A },=0A- { /* MWAIT C2 */=0A+ {=0A = .name =3D "C2-ATM",=0A .flags =3D MWAIT2flg(0x10),=0A = .exit_latency =3D 20,=0A .target_residency =3D 80,=0A = },=0A- { /* MWAIT C3 */ },=0A- { /* MWAIT C4 */=0A+ {=0A = .name =3D "C4-ATM",=0A .flags =3D MWAIT2flg(0x30) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A .exit_latency =3D 100,=0A .target_res= idency =3D 400,=0A },=0A- { /* MWAIT C5 */ },=0A- { /* MWAIT C6 = */=0A+ {=0A .name =3D "C6-ATM",=0A .flags =3D = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,=0A .exit_latency =3D = 140,=0A .target_residency =3D 560,=0A- }=0A+ },=0A+ = {}=0A };=0A =0A static void mwait_idle(void)=0A@@ -476,29 +476,25 @@ = static int mwait_idle_cpu_init(struct no=0A =0A dev->count =3D = 1;=0A =0A- for (cstate =3D 1; cstate < MWAIT_MAX_NUM_CSTATES; = ++cstate) {=0A- unsigned int num_substates;=0A+ for (cstate =3D 0; = cpuidle_state_table[cstate].target_residency; ++cstate) {=0A+ = unsigned int num_substates, hint, state, substate;=0A struct = acpi_processor_cx *cx;=0A =0A- if (cstate > max_cstate) {=0A+ = hint =3D flg2MWAIT(cpuidle_state_table[cstate].flags);=0A+ = state =3D MWAIT_HINT2CSTATE(hint) + 1;=0A+ substate =3D = MWAIT_HINT2SUBSTATE(hint);=0A+=0A+ if (state > max_cstate) = {=0A printk(PREFIX "max C-state %u reached\n", = max_cstate);=0A break;=0A }=0A =0A = /* Does the state exist in CPUID.MWAIT? */=0A- num_substat= es =3D (mwait_substates >> (cstate * 4))=0A- & = MWAIT_SUBSTATE_MASK;=0A- if (!num_substates)=0A- = continue;=0A- /* Is the state not enabled? */=0A- if = (!cpuidle_state_table[cstate].target_residency) {=0A- /* = does the driver not know about the state? */=0A- if = (!pm_idle_save && !*cpuidle_state_table[cstate].name)=0A- = pr_debug(PREFIX "unaware of family %#x model %#x MWAIT %u\n",=0A- = boot_cpu_data.x86,=0A- = boot_cpu_data.x86_model, cstate);=0A+ num_substates =3D = (mwait_substates >> (state * 4))=0A+ & = MWAIT_SUBSTATE_MASK;=0A+ /* if sub-state in table is not = enumerated by CPUID */=0A+ if (substate >=3D num_substates)=0A= continue;=0A- }=0A =0A if = (dev->count >=3D ACPI_PROCESSOR_MAX_POWER) {=0A = printk(PREFIX "max C-state count of %u reached\n",=0A@@ -506,15 +502,13 @@ = static int mwait_idle_cpu_init(struct no=0A break;=0A = }=0A =0A- if (cstate > 2 && !boot_cpu_has(X86_FEATURE= _NONSTOP_TSC)) {=0A- if (pm_idle_save)=0A- = continue;=0A+ if (state > 2 && !boot_cpu_has(X86_FEATURE_= NONSTOP_TSC) &&=0A+ !pm_idle_save)=0A = setup_clear_cpu_cap(X86_FEATURE_TSC_RELIABLE);=0A- }=0A =0A = cx =3D dev->states + dev->count;=0A- cx->type =3D = cstate;=0A- cx->address =3D flg2MWAIT(cpuidle_state_table[cstat= e].flags);=0A+ cx->type =3D state;=0A+ cx->address =3D = hint;=0A cx->entry_method =3D ACPI_CSTATE_EM_FFH;=0A = cx->latency =3D cpuidle_state_table[cstate].exit_latency;=0A = cx->target_residency =3D=0A--- a/xen/include/asm-x86/mwait.h=0A+++ = b/xen/include/asm-x86/mwait.h=0A@@ -4,7 +4,6 @@=0A #define MWAIT_SUBSTATE_M= ASK 0xf=0A #define MWAIT_CSTATE_MASK 0xf=0A = #define MWAIT_SUBSTATE_SIZE 4=0A-#define MWAIT_MAX_NUM_CSTATES = 8=0A =0A #define CPUID_MWAIT_LEAF 5=0A #define = CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1=0A --=__Part04374469.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 --=__Part04374469.1__=--