From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <groug@kaod.org>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [Qemu-devel] [PATCH 4/5] spapr_cpu_core: introduce spapr_create_vcpu()
Date: Fri, 15 Jun 2018 10:05:26 +1000 [thread overview]
Message-ID: <20180615000526.GD4129@umbus.fritz.box> (raw)
In-Reply-To: <152901305726.252222.7317082325256499414.stgit@bahia.lan>
[-- Attachment #1: Type: text/plain, Size: 4043 bytes --]
On Thu, Jun 14, 2018 at 11:50:57PM +0200, Greg Kurz wrote:
> This moves some code out from spapr_cpu_core_realize() for clarity. No
> functional change.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
Applied to ppc-for-3.0, thanks.
> ---
> hw/ppc/spapr_cpu_core.c | 73 +++++++++++++++++++++++++++++------------------
> 1 file changed, 45 insertions(+), 28 deletions(-)
>
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 04c818a6ecac..0ebaf804a9bc 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -172,6 +172,49 @@ error:
> error_propagate(errp, local_err);
> }
>
> +static PowerPCCPU *spapr_create_vcpu(sPAPRCPUCore *sc, int i, Error **errp)
> +{
> + sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc);
> + CPUCore *cc = CPU_CORE(sc);
> + Object *obj;
> + char *id;
> + CPUState *cs;
> + PowerPCCPU *cpu;
> + Error *local_err = NULL;
> +
> + obj = object_new(scc->cpu_type);
> +
> + cs = CPU(obj);
> + cpu = POWERPC_CPU(obj);
> + cs->cpu_index = cc->core_id + i;
> + spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
> + if (local_err) {
> + goto err;
> + }
> +
> + cpu->node_id = sc->node_id;
> +
> + id = g_strdup_printf("thread[%d]", i);
> + object_property_add_child(OBJECT(sc), id, obj, &local_err);
> + g_free(id);
> + if (local_err) {
> + goto err;
> + }
> +
> + object_unref(obj);
> + return cpu;
> +
> +err:
> + object_unref(obj);
> + error_propagate(errp, local_err);
> + return NULL;
> +}
> +
> +static void spapr_delete_vcpu(PowerPCCPU *cpu)
> +{
> + object_unparent(OBJECT(cpu));
> +}
> +
> static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
> {
> /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user
> @@ -181,10 +224,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
> (sPAPRMachineState *) object_dynamic_cast(qdev_get_machine(),
> TYPE_SPAPR_MACHINE);
> sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
> - sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(OBJECT(dev));
> CPUCore *cc = CPU_CORE(OBJECT(dev));
> Error *local_err = NULL;
> - Object *obj;
> int i, j;
>
> if (!spapr) {
> @@ -194,33 +235,10 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
>
> sc->threads = g_new(PowerPCCPU *, cc->nr_threads);
> for (i = 0; i < cc->nr_threads; i++) {
> - char *id;
> - CPUState *cs;
> - PowerPCCPU *cpu;
> -
> - obj = object_new(scc->cpu_type);
> -
> - cs = CPU(obj);
> - cpu = sc->threads[i] = POWERPC_CPU(obj);
> - cs->cpu_index = cc->core_id + i;
> - spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
> - if (local_err) {
> - object_unref(obj);
> - goto err;
> - }
> -
> -
> - /* Set NUMA node for the threads belonged to core */
> - cpu->node_id = sc->node_id;
> -
> - id = g_strdup_printf("thread[%d]", i);
> - object_property_add_child(OBJECT(sc), id, obj, &local_err);
> - g_free(id);
> + sc->threads[i] = spapr_create_vcpu(sc, i, &local_err);
> if (local_err) {
> - object_unref(obj);
> goto err;
> }
> - object_unref(obj);
> }
>
> for (j = 0; j < cc->nr_threads; j++) {
> @@ -237,8 +255,7 @@ err_unrealize:
> }
> err:
> while (--i >= 0) {
> - obj = OBJECT(sc->threads[i]);
> - object_unparent(obj);
> + spapr_delete_vcpu(sc->threads[i]);
> }
> g_free(sc->threads);
> error_propagate(errp, local_err);
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-06-15 0:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-14 21:49 [Qemu-devel] [PATCH 0/5] spapr_cpu_core: fixes and cleanups Greg Kurz
2018-06-14 21:50 ` [Qemu-devel] [PATCH 1/5] spapr_cpu_core: convert last snprintf() to g_strdup_printf() Greg Kurz
2018-06-14 23:59 ` David Gibson
2018-06-14 21:50 ` [Qemu-devel] [PATCH 2/5] spapr_cpu_core: fix potential leak in spapr_cpu_core_realize() Greg Kurz
2018-06-14 23:59 ` David Gibson
2018-06-14 21:50 ` [Qemu-devel] [PATCH 3/5] spapr_cpu_core: add missing rollback on realization path Greg Kurz
2018-06-15 0:02 ` David Gibson
2018-06-15 0:14 ` David Gibson
2018-06-15 5:58 ` Greg Kurz
2018-06-15 6:29 ` David Gibson
2018-06-15 7:07 ` Greg Kurz
2018-06-15 8:01 ` Greg Kurz
2018-06-15 12:32 ` David Gibson
2018-06-15 13:24 ` Greg Kurz
2018-06-16 6:26 ` David Gibson
2018-06-15 5:53 ` Greg Kurz
2018-06-15 6:27 ` David Gibson
2018-06-14 21:50 ` [Qemu-devel] [PATCH 4/5] spapr_cpu_core: introduce spapr_create_vcpu() Greg Kurz
2018-06-15 0:05 ` David Gibson [this message]
2018-06-14 21:51 ` [Qemu-devel] [PATCH 5/5] spapr_cpu_core: simplify spapr_cpu_core_realize() Greg Kurz
2018-06-15 0:08 ` David Gibson
2018-06-15 6:57 ` Greg Kurz
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=20180615000526.GD4129@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=clg@kaod.org \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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).