From: "Jan Beulich" Subject: [PATCH 4/4] mwait-idle: fine-tune IVT residency targets Date: Thu, 26 Jun 2014 11:22:22 +0100 Message-ID: <53AC107E020000780001D8B2@mail.emea.novell.com> References: <53AC0ED0020000780001D883@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2A18DF4E.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 1X06ox-0007mK-IC for xen-devel@lists.xenproject.org; Thu, 26 Jun 2014 10:22:23 +0000 In-Reply-To: <53AC0ED0020000780001D883@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: 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. --=__Part2A18DF4E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ivy Town processors have slightly different properties than Ivy Bridge processors, particuarly as socket count grows. Here we add dedicated tables covering 1-2 socket, 3-4 socket, and > 4 socket IVT configurations. This reduces the frequency of deep transitions on those systems, which can impact throughput. Signed-off-by: Len Brown Socket count determination needs to be done differently for us: The relevant code runs in a pre-SMP initcall, and hence can't use cpu_to_socket() (as only the boot CPU's cpu_data[].phys_proc_id got set up by that time). As a replacement the patch introduces apicid_to_socket(), thus estimating the socket count based on the boot CPU's internal topology information (if all CPUs in a system are the same, wich ought to be the common case, this estimate will be precise). Note that apicid_to_socket() handles Intel topology determination only for now, as the mwait-idle driver currently only supports Intel CPUs. Signed-off-by: Jan Beulich --- This requires the patch at http://lists.xenproject.org/archives/html/xen-devel/2014-06/msg03335.html= =20 as a prerequisite. --- a/xen/arch/x86/cpu/mwait-idle.c +++ b/xen/arch/x86/cpu/mwait-idle.c @@ -261,6 +261,90 @@ static const struct cpuidle_state ivb_cs {} }; =20 +static const struct cpuidle_state ivt_cstates[] =3D { + { + .name =3D "C1-IVT", + .flags =3D MWAIT2flg(0x00), + .exit_latency =3D 1, + .target_residency =3D 1, + }, + { + .name =3D "C1E-IVT", + .flags =3D MWAIT2flg(0x01), + .exit_latency =3D 10, + .target_residency =3D 80, + }, + { + .name =3D "C3-IVT", + .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 59, + .target_residency =3D 156, + }, + { + .name =3D "C6-IVT", + .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 82, + .target_residency =3D 300, + }, + {} +}; + +static const struct cpuidle_state ivt_cstates_4s[] =3D { + { + .name =3D "C1-IVT-4S", + .flags =3D MWAIT2flg(0x00), + .exit_latency =3D 1, + .target_residency =3D 1, + }, + { + .name =3D "C1E-IVT-4S", + .flags =3D MWAIT2flg(0x01), + .exit_latency =3D 10, + .target_residency =3D 250, + }, + { + .name =3D "C3-IVT-4S", + .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 59, + .target_residency =3D 300, + }, + { + .name =3D "C6-IVT-4S", + .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 84, + .target_residency =3D 400, + }, + {} +}; + +static const struct cpuidle_state ivt_cstates_8s[] =3D { + { + .name =3D "C1-IVT-8S", + .flags =3D MWAIT2flg(0x00), + .exit_latency =3D 1, + .target_residency =3D 1, + }, + { + .name =3D "C1E-IVT-8S", + .flags =3D MWAIT2flg(0x01), + .exit_latency =3D 10, + .target_residency =3D 500, + }, + { + .name =3D "C3-IVT-8S", + .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 59, + .target_residency =3D 600, + }, + { + .name =3D "C6-IVT-8S", + .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency =3D 88, + .target_residency =3D 700, + }, + {} +}; + static const struct cpuidle_state hsw_cstates[] =3D { { .name =3D "C1-HSW", @@ -494,6 +578,11 @@ static const struct idle_cpu idle_cpu_iv .disable_promotion_to_c1e =3D 1, }; =20 +static const struct idle_cpu idle_cpu_ivt =3D { + .state_table =3D ivt_cstates, + .disable_promotion_to_c1e =3D 1, +}; + static const struct idle_cpu idle_cpu_hsw =3D { .state_table =3D hsw_cstates, .disable_promotion_to_c1e =3D 1, @@ -524,7 +613,7 @@ static struct intel_idle_id { ICPU(0x36, atom), ICPU(0x37, byt), ICPU(0x3a, ivb), - ICPU(0x3e, ivb), + ICPU(0x3e, ivt), ICPU(0x3c, hsw), ICPU(0x3f, hsw), ICPU(0x45, hsw), @@ -533,6 +622,37 @@ static struct intel_idle_id { {} }; =20 +/* + * mwait_idle_state_table_update() + * + * Update the default state_table for this CPU-id + * + * Currently used to access tuned IVT multi-socket targets + * Assumption: num_sockets =3D=3D (max_package_num + 1) + */ +static void __init mwait_idle_state_table_update(void) +{ + /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */ + if (boot_cpu_data.x86_model =3D=3D 0x3e) { /* IVT */ + unsigned int cpu, max_apicid =3D boot_cpu_physical_apicid; + + for_each_present_cpu(cpu) + if (max_apicid < x86_cpu_to_apicid[cpu]) + max_apicid =3D x86_cpu_to_apicid[cpu]; + switch (apicid_to_socket(max_apicid)) { + case 0: case 1: + /* 1 and 2 socket systems use default ivt_cstates = */ + break; + case 2: case 3: + cpuidle_state_table =3D ivt_cstates_4s; + break; + default: + cpuidle_state_table =3D ivt_cstates_8s; + break; + } + } +} + static int __init mwait_idle_probe(void) { unsigned int eax, ebx, ecx; @@ -578,6 +698,9 @@ static int __init mwait_idle_probe(void) =20 pr_debug(PREFIX "lapic_timer_reliable_states %#x\n", lapic_timer_reliable_states); + + mwait_idle_state_table_update(); + return 0; } =20 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -152,6 +152,11 @@ static void __cpuinit get_cpu_vendor(str this_cpu =3D &default_cpu; } =20 +static inline u32 _phys_pkg_id(u32 cpuid_apic, int index_msb) +{ + return cpuid_apic >> index_msb; +} + /* * cpuid returns the value latched in the HW at reset, not the APIC ID * register's value. For any box whose BIOS changes APIC IDs, like @@ -161,7 +166,7 @@ static void __cpuinit get_cpu_vendor(str */ static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) { - return hard_smp_processor_id() >> index_msb; + return _phys_pkg_id(hard_smp_processor_id(), index_msb); } =20 /* Do minimum CPU detection early. @@ -471,6 +476,43 @@ void __cpuinit detect_ht(struct cpuinfo_ } #endif =20 +unsigned int __init apicid_to_socket(unsigned int apicid) +{ + unsigned int dummy; + + if (boot_cpu_has(X86_FEATURE_XTOPOLOGY)) { + unsigned int eax, ecx, sub_index =3D 1, core_plus_mask_widt= h; + + cpuid_count(0xb, SMT_LEVEL, &eax, &dummy, &dummy, &dummy); + core_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); + do { + cpuid_count(0xb, sub_index, &eax, &dummy, &ecx, + &dummy); + + if (LEAFB_SUBTYPE(ecx) =3D=3D CORE_TYPE) { + core_plus_mask_width =3D + BITS_SHIFT_NEXT_LEVEL(eax); + break; + } + + sub_index++; + } while (LEAFB_SUBTYPE(ecx) !=3D INVALID_TYPE); + + return _phys_pkg_id(apicid, core_plus_mask_width); + } + + if (boot_cpu_has(X86_FEATURE_HT) && + !boot_cpu_has(X86_FEATURE_CMP_LEGACY)) { + unsigned int num_siblings =3D (cpuid_ebx(1) & 0xff0000) >> = 16; + + if (num_siblings) + return _phys_pkg_id(apicid, + get_count_order(num_siblings));= + } + + return apicid; +} + void __cpuinit print_cpu_info(unsigned int cpu) { const struct cpuinfo_x86 *c =3D cpu_data + cpu; --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -220,6 +220,8 @@ static always_inline void detect_ht(stru #define cpu_to_core(_cpu) (cpu_data[_cpu].cpu_core_id) #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id) =20 +unsigned int apicid_to_socket(unsigned int); + /* * Generic CPUID function * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx --=__Part2A18DF4E.0__= Content-Type: text/plain; name="x86-mwait-IvyTown.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mwait-IvyTown.patch" mwait-idle: fine-tune IVT residency targets=0A=0AIvy Town processors have = slightly different properties=0Athan Ivy Bridge processors, particuarly as = socket count grows.=0AHere we add dedicated tables covering 1-2 socket,=0A3= -4 socket, and > 4 socket IVT configurations.=0A=0AThis reduces the = frequency of deep transitions on those systems,=0Awhich can impact = throughput.=0A=0ASigned-off-by: Len Brown =0A=0ASocket= count determination needs to be done differently for us: The=0Arelevant = code runs in a pre-SMP initcall, and hence can't use=0Acpu_to_socket() (as = only the boot CPU's cpu_data[].phys_proc_id got set=0Aup by that time). As = a replacement the patch introduces=0Aapicid_to_socket(), thus estimating = the socket count based on the boot=0ACPU's internal topology information = (if all CPUs in a system are the=0Asame, wich ought to be the common case, = this estimate will be precise).=0A=0ANote that apicid_to_socket() handles = Intel topology determination only=0Afor now, as the mwait-idle driver = currently only supports Intel CPUs.=0A=0ASigned-off-by: Jan Beulich = =0A---=0AThis requires the patch at=0Ahttp://lists.xenpr= oject.org/archives/html/xen-devel/2014-06/msg03335.html=0Aas a prerequisite= .=0A=0A--- a/xen/arch/x86/cpu/mwait-idle.c=0A+++ b/xen/arch/x86/cpu/mwait-i= dle.c=0A@@ -261,6 +261,90 @@ static const struct cpuidle_state ivb_cs=0A = {}=0A };=0A =0A+static const struct cpuidle_state ivt_cstates[] =3D {=0A+ = {=0A+ .name =3D "C1-IVT",=0A+ .flags =3D MWAIT2flg(0x00),= =0A+ .exit_latency =3D 1,=0A+ .target_residency = =3D 1,=0A+ },=0A+ {=0A+ .name =3D "C1E-IVT",=0A+ = .flags =3D MWAIT2flg(0x01),=0A+ .exit_latency =3D 10,=0A+ = .target_residency =3D 80,=0A+ },=0A+ {=0A+ .name =3D = "C3-IVT",=0A+ .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSH= ED,=0A+ .exit_latency =3D 59,=0A+ .target_residency = =3D 156,=0A+ },=0A+ {=0A+ .name =3D "C6-IVT",=0A+ = .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,=0A+ = .exit_latency =3D 82,=0A+ .target_residency =3D 300,=0A+ = },=0A+ {}=0A+};=0A+=0A+static const struct cpuidle_state ivt_cstates_4s[] = =3D {=0A+ {=0A+ .name =3D "C1-IVT-4S",=0A+ = .flags =3D MWAIT2flg(0x00),=0A+ .exit_latency =3D 1,=0A+ = .target_residency =3D 1,=0A+ },=0A+ {=0A+ .name =3D = "C1E-IVT-4S",=0A+ .flags =3D MWAIT2flg(0x01),=0A+ = .exit_latency =3D 10,=0A+ .target_residency =3D 250,=0A+ = },=0A+ {=0A+ .name =3D "C3-IVT-4S",=0A+ .flags =3D = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,=0A+ .exit_latency =3D = 59,=0A+ .target_residency =3D 300,=0A+ },=0A+ {=0A+ = .name =3D "C6-IVT-4S",=0A+ .flags =3D MWAIT2flg(0x20) | = CPUIDLE_FLAG_TLB_FLUSHED,=0A+ .exit_latency =3D 84,=0A+ = .target_residency =3D 400,=0A+ },=0A+ {}=0A+};=0A+=0A+static const = struct cpuidle_state ivt_cstates_8s[] =3D {=0A+ {=0A+ .name =3D = "C1-IVT-8S",=0A+ .flags =3D MWAIT2flg(0x00),=0A+ = .exit_latency =3D 1,=0A+ .target_residency =3D 1,=0A+ = },=0A+ {=0A+ .name =3D "C1E-IVT-8S",=0A+ .flags =3D = MWAIT2flg(0x01),=0A+ .exit_latency =3D 10,=0A+ = .target_residency =3D 500,=0A+ },=0A+ {=0A+ .name =3D = "C3-IVT-8S",=0A+ .flags =3D MWAIT2flg(0x10) | CPUIDLE_FLAG_T= LB_FLUSHED,=0A+ .exit_latency =3D 59,=0A+ .target_res= idency =3D 600,=0A+ },=0A+ {=0A+ .name =3D "C6-IVT-8S",=0A+ = .flags =3D MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,=0A+ = .exit_latency =3D 88,=0A+ .target_residency =3D 700,=0A+ = },=0A+ {}=0A+};=0A+=0A static const struct cpuidle_state hsw_cstates[] = =3D {=0A {=0A .name =3D "C1-HSW",=0A@@ -494,6 +578,11 @@ = static const struct idle_cpu idle_cpu_iv=0A .disable_promotion_to_c1e = =3D 1,=0A };=0A =0A+static const struct idle_cpu idle_cpu_ivt =3D {=0A+ = .state_table =3D ivt_cstates,=0A+ .disable_promotion_to_c1e =3D = 1,=0A+};=0A+=0A static const struct idle_cpu idle_cpu_hsw =3D {=0A = .state_table =3D hsw_cstates,=0A .disable_promotion_to_c1e =3D = 1,=0A@@ -524,7 +613,7 @@ static struct intel_idle_id {=0A ICPU(0x36, = atom),=0A ICPU(0x37, byt),=0A ICPU(0x3a, ivb),=0A- ICPU(0x3e, = ivb),=0A+ ICPU(0x3e, ivt),=0A ICPU(0x3c, hsw),=0A ICPU(0x3f, = hsw),=0A ICPU(0x45, hsw),=0A@@ -533,6 +622,37 @@ static struct = intel_idle_id {=0A {}=0A };=0A =0A+/*=0A+ * mwait_idle_state_table_upd= ate()=0A+ *=0A+ * Update the default state_table for this CPU-id=0A+ *=0A+ = * Currently used to access tuned IVT multi-socket targets=0A+ * Assumption:= num_sockets =3D=3D (max_package_num + 1)=0A+ */=0A+static void __init = mwait_idle_state_table_update(void)=0A+{=0A+ /* IVT uses a different = table for 1-2, 3-4, and > 4 sockets */=0A+ if (boot_cpu_data.x86_model= =3D=3D 0x3e) { /* IVT */=0A+ unsigned int cpu, max_apicid =3D = boot_cpu_physical_apicid;=0A+=0A+ for_each_present_cpu(cpu)= =0A+ if (max_apicid < x86_cpu_to_apicid[cpu])=0A+ = max_apicid =3D x86_cpu_to_apicid[cpu];=0A+ = switch (apicid_to_socket(max_apicid)) {=0A+ case 0: case = 1:=0A+ /* 1 and 2 socket systems use default ivt_cstates = */=0A+ break;=0A+ case 2: case 3:=0A+ = cpuidle_state_table =3D ivt_cstates_4s;=0A+ = break;=0A+ default:=0A+ cpuidle_state_table= =3D ivt_cstates_8s;=0A+ break;=0A+ = }=0A+ }=0A+}=0A+=0A static int __init mwait_idle_probe(void)=0A {=0A = unsigned int eax, ebx, ecx;=0A@@ -578,6 +698,9 @@ static int __init = mwait_idle_probe(void)=0A =0A pr_debug(PREFIX "lapic_timer_reliable_state= s %#x\n",=0A lapic_timer_reliable_states);=0A+=0A+ mwait_idle_= state_table_update();=0A+=0A return 0;=0A }=0A =0A--- a/xen/arch/x86/cpu= /common.c=0A+++ b/xen/arch/x86/cpu/common.c=0A@@ -152,6 +152,11 @@ static = void __cpuinit get_cpu_vendor(str=0A this_cpu =3D &default_cpu;=0A }=0A = =0A+static inline u32 _phys_pkg_id(u32 cpuid_apic, int index_msb)=0A+{=0A+ = return cpuid_apic >> index_msb;=0A+}=0A+=0A /*=0A * cpuid returns the = value latched in the HW at reset, not the APIC ID=0A * register's value. = For any box whose BIOS changes APIC IDs, like=0A@@ -161,7 +166,7 @@ static = void __cpuinit get_cpu_vendor(str=0A */=0A static inline u32 phys_pkg_id(u= 32 cpuid_apic, int index_msb)=0A {=0A- return hard_smp_processor_id() >> = index_msb;=0A+ return _phys_pkg_id(hard_smp_processor_id(), index_msb);=0A= }=0A =0A /* Do minimum CPU detection early.=0A@@ -471,6 +476,43 @@ void = __cpuinit detect_ht(struct cpuinfo_=0A }=0A #endif=0A =0A+unsigned int = __init apicid_to_socket(unsigned int apicid)=0A+{=0A+ unsigned int = dummy;=0A+=0A+ if (boot_cpu_has(X86_FEATURE_XTOPOLOGY)) {=0A+ = unsigned int eax, ecx, sub_index =3D 1, core_plus_mask_width;=0A+=0A+ = cpuid_count(0xb, SMT_LEVEL, &eax, &dummy, &dummy, &dummy);=0A+ = core_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax);=0A+ do = {=0A+ cpuid_count(0xb, sub_index, &eax, &dummy, = &ecx,=0A+ &dummy);=0A+=0A+ = if (LEAFB_SUBTYPE(ecx) =3D=3D CORE_TYPE) {=0A+ = core_plus_mask_width =3D=0A+ BITS_SHIFT_= NEXT_LEVEL(eax);=0A+ break;=0A+ = }=0A+=0A+ sub_index++;=0A+ } while = (LEAFB_SUBTYPE(ecx) !=3D INVALID_TYPE);=0A+=0A+ return _phys_pkg_id= (apicid, core_plus_mask_width);=0A+ }=0A+=0A+ if (boot_cpu_has(X8= 6_FEATURE_HT) &&=0A+ !boot_cpu_has(X86_FEATURE_CMP_LEGACY)) {=0A+ = unsigned int num_siblings =3D (cpuid_ebx(1) & 0xff0000) >> = 16;=0A+=0A+ if (num_siblings)=0A+ return = _phys_pkg_id(apicid,=0A+ = get_count_order(num_siblings));=0A+ }=0A+=0A+ return apicid;=0A+}= =0A+=0A void __cpuinit print_cpu_info(unsigned int cpu)=0A {=0A = const struct cpuinfo_x86 *c =3D cpu_data + cpu;=0A--- a/xen/include/asm-x86= /processor.h=0A+++ b/xen/include/asm-x86/processor.h=0A@@ -220,6 +220,8 @@ = static always_inline void detect_ht(stru=0A #define cpu_to_core(_cpu) = (cpu_data[_cpu].cpu_core_id)=0A #define cpu_to_socket(_cpu) (cpu_data[_cpu]= .phys_proc_id)=0A =0A+unsigned int apicid_to_socket(unsigned int);=0A+=0A = /*=0A * Generic CPUID function=0A * clear %ecx since some cpus (Cyrix = MII) do not set or clear %ecx=0A --=__Part2A18DF4E.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 --=__Part2A18DF4E.0__=--