qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Tang Chen <tangchen@cn.fujitsu.com>,
	Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>,
	Anthony Liguori <aliguori@amazon.com>,
	Peter Crosthwaite <peter.crostwaite@xilinx.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PULL v2 018/106] pc-dimm: add busy slot check and slot auto-allocation
Date: Wed, 18 Jun 2014 19:16:42 +0300	[thread overview]
Message-ID: <1403108034-32054-19-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1403108034-32054-1-git-send-email-mst@redhat.com>

From: Igor Mammedov <imammedo@redhat.com>

- if slot property is not specified on -device/device_add command,
treat default value as request for assigning PCDIMMDevice to
the first free slot.

- if slot is provided with -device/device_add command, attempt to
use it or fail command if it's already occupied.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/mem/pc-dimm.h |  2 ++
 hw/i386/pc.c             | 21 +++++++++++++++++++++
 hw/mem/pc-dimm.c         | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 5cd8f35..5f80d14 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -74,4 +74,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
                                uint64_t address_space_size,
                                uint64_t *hint, uint64_t size,
                                Error **errp);
+
+int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 #endif
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4dc86d5..be5e3bb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1547,8 +1547,10 @@ void qemu_register_pc_machine(QEMUMachine *m)
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
+    int slot;
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+    MachineState *machine = MACHINE(hotplug_dev);
     PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *mr = ddc->get_memory_region(dimm);
@@ -1565,7 +1567,26 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
     if (local_err) {
         goto out;
     }
+
     object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
+                                 machine->ram_slots, &local_err);
+    if (local_err) {
+        goto out;
+    }
+    object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
 
     memory_region_add_subregion(&pcms->hotplug_memory,
                                 addr - pcms->hotplug_memory_base, mr);
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 40b51c8..8c26568 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -23,6 +23,52 @@
 #include "qapi/visitor.h"
 #include "qemu/range.h"
 
+static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
+{
+    unsigned long *bitmap = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+        DeviceState *dev = DEVICE(obj);
+        if (dev->realized) { /* count only realized DIMMs */
+            PCDIMMDevice *d = PC_DIMM(obj);
+            set_bit(d->slot, bitmap);
+        }
+    }
+
+    object_child_foreach(obj, pc_dimm_slot2bitmap, opaque);
+    return 0;
+}
+
+int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp)
+{
+    unsigned long *bitmap = bitmap_new(max_slots);
+    int slot = 0;
+
+    object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
+
+    /* check if requested slot is not occupied */
+    if (hint) {
+        if (*hint >= max_slots) {
+            error_setg(errp, "invalid slot# %d, should be less than %d",
+                       *hint, max_slots);
+        } else if (!test_bit(*hint, bitmap)) {
+            slot = *hint;
+        } else {
+            error_setg(errp, "slot %d is busy", *hint);
+        }
+        goto out;
+    }
+
+    /* search for free slot */
+    slot = find_first_zero_bit(bitmap, max_slots);
+    if (slot == max_slots) {
+        error_setg(errp, "no free slots available");
+    }
+out:
+    g_free(bitmap);
+    return slot;
+}
+
 static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b)
 {
     PCDIMMDevice *x = PC_DIMM(a);
-- 
MST

  parent reply	other threads:[~2014-06-18 16:16 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18 16:15 [Qemu-devel] [PULL v2 000/106] pc, pci, virtio, hotplug fixes, enhancements Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 001/106] pc: create custom generic PC machine type Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 002/106] pc: ACPI BIOS: use enum for defining memory affinity flags Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 003/106] object_add: allow completion handler to get canonical path Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 004/106] vl.c: daemonize before guest memory allocation Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 005/106] add memdev backend infrastructure Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 007/106] qdev: hotplug for bus-less devices Michael S. Tsirkin
2014-06-18 16:15 ` [Qemu-devel] [PULL v2 008/106] qdev: expose DeviceState.hotplugged field as a property Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 009/106] pc: implement pc-dimm device abstraction Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 010/106] memory: add memory_region_is_mapped() API Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 011/106] pc-dimm: do not allow setting an in-use memdev Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 012/106] pc: initialize memory hotplug address space Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 013/106] pc: exit QEMU if number of slots more than supported 256 Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 014/106] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 015/106] pc: exit QEMU if compat machine doesn't support memory hotlpug Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 016/106] pc: add memory hotplug handler to PC_MACHINE Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 017/106] pc-dimm: add busy address check and address auto-allocation Michael S. Tsirkin
2014-06-18 16:16 ` Michael S. Tsirkin [this message]
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 019/106] acpi: rename cpu_hotplug_defs.h to pc-hotplug.h Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 020/106] acpi: memory hotplug ACPI hardware implementation Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 021/106] trace: add acpi memory hotplug IO region events Michael S. Tsirkin
2014-06-18 16:16 ` [Qemu-devel] [PULL v2 022/106] trace: pc: add PC_DIMM slot & address allocation Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 023/106] acpi:piix4: allow plug/unlug callbacks handle not only PCI devices Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 024/106] acpi:piix4: add memory hotplug handling Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 025/106] pc: ich9 lpc: make it work with global/compat properties Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 026/106] acpi:ich9: add memory hotplug handling Michael S. Tsirkin
2014-06-24 16:44   ` [Qemu-devel] per-machine vs per-qemu-version compat_props macros (was Re: acpi:ich9: add memory hotplug handling) Eduardo Habkost
2014-06-24 16:47     ` Peter Maydell
2014-06-24 17:55       ` Eduardo Habkost
2014-06-24 19:13         ` Marcel Apfelbaum
2014-06-24 22:30         ` Peter Maydell
2014-06-25  0:18           ` Eduardo Habkost
2014-06-25  1:31         ` Eduardo Habkost
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 027/106] pc: migrate piix4 & ich9 MemHotplugState Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 028/106] pc: add acpi-device link to PCMachineState Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 029/106] pc: propagate memory hotplug event to ACPI device Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 030/106] pc: ACPI BIOS: implement memory hotplug interface Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 031/106] pc: add "hotplug-memory-region-size" property to PC_MACHINE Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 032/106] pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 033/106] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 034/106] acpi: update generated files Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 035/106] acpi-test: update expected tables Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 036/106] virtio: Drop superfluous conditionals around g_free() Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 037/106] virtio: Drop superfluous conditionals around g_strdup() Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 038/106] ich: get rid of spaces in type name Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 039/106] pc: q35: acpi: report error to user on unsupported unplug request Michael S. Tsirkin
2014-06-18 16:17 ` [Qemu-devel] [PULL v2 040/106] migration: export SELF_ANNOUNCE_ROUNDS Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 041/106] migration: introduce self_announce_delay() Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 042/106] virtio-net: announce self by guest Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 043/106] Add kvm_eventfds_enabled function Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 044/106] Add chardev API qemu_chr_fe_read_all Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 045/106] Add chardev API qemu_chr_fe_set_msgfds Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 046/106] Add chardev API qemu_chr_fe_get_msgfds Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 047/106] Add G_IO_HUP handler for socket chardev Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 048/106] vhost: add vhost_get_features and vhost_ack_features Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 049/106] vhost_net should call the poll callback only when it is set Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 050/106] Refactor virtio-net to use generic get_vhost_net Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 051/106] vhost_net_init will use VhostNetOptions to get all its arguments Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 052/106] Add vhost_ops to vhost_dev struct and replace all relevant ioctls Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 053/106] Add vhost-backend and VhostBackendType Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 054/106] Add vhost-user as a vhost backend Michael S. Tsirkin
2014-06-18 16:18 ` [Qemu-devel] [PULL v2 055/106] vhost-net: vhost-user feature bits support Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 056/106] Add new vhost-user netdev backend Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 057/106] Add the vhost-user netdev backend to the command line Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 058/106] Add vhost-user protocol documentation Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 059/106] libqemustub: add stubs to be able to use qemu-char.c Michael S. Tsirkin
2014-06-23  6:15   ` Riku Voipio
2014-06-23  7:20     ` Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 060/106] Add qtest for vhost-user Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 061/106] NUMA: move numa related code to new file numa.c Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 062/106] NUMA: check if the total numa memory size is equal to ram_size Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 063/106] NUMA: Add numa_info structure to contain numa nodes info Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 064/106] NUMA: convert -numa option to use OptsVisitor Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 065/106] NUMA: expand MAX_NODES from 64 to 128 Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 066/106] man: improve -numa doc Michael S. Tsirkin
2014-06-18 16:19 ` [Qemu-devel] [PULL v2 067/106] qmp: improve error reporting for -object and object-add Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 068/106] numa: introduce memory_region_allocate_system_memory Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 069/106] memory: reorganize file-based allocation Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 070/106] memory: move preallocation code out of exec.c Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 071/106] memory: move RAM_PREALLOC_MASK to exec.c, rename Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 072/106] configure: add Linux libnuma detection Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 073/106] Introduce signed range Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 074/106] qom: introduce object_property_get_enum and object_property_get_uint16List Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 075/106] numa: add -numa node, memdev= option Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 076/106] memory: move mem_path handling to memory_region_allocate_system_memory Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 077/106] memory: add error propagation to file-based RAM allocation Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 078/106] vl: redo -object parsing Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 079/106] pc: pass MachineState to pc_memory_init Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 080/106] backend:hostmem: replace hostmemory with host_memory Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 081/106] hostmem: separate allocation from UserCreatable complete method Michael S. Tsirkin
2014-06-18 16:20 ` [Qemu-devel] [PULL v2 082/106] hostmem: add file-based HostMemoryBackend Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 083/106] hostmem: add merge and dump properties Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 084/106] hostmem: allow preallocation of any memory region Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 085/106] hostmem: add property to map memory with MAP_SHARED Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 086/106] hostmem: add properties for NUMA memory policy Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 087/106] qmp: add query-memdev Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 088/106] hmp: add info memdev Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 089/106] tests: fix memory leak in test of string input visitor Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 090/106] qapi: make string input visitor parse int list Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 091/106] qapi: make string output " Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 092/106] qapi: fix build on glib < 2.28 Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 093/106] qdev: reorganize error reporting in bus_set_realized Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 094/106] qdev: recursively unrealize devices when unrealizing bus Michael S. Tsirkin
2014-06-18 16:21 ` [Qemu-devel] [PULL v2 095/106] qmp: clean out whitespace Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 096/106] pc: acpi: do not hardcode preprocessor Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 097/106] numa: handle mmaped memory allocation failure correctly Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 098/106] qmp: add query-memory-devices command Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 099/106] acpi: introduce TYPE_ACPI_DEVICE_IF interface Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 100/106] acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 101/106] qmp: add query-acpi-ospm-status command Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 102/106] qmp: add ACPI_DEVICE_OST event handling Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 103/106] acpi: rephrase comment Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 104/106] qapi: fix input visitor bugs Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 105/106] tests: simplify code Michael S. Tsirkin
2014-06-18 16:22 ` [Qemu-devel] [PULL v2 106/106] qapi/string-output-visitor: fix bugs Michael S. Tsirkin
2014-06-18 17:25 ` [Qemu-devel] [PULL v2 006/106] vl.c: extend -m option to support options for memory hotplug Michael S. Tsirkin
2014-06-18 17:48 ` [Qemu-devel] [PULL v2 000/106] pc, pci, virtio, hotplug fixes, enhancements Michael S. Tsirkin

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=1403108034-32054-19-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=imammedo@redhat.com \
    --cc=peter.crostwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tangchen@cn.fujitsu.com \
    --cc=vasilis.liaskovitis@profitbricks.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).