From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfRDA-0008DE-MC for qemu-devel@nongnu.org; Thu, 23 May 2013 04:49:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfRD9-0002Of-1h for qemu-devel@nongnu.org; Thu, 23 May 2013 04:49:24 -0400 Received: from [222.73.24.84] (port=51104 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfRD8-0002MT-LK for qemu-devel@nongnu.org; Thu, 23 May 2013 04:49:22 -0400 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r4N8nAgn026970 for ; Thu, 23 May 2013 16:49:10 +0800 From: Wanlong Gao Date: Thu, 23 May 2013 16:47:21 +0800 Message-Id: <1369298842-6295-4-git-send-email-gaowanlong@cn.fujitsu.com> In-Reply-To: <1369298842-6295-1-git-send-email-gaowanlong@cn.fujitsu.com> References: <1369298842-6295-1-git-send-email-gaowanlong@cn.fujitsu.com> Subject: [Qemu-devel] [PATCH 4/5] Add qemu_mbind interface for pinning memory to host node List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Wanlong Gao 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 --- 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 +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 +/* 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 #endif +#if defined(CONFIG_MBIND) +#include +#endif + #ifdef CONFIG_SOLARIS #include #include @@ -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