diff mbox

Introduce machine specific default memory size

Message ID 1425387274-11133-1-git-send-email-nikunj@linux.vnet.ibm.com
State New
Headers show

Commit Message

Nikunj A Dadhania March 3, 2015, 12:54 p.m. UTC
Qemu default memory of 128MB is not enough to boot spapr
guest. Introduce a property in the machine class to override the
default memory size enforced by qemu.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
---
 hw/ppc/spapr.c         |  1 +
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 +++
 vl.c                   | 12 ++++++++++++
 4 files changed, 17 insertions(+)

Comments

Markus Armbruster March 4, 2015, 7:24 a.m. UTC | #1
Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> writes:

> Qemu default memory of 128MB is not enough to boot spapr
> guest. Introduce a property in the machine class to override the
> default memory size enforced by qemu.
>
> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
> ---
>  hw/ppc/spapr.c         |  1 +
>  include/hw/boards.h    |  1 +
>  include/hw/ppc/spapr.h |  3 +++
>  vl.c                   | 12 ++++++++++++
>  4 files changed, 17 insertions(+)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 30de25d..857035e 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1686,6 +1686,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
>      mc->max_cpus = MAX_CPUS;
>      mc->no_parallel = 1;
>      mc->default_boot_order = NULL;
> +    mc->default_ram_size = SPAPR_DEFAULT_RAM_SIZE;
>      mc->kvm_type = spapr_kvm_type;
>      mc->has_dynamic_sysbus = true;
>  
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index e0a6790..9fe264f 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -106,6 +106,7 @@ struct MachineClass {
>      const char *default_display;
>      GlobalProperty *compat_props;
>      const char *hw_version;
> +    ram_addr_t default_ram_size;
>  
>      HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
>                                             DeviceState *dev);
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index 749daf4..2f83458 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -443,6 +443,9 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
>  #define SPAPR_VIO_BASE_LIOBN    0x00000000
>  #define SPAPR_PCI_BASE_LIOBN    0x80000000
>  
> +/* Default to 1GB guest ram_size */
> +#define SPAPR_DEFAULT_RAM_SIZE  (1ULL << 30)
> +
>  #define RTAS_ERROR_LOG_MAX      2048
>  
>  typedef struct sPAPRTCETable sPAPRTCETable;
> diff --git a/vl.c b/vl.c
> index eb89d62..dd56754 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4053,6 +4053,18 @@ int main(int argc, char **argv, char **envp)
>          exit(1);
>      }
>  
> +    if (machine_class->default_ram_size && ram_size < machine_class->default_ram_size) {
> +        fprintf(stderr, "qemu: %s guest ram size defaulting to %ld MB\n",
> +                machine_class->name,
> +                machine_class->default_ram_size / (1024 * 1024));

If the user explicitly asks for something, we either provide it
silently, or we error out.  This does neither.  Why?

> +        ram_size = machine_class->default_ram_size;
> +
> +        /* if maxram size is not provided in options use machine default */
> +        if (maxram_size == default_ram_size) {
> +            maxram_size = machine_class->default_ram_size;
> +        }
> +    }
> +
>      /* store value for the future use */
>      qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size);

Does not apply to master, please name your prerequisite patches or
rebase.
diff mbox

Patch

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 30de25d..857035e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1686,6 +1686,7 @@  static void spapr_machine_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = MAX_CPUS;
     mc->no_parallel = 1;
     mc->default_boot_order = NULL;
+    mc->default_ram_size = SPAPR_DEFAULT_RAM_SIZE;
     mc->kvm_type = spapr_kvm_type;
     mc->has_dynamic_sysbus = true;
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index e0a6790..9fe264f 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -106,6 +106,7 @@  struct MachineClass {
     const char *default_display;
     GlobalProperty *compat_props;
     const char *hw_version;
+    ram_addr_t default_ram_size;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 749daf4..2f83458 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -443,6 +443,9 @@  int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
 #define SPAPR_VIO_BASE_LIOBN    0x00000000
 #define SPAPR_PCI_BASE_LIOBN    0x80000000
 
+/* Default to 1GB guest ram_size */
+#define SPAPR_DEFAULT_RAM_SIZE  (1ULL << 30)
+
 #define RTAS_ERROR_LOG_MAX      2048
 
 typedef struct sPAPRTCETable sPAPRTCETable;
diff --git a/vl.c b/vl.c
index eb89d62..dd56754 100644
--- a/vl.c
+++ b/vl.c
@@ -4053,6 +4053,18 @@  int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    if (machine_class->default_ram_size && ram_size < machine_class->default_ram_size) {
+        fprintf(stderr, "qemu: %s guest ram size defaulting to %ld MB\n",
+                machine_class->name,
+                machine_class->default_ram_size / (1024 * 1024));
+        ram_size = machine_class->default_ram_size;
+
+        /* if maxram size is not provided in options use machine default */
+        if (maxram_size == default_ram_size) {
+            maxram_size = machine_class->default_ram_size;
+        }
+    }
+
     /* store value for the future use */
     qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size);