kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Andrew Jones <drjones@redhat.com>
Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, thuth@redhat.com,
	dgibson@redhat.com, agraf@suse.de, lvivier@redhat.com,
	pbonzini@redhat.com, rkrcmar@redhat.com
Subject: Re: [kvm-unit-tests PATCH v5 13/18] powerpc/ppc64: adapt arm's setup
Date: Mon, 22 Feb 2016 12:00:13 +1100	[thread overview]
Message-ID: <20160222010013.GA2808@voom.fritz.box> (raw)
In-Reply-To: <20160219074933.r2uz3jwnnbnjxxjj@hawk.localdomain>

[-- Attachment #1: Type: text/plain, Size: 6084 bytes --]

On Fri, Feb 19, 2016 at 08:49:33AM +0100, Andrew Jones wrote:
> On Fri, Feb 19, 2016 at 02:40:53PM +1100, David Gibson wrote:
> > On Wed, Feb 17, 2016 at 07:40:54PM +0100, Andrew Jones wrote:
> > > Copy arm's setup code (also DT based) over to powerpc, adapting
> > > it a bit. Also bring over arm's setup selftest, giving powerpc
> > > its first test.
> > > 
> > > The largest change from arm's setup.c is that instead of using a
> > > hardcoded SMP_CACHE_BYTES, cpu_set() is extended to extract the
> > > line size from the cpu DT nodes. That change also requires that
> > > we call cpu_init() before mem_init() in setup().
> > > 
> > > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > > Reviewed-by: Thomas Huth <thuth@redhat.com>
> > > Tested-by: Laurent Vivier <lvivier@redhat.com>
> > > ---
> > >  lib/powerpc/asm/setup.h |  30 +++++++++++
> > >  lib/powerpc/setup.c     | 141 ++++++++++++++++++++++++++++++++++++++++++++++++
> > >  lib/ppc64/asm/setup.h   |   1 +
> > >  powerpc/Makefile.common |   1 +
> > >  powerpc/cstart64.S      |  16 +++++-
> > >  powerpc/selftest.c      |  63 ++++++++++++++++++++--
> > >  6 files changed, 248 insertions(+), 4 deletions(-)
> > >  create mode 100644 lib/powerpc/asm/setup.h
> > >  create mode 100644 lib/powerpc/setup.c
> > >  create mode 100644 lib/ppc64/asm/setup.h
> > > 
> > > diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h
> > > new file mode 100644
> > > index 0000000000000..8288ff37ff1b9
> > > --- /dev/null
> > > +++ b/lib/powerpc/asm/setup.h
> > > @@ -0,0 +1,30 @@
> > > +#ifndef _ASMPOWERPC_SETUP_H_
> > > +#define _ASMPOWERPC_SETUP_H_
> > > +/*
> > > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
> > > + *
> > > + * This work is licensed under the terms of the GNU LGPL, version 2.
> > > + */
> > > +#include <libcflat.h>
> > > +#include <alloc.h>	/* phys_addr_t */
> > > +
> > > +#define NR_CPUS			8	/* arbitrarily set for now */
> > 
> > We probably want to set this larger sooner rather than later.  The
> > test machines the virt dev team uses have 160 logical CPUs, and
> > they're not particularly large as Power systems go.
> 
> One of the changes that the "Add SMP support" follow-on series will
> make is to change this to whatever qemu-kvm/spapr supports.

Ok, great.

> > > +extern u32 cpus[NR_CPUS];
> > > +extern int nr_cpus;
> > > +
> > > +#define NR_MEM_REGIONS		8
> > > +#define MR_F_PRIMARY		(1U << 0)
> > > +struct mem_region {
> > > +	phys_addr_t start;
> > > +	phys_addr_t end;
> > > +	unsigned int flags;
> > > +};
> > > +extern struct mem_region mem_regions[NR_MEM_REGIONS];
> > > +extern phys_addr_t __physical_start, __physical_end;
> > > +extern unsigned __smp_cache_bytes;
> > > +
> > > +#define PHYSICAL_START		(__physical_start)
> > > +#define PHYSICAL_END		(__physical_end)
> > > +#define SMP_CACHE_BYTES		(__smp_cache_bytes)
> > > +
> > > +#endif /* _ASMPOWERPC_SETUP_H_ */
> > > diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
> > > new file mode 100644
> > > index 0000000000000..70f50deb9bacf
> > > --- /dev/null
> > > +++ b/lib/powerpc/setup.c
> > > @@ -0,0 +1,141 @@
> > > +/*
> > > + * Initialize machine setup information and I/O.
> > > + *
> > > + * After running setup() unit tests may query how many cpus they have
> > > + * (nr_cpus), how much memory they have (PHYSICAL_END - PHYSICAL_START),
> > > + * may use dynamic memory allocation (malloc, etc.), printf, and exit.
> > > + * Finally, argc and argv are also ready to be passed to main().
> > > + *
> > > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
> > > + *
> > > + * This work is licensed under the terms of the GNU LGPL, version 2.
> > > + */
> > > +#include <libcflat.h>
> > > +#include <libfdt/libfdt.h>
> > > +#include <devicetree.h>
> > > +#include <alloc.h>
> > > +#include <asm/setup.h>
> > > +#include <asm/page.h>
> > > +
> > > +extern unsigned long stacktop;
> > > +extern void io_init(void);
> > > +extern void setup_args(const char *args);
> > > +
> > > +u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
> > > +int nr_cpus;
> > > +
> > > +struct mem_region mem_regions[NR_MEM_REGIONS];
> > > +phys_addr_t __physical_start, __physical_end;
> > > +unsigned __smp_cache_bytes;
> > > +
> > > +static void cpu_set(int fdtnode, u32 regval, void *info)
> > > +{
> > > +	const struct fdt_property *prop;
> > > +	unsigned *max_linesz = (unsigned *)info, sz;
> > > +	int cpu = nr_cpus++;
> > > +	u32 *data;
> > > +
> > > +	if (cpu >= NR_CPUS) {
> > > +		printf("Number cpus exceeds maximum supported (%d).\n",
> > > +			NR_CPUS);
> > > +		assert(0);
> > > +	}
> > > +	cpus[cpu] = regval;
> > > +
> > > +	prop = fdt_get_property(dt_fdt(), fdtnode, "i-cache-line-size", NULL);
> > > +	assert(prop != NULL);
> > > +	data = (u32 *)prop->data;
> > > +	sz = fdt32_to_cpu(*data);
> > > +
> > > +	if (*max_linesz < sz)
> > > +		*max_linesz = sz;
> > > +
> > > +	prop = fdt_get_property(dt_fdt(), fdtnode, "d-cache-line-size", NULL);
> > > +	assert(prop != NULL);
> > > +	data = (u32 *)prop->data;
> > > +	sz = fdt32_to_cpu(*data);
> > > +
> > > +	if (*max_linesz < sz)
> > > +		*max_linesz = sz;
> > 
> > Hmm.. what is __smp_cache_bytes used for, exactly?
> > 
> > If you're just trying to get cacheline alignment, then this is
> > correct.
> > 
> > However, if you're using this to control loops which step over each
> > cacheline to invalidate / flush / whatever, then you'd need the
> > minimum cacheline size instead.
> 
> OK, I can just save both to respective icache, dcache variables,
> deferring the decision on which, or max, or min, to use.

Or... you could just abort if they're not the same and worry about it
when we actually get a machine where they're different (i.e. probably
never).

-- 
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: 819 bytes --]

  reply	other threads:[~2016-02-22  1:08 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 18:40 [kvm-unit-tests PATCH v5 00/18] ppc64: initial drop Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 01/18] arm/arm64: trivial: another assert fix Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 02/18] Makefile: cscope: also look in arch shared asm Andrew Jones
2016-02-18  2:36   ` David Gibson
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 03/18] lib: asm-generic: add missing casts Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 04/18] devicetree: fix dt_get_memory_params Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 05/18] arm/arm64: setup improvements Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 06/18] lib: add vprintf Andrew Jones
2016-02-18  2:44   ` David Gibson
2016-02-18  6:34   ` Thomas Huth
2016-02-18 10:21     ` Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 07/18] lib: share arm-selftest utility functions Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 08/18] config: no need to mix arch makefiles Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 09/18] powerpc/ppc64: start skeleton framework Andrew Jones
2016-02-19  2:11   ` David Gibson
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 10/18] powerpc/ppc64: ppc-ify makefiles and linker script Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 11/18] powerpc/ppc64: add a boot rom Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 12/18] powerpc/ppc64: add hcall support and putchar Andrew Jones
2016-02-19  3:10   ` David Gibson
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 13/18] powerpc/ppc64: adapt arm's setup Andrew Jones
2016-02-19  3:40   ` David Gibson
2016-02-19  7:49     ` Andrew Jones
2016-02-22  1:00       ` David Gibson [this message]
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 14/18] powerpc/ppc64: relocate linker VMAs Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 15/18] powerpc/ppc64: add run script and unittests.cfg Andrew Jones
2016-02-19  3:43   ` David Gibson
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 16/18] mkstandalone: add support for powerpc Andrew Jones
2016-02-18 14:51   ` Radim Krčmář
2016-02-19  3:53   ` David Gibson
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 17/18] powerpc/ppc64: add RTAS support Andrew Jones
2016-02-19  4:08   ` David Gibson
2016-02-19  7:52     ` Andrew Jones
2016-02-17 18:40 ` [kvm-unit-tests PATCH v5 18/18] powerpc/ppc64: make a fake debug-exit Andrew Jones
2016-02-19  4:12   ` David Gibson

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=20160222010013.GA2808@voom.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=dgibson@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=thuth@redhat.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).