public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <haveblue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Amit Shah <amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: Slow Kernel Boot
Date: Tue, 08 Jan 2008 11:13:08 -0800	[thread overview]
Message-ID: <1199819588.9834.72.camel@localhost> (raw)
In-Reply-To: <200801081212.53737.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

On Tue, 2008-01-08 at 12:12 +0530, Amit Shah wrote:
> > BIOS-provided physical RAM map:
> >  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
> >  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
> >  BIOS-e820: 00000000000e8000 - 0000000000100000 (reserved)
> >  BIOS-e820: 0000000000100000 - 00000000fffbd000 (usable)
> >  BIOS-e820: 00000000fffbd000 - 00000000ffff0000 (reserved)
> >
> > Note that this is with '-m 1G'!!  It looks to me like one of those
> 
> And there lies the problem. qemu doesn't understand suffixes like 'G'.
> If you 
> pass -m 1024, you'll boot just fine.
> 
> This is really annoying of qemu (it should either accept that input
> properly 
> or bail out); a patch is welcome!

OK.  Here's a function stolen blatantly from the kernel.  Seems to work
OK for me for:

	-m 1234
	-m 1234M
	-m 1G
	-m 99G

diff -ru orig/qemu-0.9.1/vl.c qemu-0.9.1/vl.c
--- orig/qemu-0.9.1/vl.c	2008-01-06 11:38:42.000000000 -0800
+++ qemu-0.9.1/vl.c	2008-01-08 11:23:29.000000000 -0800
@@ -8052,6 +8052,47 @@
 }
 #endif
 
+/**
+ *	memparse - parse a string with mem suffixes into a number of bytes
+ *	@ptr: Where parse begins
+ *
+ *	Parses a string into a number.  The number stored at @ptr is
+ *	potentially suffixed with %M (for megabytes, or 1048576 bytes)
+ *	or %G (for gigabytes, or 1073741824).  If the number is
+ *	suffixed with M or G, then the return value is the number
+ *	multiplied by one megabyte or one gigabyte, respectively. No
+ *	suffix implies megabytes.
+ */
+
+unsigned long long memparse (const char *ptr)
+{
+	char *endptr;
+	unsigned long ret = strtoull(ptr, &endptr, 0);
+
+	switch (*endptr) {
+	case 'G':
+	case 'g':
+		ret <<= 10;
+	case 'M':
+	case 'm':
+		ret <<= 20;
+		break;
+	default:
+		/* for backward compatibility; qemu has
+		 * traditionally taken this in plain MB */
+		ret <<= 20;
+		break;
+	}
+	if (ret <= 0)
+        	help(1);
+	if (ret > PHYS_RAM_MAX_SIZE) {
+		fprintf(stderr, "qemu: at most %d MB RAM can be simulated\n",
+			PHYS_RAM_MAX_SIZE / (1024 * 1024));
+		exit(1);
+	}
+	return ret;
+}
+
 #define MAX_NET_CLIENTS 32
 
 int main(int argc, char **argv)
@@ -8402,14 +8443,7 @@
                 help(0);
                 break;
             case QEMU_OPTION_m:
-                ram_size = atoi(optarg) * 1024 * 1024;
-                if (ram_size <= 0)
-                    help(1);
-                if (ram_size > PHYS_RAM_MAX_SIZE) {
-                    fprintf(stderr, "qemu: at most %d MB RAM can be simulated\n",
-                            PHYS_RAM_MAX_SIZE / (1024 * 1024));
-                    exit(1);
-                }
+                ram_size = memparse(optarg);
                 break;
             case QEMU_OPTION_d:
                 {
@@ -8664,6 +8698,7 @@
             }
         }
     }
+    fprintf(stderr, "qemu: using %d MB RAM\n", ram_size>>20);
 
 #ifndef _WIN32
     if (daemonize && !nographic && vnc_display == NULL) {


-- Dave


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

  parent reply	other threads:[~2008-01-08 19:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-07 22:05 Slow Kernel Boot Dave Hansen
2008-01-07 22:16 ` Izik Eidus
     [not found]   ` <4782A4AF.6020902-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-07 22:46     ` Dave Hansen
2008-01-07 22:46       ` Izik Eidus
     [not found]         ` <4782ABCA.2090303-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-07 23:03           ` Dave Hansen
2008-01-08  6:42 ` Amit Shah
     [not found]   ` <200801081212.53737.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-08 13:01     ` Amit Shah
     [not found]       ` <200801081831.54465.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-08 12:54         ` Izik Eidus
2008-01-08 13:18         ` Amit Shah
2008-01-08 19:13     ` Dave Hansen [this message]
2008-01-08 19:26       ` Daniel P. Berrange

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=1199819588.9834.72.camel@localhost \
    --to=haveblue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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