[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/5] Add qemu_mbind interface for pinning memory to
From: |
Wanlong Gao |
Subject: |
[Qemu-devel] [PATCH 4/5] Add qemu_mbind interface for pinning memory to host node |
Date: |
Thu, 23 May 2013 16:47:21 +0800 |
Add qemu_mbind() interface for pinning memory to host node
manually. Use the mbind() syscall wrapper which defined
in libnuma.
Signed-off-by: Wanlong Gao <address@hidden>
---
configure | 18 ++++++++++++++++++
include/qemu/osdep.h | 26 ++++++++++++++++++++++++++
util/osdep.c | 15 +++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/configure b/configure
index 5ae7e4a..5364d01 100755
--- a/configure
+++ b/configure
@@ -3141,6 +3141,20 @@ if compile_prog "" "" ; then
fi
##########################################
+# check if we have mbind
+
+mbind=no
+cat > $TMPC << EOF
+#include <numaif.h>
+int main(void) { return mbind(0, 0, MPOL_BIND, 0, 0, 0); }
+EOF
+if compile_prog "" "-lnuma"; then
+ mbind=yes
+ LIBS="-lnuma $LIBS"
+ libs_qga="-lnuma $libs_qga"
+fi
+
+##########################################
# check if we have usable SIGEV_THREAD_ID
sigev_thread_id=no
@@ -3560,6 +3574,7 @@ echo "preadv support $preadv"
echo "fdatasync $fdatasync"
echo "madvise $madvise"
echo "posix_madvise $posix_madvise"
+echo "mbind $mbind"
echo "sigev_thread_id $sigev_thread_id"
echo "uuid support $uuid"
echo "libcap-ng support $cap_ng"
@@ -3875,6 +3890,9 @@ fi
if test "$posix_madvise" = "yes" ; then
echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
fi
+if test "$mbind" = "yes"; then
+ echo "CONFIG_MBIND=y" >> $config_host_mak
+fi
if test "$sigev_thread_id" = "yes" ; then
echo "CONFIG_SIGEV_THREAD_ID=y" >> $config_host_mak
fi
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 57d7b1f..82a790e 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -152,6 +152,32 @@ int qemu_madvise(void *addr, size_t len, int advice);
int qemu_open(const char *name, int flags, ...);
int qemu_close(int fd);
+#define QEMU_MPOL_INVALID -1
+
+#if defined(CONFIG_MBIND)
+#include <numaif.h>
+/* Policies */
+#define QEMU_MPOL_DEFAULT MPOL_DEFAULT
+#define QEMU_MPOL_PREFERRED MPOL_PREFERRED
+#define QEMU_MPOL_BIND MPOL_BIND
+#define QEMU_MPOL_INTERLEAVE MPOL_INTERLEAVE
+/* Flags for qemu_mbind */
+#define QEMU_MPOL_MF_STRICT MPOL_MF_STRICT
+#define QEMU_MPOL_MF_MOVE MPOL_MF_MOVE
+#define QEMU_MPOL_MF_MOVE_ALL MPOL_MF_MOVE_ALL
+#else
+#define QEMU_MPOL_DEFAULT QEMU_MPOL_INVALID
+#define QEMU_MPOL_PREFERRED QEMU_MPOL_INVALID
+#define QEMU_MPOL_BIND QEMU_MPOL_INVALID
+#define QEMU_MPOL_INTERLEAVE QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_STRICT QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_MOVE QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_MOVE_ALL QEMU_MPOL_INVALID
+#endif
+int qemu_mbind(void *addr, unsigned long len, int mode,
+ unsigned long *nodemask, unsigned long maxnode,
+ unsigned flags);
+
#if defined(__HAIKU__) && defined(__i386__)
#define FMT_pid "%ld"
#elif defined(WIN64)
diff --git a/util/osdep.c b/util/osdep.c
index 685c8ae..70f33c7 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -37,6 +37,10 @@
#include <sys/mman.h>
#endif
+#if defined(CONFIG_MBIND)
+#include <numaif.h>
+#endif
+
#ifdef CONFIG_SOLARIS
#include <sys/types.h>
#include <sys/statvfs.h>
@@ -472,3 +476,14 @@ writev(int fd, const struct iovec *iov, int iov_cnt)
return readv_writev(fd, iov, iov_cnt, true);
}
#endif
+
+int qemu_mbind(void *addr, unsigned long len, int mode,
+ unsigned long *nodemask, unsigned long maxnode,
+ unsigned flags)
+{
+#if defined(CONFIG_MBIND)
+ return mbind(addr, len, mode, nodemask, maxnode, flags);
+#else
+ return 0;
+#endif
+}
--
1.8.3.rc2.10.g0c2b1cf