From: Wanlong Gao <gaowanlong@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: Wanlong Gao <gaowanlong@cn.fujitsu.com>
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 [thread overview]
Message-ID: <1369298842-6295-4-git-send-email-gaowanlong@cn.fujitsu.com> (raw)
In-Reply-To: <1369298842-6295-1-git-send-email-gaowanlong@cn.fujitsu.com>
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 <gaowanlong@cn.fujitsu.com>
---
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
next prev parent reply other threads:[~2013-05-23 8:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-23 8:47 [Qemu-devel] [PATCH 1/5] pci-assign: remove the duplicate function name in debug message Wanlong Gao
2013-05-23 8:47 ` [Qemu-devel] [PATCH 2/5] memory: check if the total numa memory size is equal to ram_size Wanlong Gao
2013-05-23 8:47 ` [Qemu-devel] [PATCH 3/5] memory: do not assign node_mem[] to 0 twice Wanlong Gao
2013-05-23 8:47 ` Wanlong Gao [this message]
2013-05-23 8:47 ` [Qemu-devel] [PATCH 5/5] memory: able to pin guest node memory to host node manually Wanlong Gao
2013-05-24 7:10 ` Wanlong Gao
2013-05-27 2:57 ` Wanlong Gao
2013-05-28 2:27 ` Wanlong Gao
2013-05-30 9:57 ` Wanlong Gao
2013-05-30 18:22 ` Eduardo Habkost
2013-05-31 8:45 ` Wanlong Gao
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=1369298842-6295-4-git-send-email-gaowanlong@cn.fujitsu.com \
--to=gaowanlong@cn.fujitsu.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).