All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Introduce qemu_madvise()
@ 2010-09-11 17:05 Andreas Färber
  2010-09-11 21:37 ` Alexander Graf
  2010-09-12  7:20 ` [Qemu-devel] " Blue Swirl
  0 siblings, 2 replies; 28+ messages in thread
From: Andreas Färber @ 2010-09-11 17:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, Andreas Färber

From: Andreas Färber <afaerber@opensolaris.org>

vl.c has a Sun-specific hack to supply a prototype for madvise(),
but the call site has apparently moved to arch_init.c.
The underlying issue is that madvise() is not a POSIX function,
therefore Solaris' _POSIX_C_SOURCE suppresses the prototype.

Haiku doesn't implement madvise() at all.
OpenBSD however doesn't implement posix_madvise().

Check for posix_madvise() in configure and supply qemu_madvise() as wrapper.
Use qemu_madvise() in arch_init.c's ram_load().

http://www.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html

Remaining madvise() users:
exec.c: limited to __linux__ and/or MADV_MERGEABLE (no POSIX equivalent)
kvm-all.c: limited to MADV_DONTFORK (no POSIX equivalent),
           otherwise runtime error if !kvm_has_sync_mmu()
hw/virtio-balloon.c: limited to __linux__

v1 -> v2:
* Don't rely on posix_madvise() availability, add qemu_madvise().
  Suggested by Blue Swirl.

Signed-off-by: Andreas Färber <afaerber@opensolaris.org>
Cc: Blue Swirl <blauwirbel@gmail.com>
---
 arch_init.c |    2 +-
 configure   |   11 +++++++++++
 osdep.c     |   26 ++++++++++++++++++++++++++
 osdep.h     |    4 ++++
 vl.c        |    3 ---
 5 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index e468c0c..a910033 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -396,7 +396,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
 #ifndef _WIN32
             if (ch == 0 &&
                 (!kvm_enabled() || kvm_has_sync_mmu())) {
-                madvise(host, TARGET_PAGE_SIZE, MADV_DONTNEED);
+                qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
             }
 #endif
         } else if (flags & RAM_SAVE_FLAG_PAGE) {
diff --git a/configure b/configure
index 4061cb7..5e6f3e1 100755
--- a/configure
+++ b/configure
@@ -2069,6 +2069,17 @@ if compile_prog "" "" ; then
 fi
 
 ##########################################
+# check if we have posix_madvise
+
+cat > $TMPC << EOF
+#include <sys/mman.h>
+int main(void) { posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); return 0; }
+EOF
+if compile_prog "" "" ; then
+    QEMU_CFLAGS="-DCONFIG_POSIX_MADVISE ${QEMU_CFLAGS}"
+fi
+
+##########################################
 # check if trace backend exists
 
 sh "$source_path/tracetool" "--$trace_backend" --check-backend > /dev/null 2> /dev/null
diff --git a/osdep.c b/osdep.c
index 30426ff..8c09597 100644
--- a/osdep.c
+++ b/osdep.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/mman.h>
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -139,6 +140,31 @@ void qemu_vfree(void *ptr)
 
 #endif
 
+int qemu_madvise(void *addr, size_t len, int advice)
+{
+#ifdef CONFIG_POSIX_MADVISE
+    switch (advice) {
+        case QEMU_MADV_DONTNEED:
+            advice = POSIX_MADV_DONTNEED;
+            break;
+        default:
+            fprintf(stderr, "Advice %d unhandled.\n", advice);
+            abort();
+    }
+    return posix_madvise(addr, len, advice);
+#else
+    switch (advice) {
+        case QEMU_MADV_DONTNEED:
+            advice = MADV_DONTNEED;
+            break;
+        default:
+            fprintf(stderr, "Advice %d unhandled.\n", advice);
+            abort();
+    }
+    return madvise(addr, len, advice);
+#endif
+}
+
 int qemu_create_pidfile(const char *filename)
 {
     char buffer[128];
diff --git a/osdep.h b/osdep.h
index 1cdc7e2..9f0da46 100644
--- a/osdep.h
+++ b/osdep.h
@@ -90,6 +90,10 @@ void *qemu_memalign(size_t alignment, size_t size);
 void *qemu_vmalloc(size_t size);
 void qemu_vfree(void *ptr);
 
+#define QEMU_MADV_DONTNEED 1
+
+int qemu_madvise(void *addr, size_t len, int advice);
+
 int qemu_create_pidfile(const char *filename);
 
 #ifdef _WIN32
diff --git a/vl.c b/vl.c
index 3f45aa9..d352d18 100644
--- a/vl.c
+++ b/vl.c
@@ -80,9 +80,6 @@
 #include <net/if.h>
 #include <syslog.h>
 #include <stropts.h>
-/* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
-   discussion about Solaris header problems */
-extern int madvise(caddr_t, size_t, int);
 #endif
 #endif
 #endif
-- 
1.7.2.2

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

end of thread, other threads:[~2010-09-25 15:18 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-11 17:05 [Qemu-devel] [PATCH] Introduce qemu_madvise() Andreas Färber
2010-09-11 21:37 ` Alexander Graf
2010-09-11 22:39   ` Andreas Färber
2010-09-11 22:47     ` Alexander Graf
2010-09-12  7:20 ` [Qemu-devel] " Blue Swirl
2010-09-12  8:50   ` Andreas Färber
2010-09-12  9:02     ` Blue Swirl
2010-09-12 12:55     ` [Qemu-devel] [PATCH v3] " Andreas Färber
2010-09-12 17:29       ` [Qemu-devel] " Blue Swirl
2010-09-13 12:02         ` Alexander Graf
2010-09-13 21:26         ` [Qemu-devel] [RFC v4] " Andreas Färber
2010-09-14 16:31           ` [Qemu-devel] " Blue Swirl
2010-09-14 16:34             ` Alexander Graf
2010-09-14 17:10               ` Blue Swirl
2010-09-14 20:28                 ` [Qemu-devel] [PATCH v5] " Andreas Färber
2010-09-14 20:36                   ` [Qemu-devel] " Blue Swirl
2010-09-14 20:39                     ` Andreas Färber
2010-09-15 18:09                       ` [Qemu-devel] [PATCH v6] " Andreas Färber
2010-09-15 19:00                         ` [Qemu-devel] " Blue Swirl
2010-09-15 19:35                           ` Andreas Färber
2010-09-15 19:50                             ` Blue Swirl
2010-09-15 20:07                               ` Andreas Färber
2010-09-19 10:11                               ` [Qemu-devel] [PATCH v7] " Andreas Färber
2010-09-20 20:33                                 ` [Qemu-devel] " Blue Swirl
2010-09-24 18:08                                   ` Andreas Färber
2010-09-25  7:49                                     ` Blue Swirl
2010-09-25 10:58                                       ` [Qemu-devel] [PATCH v8] " Andreas Färber
2010-09-25 15:17                                         ` [Qemu-devel] " Blue Swirl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.