qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] osdep.c patch (FreeBSD hosts)
@ 2008-05-29 21:40 Juergen Lock
  2008-05-29 21:54 ` Fabrice Bellard
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Lock @ 2008-05-29 21:40 UTC (permalink / raw)
  To: qemu-devel

Hi!

 This is what we use on FreeBSD hosts (re kqemu), maybe it can be
committed to qemu svn:  (also at
	http://www.freebsd.org/cgi/cvsweb.cgi/ports/emulators/qemu/files/patch-osdep.c?rev=1.2;content-type=text%2Fplain
)

Index: qemu/osdep.c
@@ -79,7 +79,9 @@
 
 #if defined(USE_KQEMU)
 
+#ifndef __FreeBSD__
 #include <sys/vfs.h>
+#endif
 #include <sys/mman.h>
 #include <fcntl.h>
 
@@ -90,6 +92,7 @@
     const char *tmpdir;
     char phys_ram_file[1024];
     void *ptr;
+#ifndef __FreeBSD__
 #ifdef HOST_SOLARIS
     struct statvfs stfs;
 #else
@@ -151,12 +154,20 @@
         }
         unlink(phys_ram_file);
     }
+#endif
     size = (size + 4095) & ~4095;
+#ifndef __FreeBSD__
     ftruncate(phys_ram_fd, phys_ram_size + size);
     ptr = mmap(NULL, 
                size, 
                PROT_WRITE | PROT_READ, MAP_SHARED, 
                phys_ram_fd, phys_ram_size);
+#else
+    ptr = mmap(NULL, 
+               size, 
+               PROT_WRITE | PROT_READ, MAP_PRIVATE|MAP_ANON, 
+               -1, 0);
+#endif
     if (ptr == MAP_FAILED) {
         fprintf(stderr, "Could not map physical memory\n");
         exit(1);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] osdep.c patch (FreeBSD hosts)
  2008-05-29 21:40 [Qemu-devel] osdep.c patch (FreeBSD hosts) Juergen Lock
@ 2008-05-29 21:54 ` Fabrice Bellard
  2008-05-29 22:57   ` Juergen Lock
  0 siblings, 1 reply; 6+ messages in thread
From: Fabrice Bellard @ 2008-05-29 21:54 UTC (permalink / raw)
  To: qemu-devel

Is it really needed to mmap() the RAM on FreeBSD ? This is a Linux
specific hack, and it may even be obsolete with recent Linux kernels.

Regards,

Fabrice.

Juergen Lock wrote:
> Hi!
> 
>  This is what we use on FreeBSD hosts (re kqemu), maybe it can be
> committed to qemu svn:  (also at
> 	http://www.freebsd.org/cgi/cvsweb.cgi/ports/emulators/qemu/files/patch-osdep.c?rev=1.2;content-type=text%2Fplain
> )
> 
> Index: qemu/osdep.c
> @@ -79,7 +79,9 @@
>  
>  #if defined(USE_KQEMU)
>  
> +#ifndef __FreeBSD__
>  #include <sys/vfs.h>
> +#endif
>  #include <sys/mman.h>
>  #include <fcntl.h>
>  
> @@ -90,6 +92,7 @@
>      const char *tmpdir;
>      char phys_ram_file[1024];
>      void *ptr;
> +#ifndef __FreeBSD__
>  #ifdef HOST_SOLARIS
>      struct statvfs stfs;
>  #else
> @@ -151,12 +154,20 @@
>          }
>          unlink(phys_ram_file);
>      }
> +#endif
>      size = (size + 4095) & ~4095;
> +#ifndef __FreeBSD__
>      ftruncate(phys_ram_fd, phys_ram_size + size);
>      ptr = mmap(NULL, 
>                 size, 
>                 PROT_WRITE | PROT_READ, MAP_SHARED, 
>                 phys_ram_fd, phys_ram_size);
> +#else
> +    ptr = mmap(NULL, 
> +               size, 
> +               PROT_WRITE | PROT_READ, MAP_PRIVATE|MAP_ANON, 
> +               -1, 0);
> +#endif
>      if (ptr == MAP_FAILED) {
>          fprintf(stderr, "Could not map physical memory\n");
>          exit(1);
> 
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] osdep.c patch (FreeBSD hosts)
  2008-05-29 21:54 ` Fabrice Bellard
@ 2008-05-29 22:57   ` Juergen Lock
  2008-05-29 23:03     ` Juergen Lock
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Lock @ 2008-05-29 22:57 UTC (permalink / raw)
  To: qemu-devel

On Thu, May 29, 2008 at 11:54:31PM +0200, Fabrice Bellard wrote:
> Is it really needed to mmap() the RAM on FreeBSD ? This is a Linux
> specific hack, and it may even be obsolete with recent Linux kernels.
> 
Hmm actually I don't know...  You think the...

> > +#else
> > +    ptr = mmap(NULL, 
> > +               size, 
> > +               PROT_WRITE | PROT_READ, MAP_PRIVATE|MAP_ANON, 
> > +               -1, 0);
> > +#endif

could be replaced by just malloc?  Or would there be align issues too?

 Thanx,
	Juergen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] osdep.c patch (FreeBSD hosts)
  2008-05-29 22:57   ` Juergen Lock
@ 2008-05-29 23:03     ` Juergen Lock
  2008-06-01 13:15       ` Juergen Lock
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Lock @ 2008-05-29 23:03 UTC (permalink / raw)
  To: qemu-devel

On Fri, May 30, 2008 at 12:57:13AM +0200, Juergen Lock wrote:
> On Thu, May 29, 2008 at 11:54:31PM +0200, Fabrice Bellard wrote:
> > Is it really needed to mmap() the RAM on FreeBSD ? This is a Linux
> > specific hack, and it may even be obsolete with recent Linux kernels.
> > 
> Hmm actually I don't know...  You think the...
> 
> > > +#else
> > > +    ptr = mmap(NULL, 
> > > +               size, 
> > > +               PROT_WRITE | PROT_READ, MAP_PRIVATE|MAP_ANON, 
> > > +               -1, 0);
> > > +#endif
> 
> could be replaced by just malloc?  Or would there be align issues too?

..and I just checked the manpage, our malloc page-aligns too (for sizes >=
pagesize), so at least that shouldn't be an issue.

	Juergen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] osdep.c patch (FreeBSD hosts)
  2008-05-29 23:03     ` Juergen Lock
@ 2008-06-01 13:15       ` Juergen Lock
  2008-06-06 19:39         ` Ed Maste
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Lock @ 2008-06-01 13:15 UTC (permalink / raw)
  To: qemu-devel

On Fri, May 30, 2008 at 01:03:05AM +0200, Juergen Lock wrote:
> On Fri, May 30, 2008 at 12:57:13AM +0200, Juergen Lock wrote:
> > On Thu, May 29, 2008 at 11:54:31PM +0200, Fabrice Bellard wrote:
> > > Is it really needed to mmap() the RAM on FreeBSD ? This is a Linux
> > > specific hack, and it may even be obsolete with recent Linux kernels.
> > > 
> > Hmm actually I don't know...  You think the...
> > 
> > > > +#else
> > > > +    ptr = mmap(NULL, 
> > > > +               size, 
> > > > +               PROT_WRITE | PROT_READ, MAP_PRIVATE|MAP_ANON, 
> > > > +               -1, 0);
> > > > +#endif
> > 
> > could be replaced by just malloc?  Or would there be align issues too?
> 
> ..and I just checked the manpage, our malloc page-aligns too (for sizes >=
> pagesize), so at least that shouldn't be an issue.

Ok and I just tested the following patch and it worked for me:

Index: qemu/osdep.c
@@ -83,7 +83,9 @@
 
 #if defined(USE_KQEMU)
 
+#ifndef __FreeBSD__
 #include <sys/vfs.h>
+#endif
 #include <sys/mman.h>
 #include <fcntl.h>
 
@@ -94,6 +96,7 @@
     const char *tmpdir;
     char phys_ram_file[1024];
     void *ptr;
+#ifndef __FreeBSD__
 #ifdef HOST_SOLARIS
     struct statvfs stfs;
 #else
@@ -155,7 +158,9 @@
         }
         unlink(phys_ram_file);
     }
+#endif
     size = (size + 4095) & ~4095;
+#ifndef __FreeBSD__
     ftruncate(phys_ram_fd, phys_ram_size + size);
     ptr = mmap(NULL,
                size,
@@ -165,6 +170,13 @@
         fprintf(stderr, "Could not map physical memory\n");
         exit(1);
     }
+#else
+    ptr = malloc(size);
+    if (ptr == NULL) {
+        fprintf(stderr, "Could not allocate physical memory\n");
+        exit(1);
+    }
+#endif
     phys_ram_size += size;
     return ptr;
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] osdep.c patch (FreeBSD hosts)
  2008-06-01 13:15       ` Juergen Lock
@ 2008-06-06 19:39         ` Ed Maste
  0 siblings, 0 replies; 6+ messages in thread
From: Ed Maste @ 2008-06-06 19:39 UTC (permalink / raw)
  To: qemu-devel

On Sun, Jun 01, 2008 at 03:15:07PM +0200, Juergen Lock wrote:

> > ..and I just checked the manpage, our malloc page-aligns too (for sizes >=
> > pagesize), so at least that shouldn't be an issue.

We also have posix_memalign available on FreeBSD for guaranteed
alignment.

I think this file should be able to be simplified greatly -- perhaps
all of the current kqemu_vmalloc should be moved into an #ifdef LINUX
(or whatever the #define is) and other systems can use plain
old posix_memalign/memalign/etc.

- Ed

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-06 19:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-29 21:40 [Qemu-devel] osdep.c patch (FreeBSD hosts) Juergen Lock
2008-05-29 21:54 ` Fabrice Bellard
2008-05-29 22:57   ` Juergen Lock
2008-05-29 23:03     ` Juergen Lock
2008-06-01 13:15       ` Juergen Lock
2008-06-06 19:39         ` Ed Maste

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).