qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Nicholas Piggin <npiggin@gmail.com>, qemu-ppc@nongnu.org
Cc: "Frédéric Barrat" <fbarrat@linux.ibm.com>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v2 10/19] ppc/pnv: Add a big-core mode that joins two regular cores
Date: Sat, 13 Jul 2024 09:19:42 +0200	[thread overview]
Message-ID: <4f0e918b-336f-4423-bc48-25607662eabc@kaod.org> (raw)
In-Reply-To: <20240712120247.477133-11-npiggin@gmail.com>

On 7/12/24 14:02, Nicholas Piggin wrote:
> POWER9 and POWER10 machines come in two variants, big-core and
> small-core. Big-core machines are SMT8 from software's point of view,
> but the low level platform topology ("xscom registers and pervasive
> addressing"), these look more like a pair of small cores ganged
> together.
> 
> Presently the way this is modelled is to create one SMT8 PnvCore and add
> special cases to xscom and pervasive for big-core mode that tries to
> split this into two small cores, but this is becoming too complicated to
> manage.
> 
> A better approach is to create 2 core structures and ganging them
> together to look like an SMT8 core in TCG. Then the xscom and pervasive
> models mostly do not need to differentiate big and small core modes.
> 
> This change adds initial mode bits and QEMU topology handling to
> split SMT8 cores into 2xSMT4 cores.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>


Looks good. See some proposal below,


> ---
>   include/hw/ppc/pnv.h      |  2 +
>   include/hw/ppc/pnv_chip.h |  1 +
>   include/hw/ppc/pnv_core.h |  1 +
>   hw/ppc/pnv.c              | 77 ++++++++++++++++++++++++++++++++-------
>   hw/ppc/pnv_core.c         |  7 +++-
>   5 files changed, 74 insertions(+), 14 deletions(-)
> 
> diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
> index 1993dededf..283ddd50e7 100644
> --- a/include/hw/ppc/pnv.h
> +++ b/include/hw/ppc/pnv.h
> @@ -101,6 +101,8 @@ struct PnvMachineState {
>       PnvPnor      *pnor;
>   
>       hwaddr       fw_load_addr;
> +
> +    bool         big_core;
>   };
>   
>   PnvChip *pnv_get_chip(PnvMachineState *pnv, uint32_t chip_id);
> diff --git a/include/hw/ppc/pnv_chip.h b/include/hw/ppc/pnv_chip.h
> index 7d5d08bcdc..69d8273efe 100644
> --- a/include/hw/ppc/pnv_chip.h
> +++ b/include/hw/ppc/pnv_chip.h
> @@ -27,6 +27,7 @@ struct PnvChip {
>       uint64_t     ram_start;
>       uint64_t     ram_size;
>   
> +    bool         big_core;
>       uint32_t     nr_cores;
>       uint32_t     nr_threads;
>       uint64_t     cores_mask;
> diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h
> index 693acb189b..50164e9e1f 100644
> --- a/include/hw/ppc/pnv_core.h
> +++ b/include/hw/ppc/pnv_core.h
> @@ -49,6 +49,7 @@ struct PnvCore {
>   
>       /*< public >*/
>       PowerPCCPU **threads;
> +    bool big_core;
>       uint32_t pir;
>       uint32_t hwid;
>       uint64_t hrmor;
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index eee34ca926..555a983536 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -1002,14 +1002,39 @@ static void pnv_init(MachineState *machine)
>       pnv->num_chips =
>           machine->smp.max_cpus / (machine->smp.cores * machine->smp.threads);
>   
> +    if (pnv->big_core) {
> +        if (machine->smp.threads % 2 == 1) {
> +            error_report("Cannot support %d threads with big-core option "
> +                         "because it must be an even number",
> +                         machine->smp.threads);
> +            exit(1);
> +        }
> +        max_smt_threads *= 2;
> +    }
> +
>       if (machine->smp.threads > max_smt_threads) {
>           error_report("Cannot support more than %d threads/core "
>                        "on %s machine", max_smt_threads, mc->desc);
> +        if (pmc->max_smt_threads == 4) {
> +            error_report("(use big-core=on for 8 threads per core)");
> +        }
>           exit(1);
>       }
>   
> +    if (pnv->big_core) {
> +        /*
> +         * powernv models PnvCore as a SMT4 core. Big-core requires 2xPnvCore
> +         * per core, so adjust topology here. pnv_dt_core() processor
> +         * device-tree and TCG SMT code make the 2 cores appear as one big core
> +         * from software point of view. pnv pervasive models and xscoms tend to
> +         * see the big core as 2 small core halves.
> +         */
> +        machine->smp.cores *= 2;
> +        machine->smp.threads /= 2;
> +    }
> +
>       if (!is_power_of_2(machine->smp.threads)) {
> -        error_report("Cannot support %d threads/core on a powernv"
> +        error_report("Cannot support %d threads/core on a powernv "
>                        "machine because it must be a power of 2",
>                        machine->smp.threads);
>           exit(1);


please add :

@@ -1054,6 +1079,9 @@ static void pnv_init(MachineState *machi
                                  &error_fatal);
          object_property_set_int(chip, "nr-threads", machine->smp.threads,
                                  &error_fatal);
+        object_property_set_bool(chip, "big-core", pnv->big_core,
+                                 &error_fatal);
+
          /*
           * The POWER8 machine use the XICS interrupt interface.
           * Propagate the XICS fabric to the chip and its controllers.


> @@ -1175,11 +1200,17 @@ static void pnv_get_pir_tir_p9(PnvChip *chip,
>                                   uint32_t core_id, uint32_t thread_id,
>                                   uint32_t *pir, uint32_t *tir)
>   {
> -    if (pir) {
> -        if (chip->nr_threads == 8) {
> -            *pir = (chip->chip_id << 8) | ((thread_id & 1) << 2) |
> -                   (core_id << 3) | (thread_id >> 1);
> -        } else {
> +    if (chip->big_core) {
> +        /* Big-core interleaves thread ID between small-cores */
> +        thread_id <<= 1;
> +        thread_id |= core_id & 1;
> +        core_id >>= 1;
> +
> +        if (pir) {
> +            *pir = (chip->chip_id << 8) | (core_id << 3) | thread_id;
> +        }
> +    } else {
> +        if (pir) {
>               *pir = (chip->chip_id << 8) | (core_id << 2) | thread_id;
>           }
>       }
> @@ -1203,11 +1234,17 @@ static void pnv_get_pir_tir_p10(PnvChip *chip,
>                                   uint32_t core_id, uint32_t thread_id,
>                                   uint32_t *pir, uint32_t *tir)
>   {
> -    if (pir) {
> -        if (chip->nr_threads == 8) {
> -            *pir = (chip->chip_id << 8) | ((core_id / 4) << 4) |
> -                    ((core_id % 2) << 3) | thread_id;
> -        } else {
> +    if (chip->big_core) {
> +        /* Big-core interleaves thread ID between small-cores */
> +        thread_id <<= 1;
> +        thread_id |= core_id & 1;
> +        core_id >>= 1;
> +
> +        if (pir) {
> +            *pir = (chip->chip_id << 8) | (core_id << 3) | thread_id;
> +        }
> +    } else {
> +        if (pir) {
>               *pir = (chip->chip_id << 8) | (core_id << 2) | thread_id;
>           }
>       }
> @@ -2180,7 +2217,8 @@ static void pnv_chip_power10_class_init(ObjectClass *klass, void *data)
>                                       &k->parent_realize);
>   }
>   
> -static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp)
> +static void pnv_chip_core_sanitize(PnvMachineState *pnv, PnvChip *chip,
> +                                   Error **errp)
>   {
>       PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
>       int cores_max;
> @@ -2201,6 +2239,17 @@ static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp)
>       }
>       chip->cores_mask &= pcc->cores_mask;
>   
> +    /* Ensure small-cores a paired up in big-core mode */
> +    if (pnv->big_core) {
> +        uint64_t even_cores = chip->cores_mask & 0x5555555555555555ULL;
> +        uint64_t odd_cores = chip->cores_mask & 0xaaaaaaaaaaaaaaaaULL;
> +
> +        if (even_cores ^ (odd_cores >> 1)) {
> +            error_setg(errp, "warning: unpaired cores in big-core mode !");
> +            return;
> +        }
> +    }
> +
>       /* now that we have a sane layout, let check the number of cores */
>       cores_max = ctpop64(chip->cores_mask);
>       if (chip->nr_cores > cores_max) {
> @@ -2224,12 +2273,14 @@ static void pnv_chip_core_realize(PnvChip *chip, Error **errp)
>       }
>   
>       /* Cores */
> -    pnv_chip_core_sanitize(chip, &error);
> +    pnv_chip_core_sanitize(pnv, chip, &error);
>       if (error) {
>           error_propagate(errp, error);
>           return;
>       }
>   
> +    chip->big_core = pnv->big_core;
> +


drop that and instead :

@@ -2282,6 +2334,8 @@ static void pnv_chip_core_realize(PnvChi
                                  &error_fatal);
          object_property_set_link(OBJECT(pnv_core), "chip", OBJECT(chip),
                                   &error_abort);
+        object_property_set_bool(OBJECT(pnv_core), "big-core", chip->big_core,
+                                 &error_abort);
          qdev_realize(DEVICE(pnv_core), NULL, &error_fatal);
  
          /* Each core has an XSCOM MMIO region */
@@ -2313,6 +2367,7 @@ static Property pnv_chip_properties[] =
      DEFINE_PROP_UINT32("nr-cores", PnvChip, nr_cores, 1),
      DEFINE_PROP_UINT64("cores-mask", PnvChip, cores_mask, 0x0),
      DEFINE_PROP_UINT32("nr-threads", PnvChip, nr_threads, 1),
+    DEFINE_PROP_BOOL("big-core", PnvChip, big_core, false),
      DEFINE_PROP_END_OF_LIST(),
  };


>       chip->cores = g_new0(PnvCore *, chip->nr_cores);
>   
>       for (i = 0, core_hwid = 0; (core_hwid < sizeof(chip->cores_mask) * 8)
> diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c
> index 8cfa94fbfa..16d40392db 100644
> --- a/hw/ppc/pnv_core.c
> +++ b/hw/ppc/pnv_core.c
> @@ -249,7 +249,12 @@ static void pnv_core_cpu_realize(PnvCore *pc, PowerPCCPU *cpu, Error **errp,
>       pir_spr->default_value = pir;
>       tir_spr->default_value = tir;
>   
> -    env->core_index = core_hwid;
> +    if (pc->big_core) {
> +        /* 2 "small cores" get the same core index for SMT operations */
> +        env->core_index = core_hwid >> 1;
> +    } else {
> +        env->core_index = core_hwid;
> +    }
>   
>       /* Set time-base frequency to 512 MHz */
>       cpu_ppc_tb_init(env, PNV_TIMEBASE_FREQ);


please add :

@@ -355,6 +360,7 @@ static Property pnv_core_properties[] =
      DEFINE_PROP_UINT32("hwid", PnvCore, hwid, 0),
      DEFINE_PROP_UINT64("hrmor", PnvCore, hrmor, 0),
      DEFINE_PROP_LINK("chip", PnvCore, chip, TYPE_PNV_CHIP, PnvChip *),
+    DEFINE_PROP_BOOL("big-core", PnvCore, big_core, false),
      DEFINE_PROP_END_OF_LIST(),
  };
  


Thanks,

C.


  reply	other threads:[~2024-07-13  7:20 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12 12:02 [PATCH v2 00/19] ppc/pnv: Better big-core model, lpar-per-core, PC unit Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 01/19] target/ppc: Fix msgsnd for POWER8 Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 02/19] ppc/pnv: Add pointer from PnvCPUState to PnvCore Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 03/19] ppc/pnv: Move timebase state into PnvCore Nicholas Piggin
2024-07-12 13:40   ` Cédric Le Goater
2024-07-15  6:30     ` Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 04/19] target/ppc: Move SPR indirect registers " Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 05/19] ppc/pnv: use class attribute to limit SMT threads for different machines Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 06/19] ppc/pnv: Extend chip_pir class method to TIR as well Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 07/19] ppc: Add a core_index to CPUPPCState for SMT vCPUs Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 08/19] target/ppc: Add helpers to check for SMT sibling threads Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 09/19] ppc: Add has_smt_siblings property to CPUPPCState Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 10/19] ppc/pnv: Add a big-core mode that joins two regular cores Nicholas Piggin
2024-07-13  7:19   ` Cédric Le Goater [this message]
2024-07-15  6:31     ` Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 11/19] ppc/pnv: Add allow for big-core differences in DT generation Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 12/19] ppc/pnv: Implement big-core PVR for Power9/10 Nicholas Piggin
2024-07-13  7:28   ` Cédric Le Goater
2024-07-12 12:02 ` [PATCH v2 13/19] ppc/pnv: Implement Power9 CPU core thread state indirect register Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 14/19] ppc/pnv: Add POWER10 ChipTOD quirk for big-core Nicholas Piggin
2024-07-13  7:22   ` Cédric Le Goater
2024-07-12 12:02 ` [PATCH v2 15/19] ppc/pnv: Add big-core machine property Nicholas Piggin
2024-07-13  7:24   ` Cédric Le Goater
2024-07-15  6:32     ` Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 16/19] system/cpus: Add cpu_pause() function Nicholas Piggin
2024-07-12 14:35   ` Philippe Mathieu-Daudé
2024-07-12 15:25   ` Peter Xu
2024-07-12 12:02 ` [PATCH v2 17/19] ppc/pnv: Add a CPU nmi and resume function Nicholas Piggin
2024-07-13  7:27   ` Cédric Le Goater
2024-07-12 12:02 ` [PATCH v2 18/19] ppc/pnv: Implement POWER10 PC xscom registers for direct controls Nicholas Piggin
2024-07-12 12:02 ` [PATCH v2 19/19] ppc/pnv: Add an LPAR per core machine option Nicholas Piggin
2024-07-13  7:27   ` Cédric Le Goater

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=4f0e918b-336f-4423-bc48-25607662eabc@kaod.org \
    --to=clg@kaod.org \
    --cc=fbarrat@linux.ibm.com \
    --cc=harshpb@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --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).