qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Babu Moger <babu.moger@amd.com>
Cc: mst@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com,
	rth@twiddle.net, mtosatti@redhat.com, qemu-devel@nongnu.org,
	kvm@vger.kernel.org, kash@tripleback.net, geoff@hostfission.com
Subject: Re: [Qemu-devel] [PATCH v13 4/5] i386: Verify and enable topoext feature if supported
Date: Mon, 11 Jun 2018 17:51:59 -0300	[thread overview]
Message-ID: <20180611205159.GX7451@localhost.localdomain> (raw)
In-Reply-To: <1528498581-131037-5-git-send-email-babu.moger@amd.com>

On Fri, Jun 08, 2018 at 06:56:20PM -0400, Babu Moger wrote:
> If the CPU model supports topoext feature, enabled the
> feature automatically if it can be supported.
> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
>  target/i386/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 4dd9a82..88bc73d 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -4763,6 +4763,33 @@ static int x86_cpu_filter_features(X86CPU *cpu)
>  #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
>                           (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
>                           (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
> +/*
> + * Check if we can support this topology
> + * Fail if number of cores are beyond the supported config
> + * or nr_threads is more than 2
> + */
> +static int topology_supports_topoext(int nr_cores, int nr_threads,
> +            Error **errp)
> +{
> +    if (nr_cores > (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET)) {
> +        error_setg(errp, "TOPOEXT unsupported with %d cores per socket",
> +                   nr_cores);
> +        error_append_hint(errp, "TOPOEXT supports only up to %d cores per"
> +                          " socket\n",
> +                          (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET));
> +        return false;
> +    }
> +
> +    if (nr_threads > 2) {
> +        error_setg(errp, "TOPOEXT unsupported with %d threads per core",
> +                   nr_threads);
> +        error_append_hint(errp, "TOPOEXT supports only up to 2 threads"
> +                          " per core\n");
> +        return false;
> +    }
> +    return true;
> +}
> +
>  static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
>  {
>      CPUState *cs = CPU(dev);
> @@ -4953,6 +4980,19 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
>  
>      qemu_init_vcpu(cs);
>  
> +    if (cpu->auto_topoext &&
> +        !(env->user_features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT)) {
> +        if (cs->nr_cores <= (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET) &&
> +            (cs->nr_threads <= 2)) {

This duplicates the logic from topology_supports_topoext().  Why
not just call
  topology_supports_topoext(cs->nr_cores, cs->nr_threads, NULL)
here?

> +            env->features[FEAT_8000_0001_ECX] |= CPUID_EXT3_TOPOEXT;
> +        }
> +    }
> +
> +    if ((env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) &&
> +        !topology_supports_topoext(cs->nr_cores, cs->nr_threads, errp)) {
> +        return;
> +    }
> +
>      /* Only Intel CPUs support hyperthreading. Even though QEMU fixes this
>       * issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
>       * based on inputs (sockets,cores,threads), it is still better to gives
> -- 
> 1.8.3.1
> 

-- 
Eduardo

  reply	other threads:[~2018-06-11 20:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 22:56 [Qemu-devel] [PATCH v13 0/5] i386: Enable TOPOEXT to support hyperthreading on AMD CPU Babu Moger
2018-06-08 22:56 ` [Qemu-devel] [PATCH v13 1/5] i386: Add support for CPUID_8000_001E for AMD Babu Moger
2018-06-11 20:54   ` Eduardo Habkost
2018-06-11 21:02     ` Moger, Babu
2020-06-02 17:52   ` Eduardo Habkost
2020-06-03 23:57     ` Babu Moger
2020-06-04 14:06     ` Babu Moger
2020-06-04 20:54       ` Eduardo Habkost
2020-06-05 16:21         ` Babu Moger
2018-06-08 22:56 ` [Qemu-devel] [PATCH v13 2/5] i386: Introduce auto_topoext bit to manage topoext Babu Moger
2018-06-11 20:25   ` Moger, Babu
2018-06-11 20:46     ` Eduardo Habkost
2018-06-11 20:59       ` Moger, Babu
2018-06-11 21:05       ` Eduardo Habkost
2018-06-11 21:20         ` Moger, Babu
2018-06-08 22:56 ` [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU Babu Moger
2018-06-11 20:50   ` Eduardo Habkost
2018-06-11 21:01     ` Moger, Babu
2018-06-11 21:10     ` Eduardo Habkost
2018-06-12 16:29       ` Moger, Babu
2018-06-12 17:40         ` Eduardo Habkost
2018-06-12 18:38           ` Moger, Babu
2018-06-12 19:05             ` Eduardo Habkost
2018-06-12 19:46               ` Babu Moger
2018-06-13 16:52                 ` Moger, Babu
2018-06-13 17:18                   ` Eduardo Habkost
2018-06-13 18:10                     ` Moger, Babu
2018-06-13 18:12                       ` Moger, Babu
2018-06-13 18:17                       ` Eduardo Habkost
2018-06-13 18:21                         ` Moger, Babu
2018-06-13 18:49                           ` Eduardo Habkost
2018-06-14  0:58                             ` Moger, Babu
2018-06-08 22:56 ` [Qemu-devel] [PATCH v13 4/5] i386: Verify and enable topoext feature if supported Babu Moger
2018-06-11 20:51   ` Eduardo Habkost [this message]
2018-06-11 21:01     ` Moger, Babu
2018-06-08 22:56 ` [Qemu-devel] [PATCH v13 5/5] i386: Remove generic SMT thread check Babu Moger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180611205159.GX7451@localhost.localdomain \
    --to=ehabkost@redhat.com \
    --cc=babu.moger@amd.com \
    --cc=geoff@hostfission.com \
    --cc=kash@tripleback.net \
    --cc=kvm@vger.kernel.org \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).