[SeaBIOS] [RFC PATCH v4 19/30] Implement "info memory-total" and "query-memory-total"

Blue Swirl blauwirbel at gmail.com
Wed Dec 19 20:47:01 CET 2012


On Tue, Dec 18, 2012 at 12:41 PM, Vasilis Liaskovitis
<vasilis.liaskovitis at profitbricks.com> wrote:
> Returns total physical memory available to guest in bytes, including hotplugged
> memory. Note that the number reported here may be different from what the guest
> sees e.g. if the guest has not logically onlined hotplugged memory.
>
> This functionality is provided independently of a balloon device, since a
> guest can be using ACPI memory hotplug without using a balloon device.
>
> v3->v4: Moved qmp command implementation to vl.c. This prevents a circular
> header dependency problem.
>
> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis at profitbricks.com>
> ---
>  hmp-commands.hx  |    2 ++
>  hmp.c            |    7 +++++++
>  hmp.h            |    1 +
>  hw/dimm.c        |   14 ++++++++++++++
>  hw/dimm.h        |    1 +
>  monitor.c        |    7 +++++++
>  qapi-schema.json |   11 +++++++++++
>  qmp-commands.hx  |   20 ++++++++++++++++++++
>  vl.c             |    9 +++++++++
>  9 files changed, 72 insertions(+), 0 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 010b8c9..3fbd975 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1570,6 +1570,8 @@ show device tree
>  show qdev device model list
>  @item info roms
>  show roms
> + at item info memory-total
> +show memory-total
>  @end table
>  ETEXI
>
> diff --git a/hmp.c b/hmp.c
> index 180ba2b..fb39b0d 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -628,6 +628,13 @@ void hmp_info_block_jobs(Monitor *mon)
>      }
>  }
>
> +void hmp_info_memory_total(Monitor *mon)
> +{
> +    uint64_t ram_total;
> +    ram_total = (uint64_t)qmp_query_memory_total(NULL);
> +    monitor_printf(mon, "MemTotal: %lu\n", ram_total);

Wrong format on 32 bit hosts, please use PRIu64.

> +}
> +
>  void hmp_quit(Monitor *mon, const QDict *qdict)
>  {
>      monitor_suspend(mon);
> diff --git a/hmp.h b/hmp.h
> index 0ab03be..25a3a70 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -36,6 +36,7 @@ void hmp_info_spice(Monitor *mon);
>  void hmp_info_balloon(Monitor *mon);
>  void hmp_info_pci(Monitor *mon);
>  void hmp_info_block_jobs(Monitor *mon);
> +void hmp_info_memory_total(Monitor *mon);
>  void hmp_quit(Monitor *mon, const QDict *qdict);
>  void hmp_stop(Monitor *mon, const QDict *qdict);
>  void hmp_system_reset(Monitor *mon, const QDict *qdict);
> diff --git a/hw/dimm.c b/hw/dimm.c
> index e384952..f181e54 100644
> --- a/hw/dimm.c
> +++ b/hw/dimm.c
> @@ -189,6 +189,20 @@ void dimm_setup_fwcfg_layout(uint64_t *fw_cfg_slots)
>      }
>  }
>
> +uint64_t get_hp_memory_total(void)
> +{
> +    DimmBus *bus;
> +    DimmDevice *slot;
> +    uint64_t info = 0;
> +
> +    QLIST_FOREACH(bus, &memory_buses, next) {
> +        QTAILQ_FOREACH(slot, &bus->dimmlist, nextdimm) {
> +            info += slot->size;
> +        }
> +    }
> +    return info;
> +}
> +
>  static int dimm_init(DeviceState *s)
>  {
>      DimmBus *bus = DIMM_BUS(qdev_get_parent_bus(s));
> diff --git a/hw/dimm.h b/hw/dimm.h
> index 75a6911..5130b2c 100644
> --- a/hw/dimm.h
> +++ b/hw/dimm.h
> @@ -85,5 +85,6 @@ DimmBus *dimm_bus_create(Object *parent, const char *name, uint32_t max_dimms,
>      dimm_calcoffset_fn pmc_set_offset);
>  void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t node,
>          uint32_t dimm_idx, uint32_t populated);
> +uint64_t get_hp_memory_total(void);
>
>  #endif
> diff --git a/monitor.c b/monitor.c
> index c0e32d6..6e87d0d 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2708,6 +2708,13 @@ static mon_cmd_t info_cmds[] = {
>          .mhandler.info = hmp_info_balloon,
>      },
>      {
> +        .name       = "memory-total",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "show total memory size",
> +        .mhandler.info = hmp_info_memory_total,
> +    },
> +    {
>          .name       = "qtree",
>          .args_type  = "",
>          .params     = "",
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 5dfa052..33f88d6 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2903,6 +2903,17 @@
>  { 'command': 'query-target', 'returns': 'TargetInfo' }
>
>  ##
> +# @query-memory-total:
> +#
> +# Returns total memory in bytes, including hotplugged dimms
> +#
> +# Returns: int
> +#
> +# Since: 1.4
> +##
> +{ 'command': 'query-memory-total', 'returns': 'int' }
> +
> +##
>  # @QKeyCode:
>  #
>  # An enumeration of key name.
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 5c692d0..a99117a 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -2654,3 +2654,23 @@ EQMP
>          .args_type  = "",
>          .mhandler.cmd_new = qmp_marshal_input_query_target,
>      },
> +
> +    {
> +        .name       = "query-memory-total",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_memory_total
> +    },
> +SQMP
> +query-memory-total
> +----------
> +
> +Return total memory in bytes, including hotplugged dimms
> +
> +Example:
> +
> +-> { "execute": "query-memory-total" }
> +<- {
> +      "return": 1073741824
> +   }
> +
> +EQMP
> diff --git a/vl.c b/vl.c
> index 8406933..80803c5 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -126,6 +126,7 @@ int main(int argc, char **argv)
>  #include "hw/xen.h"
>  #include "hw/qdev.h"
>  #include "hw/loader.h"
> +#include "hw/dimm.h"
>  #include "bt-host.h"
>  #include "net.h"
>  #include "net/slirp.h"
> @@ -442,6 +443,14 @@ StatusInfo *qmp_query_status(Error **errp)
>      return info;
>  }
>
> +int64_t qmp_query_memory_total(Error **errp)
> +{
> +    uint64_t info;
> +    info = ram_size + get_hp_memory_total();
> +
> +    return (int64_t)info;
> +}
> +
>  /***********************************************************/
>  /* real time host monotonic timer */
>
> --
> 1.7.9
>



More information about the SeaBIOS mailing list