qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: qemu-devel@nongnu.org
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>,
	borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, agraf@suse.de,
	David Hildenbrand <dahi@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 20/23] s390: move memory calculation into the sclp device
Date: Mon, 31 Aug 2015 13:14:00 +0200	[thread overview]
Message-ID: <1441019643-10677-21-git-send-email-cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <1441019643-10677-1-git-send-email-cornelia.huck@de.ibm.com>

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

The restrictions for memory calculation belong to the sclp device.

Let's move the calculation to that point, so we are able to unify it for
both s390 machines. The sclp device is the first device to be initialized.
It performs the calculation and safely stores it in the machine, where
other parts of the system can access an reuse it.

The memory hotplug device is now only created when it is really needed.

Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c | 54 +++-------------------------------------
 hw/s390x/s390-virtio.c     | 18 +++-----------
 hw/s390x/sclp.c            | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 66 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index d4afe7d..eae1305 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -102,54 +102,16 @@ static void virtio_ccw_register_hcalls(void)
 
 static void ccw_init(MachineState *machine)
 {
-    ram_addr_t my_ram_size = machine->ram_size;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
-    sclpMemoryHotplugDev *mhd = init_sclp_memory_hotplug_dev();
     int ret;
     VirtualCssBus *css_bus;
     DeviceState *dev;
-    ram_addr_t pad_size = 0;
-    ram_addr_t maxmem = machine->maxram_size;
-    ram_addr_t standby_mem_size = maxmem - my_ram_size;
-    uint64_t kvm_limit;
-
-    /* The storage increment size is a multiple of 1M and is a power of 2.
-     * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
-     * The variable 'mhd->increment_size' is an exponent of 2 that can be
-     * used to calculate the size (in bytes) of an increment. */
-    mhd->increment_size = 20;
-    while ((my_ram_size >> mhd->increment_size) > MAX_STORAGE_INCREMENTS) {
-        mhd->increment_size++;
-    }
-    while ((standby_mem_size >> mhd->increment_size) > MAX_STORAGE_INCREMENTS) {
-        mhd->increment_size++;
-    }
 
-    /* The core and standby memory areas need to be aligned with
-     * the increment size.  In effect, this can cause the
-     * user-specified memory size to be rounded down to align
-     * with the nearest increment boundary. */
-    standby_mem_size = standby_mem_size >> mhd->increment_size
-                                        << mhd->increment_size;
-    my_ram_size = my_ram_size >> mhd->increment_size
-                              << mhd->increment_size;
-
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = my_ram_size;
-    machine->maxram_size = my_ram_size + standby_mem_size;
-
-    ret = s390_set_memory_limit(machine->maxram_size, &kvm_limit);
-    if (ret == -E2BIG) {
-        hw_error("qemu: host supports a maximum of %" PRIu64 " GB",
-                 kvm_limit >> 30);
-    } else if (ret) {
-        hw_error("qemu: setting the guest size failed");
-    }
+    s390_sclp_init();
 
     /* get a BUS */
     css_bus = virtual_css_bus_init();
-    s390_sclp_init();
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
                       machine->initrd_filename, "s390-ccw.img", true);
     s390_flic_init();
@@ -163,21 +125,11 @@ static void ccw_init(MachineState *machine)
     virtio_ccw_register_hcalls();
 
     /* allocate RAM for core */
-    memory_region_init_ram(ram, NULL, "s390.ram", my_ram_size, &error_abort);
+    memory_region_init_ram(ram, NULL, "s390.ram", machine->ram_size,
+                           &error_abort);
     vmstate_register_ram_global(ram);
     memory_region_add_subregion(sysmem, 0, ram);
 
-    /* If the size of ram is not on a MEM_SECTION_SIZE boundary,
-       calculate the pad size necessary to force this boundary. */
-    if (standby_mem_size) {
-        if (my_ram_size % MEM_SECTION_SIZE) {
-            pad_size = MEM_SECTION_SIZE - my_ram_size % MEM_SECTION_SIZE;
-        }
-        my_ram_size += standby_mem_size + pad_size;
-        mhd->pad_size = pad_size;
-        mhd->standby_mem_size = standby_mem_size;
-    }
-
     /* Initialize storage key device */
     s390_skeys_init();
 
diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index b0f339e..c8e4737 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -261,10 +261,9 @@ int gtod_load(QEMUFile *f, void *opaque, int version_id)
 /* PC hardware initialisation */
 static void s390_init(MachineState *machine)
 {
-    ram_addr_t my_ram_size = machine->ram_size;
+    ram_addr_t my_ram_size;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
-    int increment_size = 20;
     void *virtio_region;
     hwaddr virtio_region_len;
     hwaddr virtio_region_start;
@@ -273,22 +272,11 @@ static void s390_init(MachineState *machine)
         error_report("Memory hotplug not supported by the selected machine.");
         exit(EXIT_FAILURE);
     }
-    /*
-     * The storage increment size is a multiple of 1M and is a power of 2.
-     * The number of storage increments must be MAX_STORAGE_INCREMENTS or
-     * fewer.
-     */
-    while ((my_ram_size >> increment_size) > MAX_STORAGE_INCREMENTS) {
-        increment_size++;
-    }
-    my_ram_size = my_ram_size >> increment_size << increment_size;
-
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = my_ram_size;
+    s390_sclp_init();
+    my_ram_size = machine->ram_size;
 
     /* get a BUS */
     s390_bus = s390_virtio_bus_init(&my_ram_size);
-    s390_sclp_init();
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
                       machine->initrd_filename, ZIPL_FILENAME, false);
     s390_flic_init();
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index b1a62c7..ac582e8 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -470,20 +470,80 @@ void s390_sclp_init(void)
 
 static void sclp_realize(DeviceState *dev, Error **errp)
 {
+    MachineState *machine = MACHINE(qdev_get_machine());
     SCLPDevice *sclp = SCLP(dev);
     Error *l_err = NULL;
+    uint64_t hw_limit;
+    int ret;
 
     object_property_set_bool(OBJECT(sclp->event_facility), true, "realized",
                              &l_err);
     if (l_err) {
         goto error;
     }
+
+    ret = s390_set_memory_limit(machine->maxram_size, &hw_limit);
+    if (ret == -E2BIG) {
+        error_setg(&l_err, "qemu: host supports a maximum of %" PRIu64 " GB",
+                   hw_limit >> 30);
+        goto error;
+    } else if (ret) {
+        error_setg(&l_err, "qemu: setting the guest size failed");
+        goto error;
+    }
     return;
 error:
     assert(l_err);
     error_propagate(errp, l_err);
 }
 
+static void sclp_memory_init(SCLPDevice *sclp)
+{
+    MachineState *machine = MACHINE(qdev_get_machine());
+    ram_addr_t initial_mem = machine->ram_size;
+    ram_addr_t max_mem = machine->maxram_size;
+    ram_addr_t standby_mem = max_mem - initial_mem;
+    ram_addr_t pad_mem = 0;
+    int increment_size = 20;
+
+    /* The storage increment size is a multiple of 1M and is a power of 2.
+     * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
+     * The variable 'increment_size' is an exponent of 2 that can be
+     * used to calculate the size (in bytes) of an increment. */
+    while ((initial_mem >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    if (machine->ram_slots) {
+        while ((standby_mem >> increment_size) > MAX_STORAGE_INCREMENTS) {
+            increment_size++;
+        }
+    }
+
+    /* The core and standby memory areas need to be aligned with
+     * the increment size.  In effect, this can cause the
+     * user-specified memory size to be rounded down to align
+     * with the nearest increment boundary. */
+    initial_mem = initial_mem >> increment_size << increment_size;
+    standby_mem = standby_mem >> increment_size << increment_size;
+
+    /* If the size of ram is not on a MEM_SECTION_SIZE boundary,
+       calculate the pad size necessary to force this boundary. */
+    if (machine->ram_slots && standby_mem) {
+        sclpMemoryHotplugDev *mhd = init_sclp_memory_hotplug_dev();
+
+        if (initial_mem % MEM_SECTION_SIZE) {
+            pad_mem = MEM_SECTION_SIZE - initial_mem % MEM_SECTION_SIZE;
+        }
+        mhd->increment_size = increment_size;
+        mhd->pad_size = pad_mem;
+        mhd->standby_mem_size = standby_mem;
+    }
+    machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem + pad_mem + standby_mem;
+    /* let's propagate the changed ram size into the global variable. */
+    ram_size = initial_mem;
+}
+
 static void sclp_init(Object *obj)
 {
     SCLPDevice *sclp = SCLP(obj);
@@ -495,6 +555,8 @@ static void sclp_init(Object *obj)
     qdev_set_parent_bus(DEVICE(new), sysbus_get_default());
     object_unref(new);
     sclp->event_facility = EVENT_FACILITY(new);
+
+    sclp_memory_init(sclp);
 }
 
 static void sclp_class_init(ObjectClass *oc, void *data)
-- 
2.5.1

  parent reply	other threads:[~2015-08-31 11:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31 11:13 [Qemu-devel] [PATCH 00/23] s390x: further patches Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 01/23] s390x/css: handle ccw-0 TIC correctly Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 02/23] s390x/css: ccw-0 enforces count > 0 Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 03/23] s390x/event-facility: fix receive mask check Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 04/23] s390x/css: start with cleared cstat/dstat Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 05/23] s390x/event-facility: fix location of receive mask Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 06/23] pc-bios/s390-ccw: Device detection in higher subchannel sets Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 07/23] pc-bios/s390-ccw: rebuild image Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 08/23] s390x/kvm: make setting of in-kernel irq routes more efficient Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 09/23] s390x/gdb: support reading/writing of control registers Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 10/23] sclp/s390: rework sclp cpu hotplug device notification Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 11/23] s390/sclp: rework sclp event facility initialization + device realization Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 12/23] s390/sclp: replace sclp event types with proper defines Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 13/23] s390/sclp: temporarily fix unassignment/reassignment of memory subregions Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 14/23] s390/sclp: introduce a root sclp device Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 15/23] s390/sclp: move sclp_execute related functions into the SCLP class Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 16/23] s390/sclp: move sclp_service_interrupt into the sclp device Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 17/23] s390: no need to manually parse for slots and maxmem Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 18/23] s390: disallow memory hotplug for the s390-virtio machine Cornelia Huck
2015-08-31 11:13 ` [Qemu-devel] [PATCH 19/23] s390/sclp: ignore memory hotplug operations if it is disabled Cornelia Huck
2015-08-31 11:14 ` Cornelia Huck [this message]
2015-08-31 11:14 ` [Qemu-devel] [PATCH 21/23] s390: unify allocation of initial memory Cornelia Huck
2015-08-31 11:14 ` [Qemu-devel] [PATCH 22/23] s390/sclp: store the increment_size in the sclp device Cornelia Huck
2015-08-31 11:14 ` [Qemu-devel] [PATCH 23/23] s390/sclp: simplify calculation of rnmax Cornelia Huck

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=1441019643-10677-21-git-send-email-cornelia.huck@de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=dahi@linux.vnet.ibm.com \
    --cc=jfrei@linux.vnet.ibm.com \
    --cc=qemu-devel@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).