qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Nina Schoetterl-Glausch <nsg@linux.ibm.com>,
	qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
	Eduardo Habkost <eduardo@habkost.net>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	David Hildenbrand <david@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Michael Roth <michael.roth@amd.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Beraldo Leal" <bleal@redhat.com>,
	"Pierre Morel" <pmorel@linux.ibm.com>
Subject: Re: [PATCH v22 02/20] s390x/cpu topology: add topology entries on CPU hotplug
Date: Tue, 5 Sep 2023 14:28:45 +0200	[thread overview]
Message-ID: <559e78ac-adff-721b-13ea-aae1de1e9dd5@redhat.com> (raw)
In-Reply-To: <20230901155812.2696560-3-nsg@linux.ibm.com>

On 01/09/2023 17.57, Nina Schoetterl-Glausch wrote:
> From: Pierre Morel <pmorel@linux.ibm.com>
> 
> The topology information are attributes of the CPU and are
> specified during the CPU device creation.
> 
> On hot plug we:
> - calculate the default values for the topology for drawers,
>    books and sockets in the case they are not specified.
> - verify the CPU attributes
> - check that we have still room on the desired socket
> 
> The possibility to insert a CPU in a mask is dependent on the
> number of cores allowed in a socket, a book or a drawer, the
> checking is done during the hot plug of the CPU to have an
> immediate answer.
> 
> If the complete topology is not specified, the core is added
> in the physical topology based on its core ID and it gets
> defaults values for the modifier attributes.
> 
> This way, starting QEMU without specifying the topology can
> still get some advantage of the CPU topology.
> 
> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
> Reviewed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> ---
...
> +/**
> + * s390_topology_cpu_default:
> + * @cpu: pointer to a S390CPU
> + * @errp: Error pointer
> + *
> + * Setup the default topology if no attributes are already set.
> + * Passing a CPU with some, but not all, attributes set is considered
> + * an error.
> + *
> + * The function calculates the (drawer_id, book_id, socket_id)
> + * topology by filling the cores starting from the first socket
> + * (0, 0, 0) up to the last (smp->drawers, smp->books, smp->sockets).
> + *
> + * CPU type and dedication have defaults values set in the
> + * s390x_cpu_properties, entitlement must be adjust depending on the
> + * dedication.
> + *
> + * Returns false if it is impossible to setup a default topology
> + * true otherwise.
> + */
> +static bool s390_topology_cpu_default(S390CPU *cpu, Error **errp)
> +{
> +    CpuTopology *smp = &current_machine->smp;
> +    CPUS390XState *env = &cpu->env;
> +
> +    /* All geometry topology attributes must be set or all unset */
> +    if ((env->socket_id < 0 || env->book_id < 0 || env->drawer_id < 0) &&
> +        (env->socket_id >= 0 || env->book_id >= 0 || env->drawer_id >= 0)) {
> +        error_setg(errp,
> +                   "Please define all or none of the topology geometry attributes");
> +        return false;
> +    }
> +
> +    /* Check if one of the geometry topology is unset */

The comment isn't too helpful - maybe rather something like this:
"If one value of the topology is still unset, this means that now that all 
of them are unset, so calculate  the default attributes now." (and then 
remove also the comment within the curly braces below)

> +    if (env->socket_id < 0) {
> +        /* Calculate default geometry topology attributes */
> +        env->socket_id = s390_std_socket(env->core_id, smp);
> +        env->book_id = s390_std_book(env->core_id, smp);
> +        env->drawer_id = s390_std_drawer(env->core_id, smp);
> +    }
> +
> +    /*
> +     * When the user specifies the entitlement as 'auto' on the command line,
> +     * QEMU will set the entitlement as:
> +     * Medium when the CPU is not dedicated.
> +     * High when dedicated is true.
> +     */
> +    if (env->entitlement == S390_CPU_ENTITLEMENT_AUTO) {
> +        if (env->dedicated) {
> +            env->entitlement = S390_CPU_ENTITLEMENT_HIGH;
> +        } else {
> +            env->entitlement = S390_CPU_ENTITLEMENT_MEDIUM;
> +        }
> +    }
> +    return true;
> +}
> +
> +/**
> + * s390_topology_check:
> + * @socket_id: socket to check
> + * @book_id: book to check
> + * @drawer_id: drawer to check
> + * @entitlement: entitlement to check
> + * @dedicated: dedication to check
> + * @errp: Error pointer
> + *
> + * The function checks if the topology
> + * attributes fits inside the system topology.
> + *
> + * Returns false if the specified topology does not match with
> + * the machine topology.
> + */
> +static bool s390_topology_check(uint16_t socket_id, uint16_t book_id,
> +                                uint16_t drawer_id, uint16_t entitlement,
> +                                bool dedicated, Error **errp)
> +{
> +    CpuTopology *smp = &current_machine->smp;
> +    ERRP_GUARD();

No need for ERRP_GUARD() here, I think.

> +    if (socket_id >= smp->sockets) {
> +        error_setg(errp, "Unavailable socket: %d", socket_id);
> +        return false;
> +    }
> +    if (book_id >= smp->books) {
> +        error_setg(errp, "Unavailable book: %d", book_id);
> +        return false;
> +    }
> +    if (drawer_id >= smp->drawers) {
> +        error_setg(errp, "Unavailable drawer: %d", drawer_id);
> +        return false;
> +    }
> +    if (entitlement >= S390_CPU_ENTITLEMENT__MAX) {
> +        error_setg(errp, "Unknown entitlement: %d", entitlement);
> +        return false;
> +    }
> +    if (dedicated && (entitlement == S390_CPU_ENTITLEMENT_LOW ||
> +                      entitlement == S390_CPU_ENTITLEMENT_MEDIUM)) {
> +        error_setg(errp, "A dedicated CPU implies high entitlement");
> +        return false;
> +    }
> +    return true;
> +}
> +
> +/**
> + * s390_update_cpu_props:
> + * @ms: the machine state
> + * @cpu: the CPU for which to update the properties from the environment.
> + *
> + */
> +static void s390_update_cpu_props(MachineState *ms, S390CPU *cpu)
> +{
> +    CpuInstanceProperties *props;
> +
> +    props = &ms->possible_cpus->cpus[cpu->env.core_id].props;
> +
> +    props->socket_id = cpu->env.socket_id;
> +    props->book_id = cpu->env.book_id;
> +    props->drawer_id = cpu->env.drawer_id;
> +}
> +
> +/**
> + * s390_topology_setup_cpu:
> + * @ms: MachineState used to initialize the topology structure on
> + *      first call.
> + * @cpu: the new S390CPU to insert in the topology structure
> + * @errp: the error pointer
> + *
> + * Called from CPU hotplug to check and setup the CPU attributes
> + * before the CPU is inserted in the topology.
> + * There is no need to update the MTCR explicitly here because it
> + * will be updated by KVM on creation of the new CPU.
> + */
> +void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp)
> +{
> +    ERRP_GUARD();

I think ERRP_GUARD is also not necessary here?

> +    int entry;
> +
> +    /*
> +     * We do not want to initialize the topology if the CPU model
> +     * does not support topology, consequently, we have to wait for
> +     * the first CPU to be realized, which realizes the CPU model
> +     * to initialize the topology structures.
> +     *
> +     * s390_topology_setup_cpu() is called from the CPU hotplug.
> +     */
> +    if (!s390_topology.cores_per_socket) {
> +        s390_topology_init(ms);
> +    }
> +
> +    if (!s390_topology_cpu_default(cpu, errp)) {
> +        return;
> +    }
> +
> +    if (!s390_topology_check(cpu->env.socket_id, cpu->env.book_id,
> +                             cpu->env.drawer_id, cpu->env.entitlement,
> +                             cpu->env.dedicated, errp)) {
> +        return;
> +    }
> +
> +    /* Do we still have space in the socket */
> +    entry = s390_socket_nb(cpu);
> +    if (s390_topology.cores_per_socket[entry] >= current_machine->smp.cores) {
> +        error_setg(errp, "No more space on this socket");
> +        return;
> +    }
> +
> +    /* Update the count of cores in sockets */
> +    s390_topology.cores_per_socket[entry] += 1;
> +
> +    /* topology tree is reflected in props */
> +    s390_update_cpu_props(ms, cpu);
> +}

Anyway, with or without the nits fixed, this looks fine to me, so:

Reviewed-by: Thomas Huth <thuth@redhat.com>



  reply	other threads:[~2023-09-05 12:29 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 15:57 [PATCH v22 00/20] s390x: CPU Topology Nina Schoetterl-Glausch
2023-09-01 15:57 ` [PATCH v22 01/20] CPU topology: extend with s390 specifics Nina Schoetterl-Glausch
2023-09-05  9:01   ` Thomas Huth
2023-09-01 15:57 ` [PATCH v22 02/20] s390x/cpu topology: add topology entries on CPU hotplug Nina Schoetterl-Glausch
2023-09-05 12:28   ` Thomas Huth [this message]
2023-09-01 15:57 ` [PATCH v22 03/20] target/s390x/cpu topology: handle STSI(15) and build the SYSIB Nina Schoetterl-Glausch
2023-09-04 18:23   ` Nina Schoetterl-Glausch
2023-09-05 13:26   ` Thomas Huth
2023-09-05 15:25     ` Nina Schoetterl-Glausch
2023-09-06  8:21       ` Thomas Huth
2023-09-06 12:12         ` Nina Schoetterl-Glausch
2023-09-06 14:53   ` Cédric Le Goater
2023-09-01 15:57 ` [PATCH v22 04/20] s390x/sclp: reporting the maximum nested topology entries Nina Schoetterl-Glausch
2023-09-01 15:57 ` [PATCH v22 05/20] s390x/cpu topology: resetting the Topology-Change-Report Nina Schoetterl-Glausch
2023-09-01 15:57 ` [PATCH v22 06/20] s390x/cpu topology: interception of PTF instruction Nina Schoetterl-Glausch
2023-09-01 15:57 ` [PATCH v22 07/20] target/s390x/cpu topology: activate CPU topology Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 08/20] qapi/s390x/cpu topology: set-cpu-topology qmp command Nina Schoetterl-Glausch
2023-09-06  8:56   ` Thomas Huth
2023-09-01 15:58 ` [PATCH v22 09/20] machine: adding s390 topology to query-cpu-fast Nina Schoetterl-Glausch
2023-09-06  9:10   ` Thomas Huth
2023-09-01 15:58 ` [PATCH v22 10/20] machine: adding s390 topology to info hotpluggable-cpus Nina Schoetterl-Glausch
2023-09-06  9:14   ` Thomas Huth
2023-09-01 15:58 ` [PATCH v22 11/20] qapi/s390x/cpu topology: CPU_POLARIZATION_CHANGE qapi event Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 12/20] qapi/s390x/cpu topology: query-cpu-polarization qmp command Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 13/20] docs/s390x/cpu topology: document s390x cpu topology Nina Schoetterl-Glausch
2023-09-07  8:15   ` Thomas Huth
2023-09-01 15:58 ` [PATCH v22 14/20] tests/avocado: s390x cpu topology core Nina Schoetterl-Glausch
2023-09-04 18:44   ` Nina Schoetterl-Glausch
2023-09-07  8:27   ` Thomas Huth
2023-09-08 14:27     ` Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 15/20] tests/avocado: s390x cpu topology polarization Nina Schoetterl-Glausch
2023-09-04 19:43   ` Nina Schoetterl-Glausch
2023-09-07  9:02   ` Thomas Huth
2023-09-08 14:47     ` Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 16/20] tests/avocado: s390x cpu topology entitlement tests Nina Schoetterl-Glausch
2023-09-04 19:51   ` Nina Schoetterl-Glausch
2023-09-07  9:05   ` Thomas Huth
2023-09-08 18:30     ` Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 17/20] tests/avocado: s390x cpu topology test dedicated CPU Nina Schoetterl-Glausch
2023-09-04 19:54   ` Nina Schoetterl-Glausch
2023-09-07 10:08   ` Thomas Huth
2023-09-01 15:58 ` [PATCH v22 18/20] tests/avocado: s390x cpu topology test socket full Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 19/20] tests/avocado: s390x cpu topology dedicated errors Nina Schoetterl-Glausch
2023-09-01 15:58 ` [PATCH v22 20/20] tests/avocado: s390x cpu topology bad move Nina Schoetterl-Glausch

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=559e78ac-adff-721b-13ea-aae1de1e9dd5@redhat.com \
    --to=thuth@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=bleal@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=crosa@redhat.com \
    --cc=david@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=nsg@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pmorel@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=wainersm@redhat.com \
    --cc=wangyanan55@huawei.com \
    /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).