From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=55144 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ov7kF-00020I-3z for qemu-devel@nongnu.org; Mon, 13 Sep 2010 08:02:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ov7kD-0006zg-Ff for qemu-devel@nongnu.org; Mon, 13 Sep 2010 08:02:46 -0400 Received: from cantor2.suse.de ([195.135.220.15]:42635 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ov7kD-0006zS-3p for qemu-devel@nongnu.org; Mon, 13 Sep 2010 08:02:45 -0400 Message-ID: <4C8E12E3.8070502@suse.de> Date: Mon, 13 Sep 2010 14:02:43 +0200 From: Alexander Graf MIME-Version: 1.0 References: <1071EF70-1867-4099-86FD-B4AFA68AD07F@web.de> <1284296134-2503-1-git-send-email-andreas.faerber@web.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH v3] Introduce qemu_madvise() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= , qemu-devel@nongnu.org Blue Swirl wrote: > On Sun, Sep 12, 2010 at 12:55 PM, Andreas F=C3=A4rber wrote: > =20 >> From: Andreas F=C3=A4rber >> >> vl.c has a Sun-specific hack to supply a prototype for madvise(), >> but the call site has apparently moved to arch_init.c. >> >> Haiku doesn't implement madvise() in favor of posix_madvise(). >> OpenBSD and Solaris 10 don't implement posix_madvise() but madvise(). >> >> Check for madvise() and posix_madvise() in configure and supply qemu_m= advise() >> as wrapper. Prefer madvise() over posix_madvise() due to flag availabi= lity. >> Convert all callers to use qemu_madvise() and QEMU_MADV_*. No function= al change >> except for arch_init.c:ram_load() now potentially falling back to posi= x_madvise() >> or no-op in lack of both. >> >> v2 -> v3: >> * Reuse the *_MADV_* defines for QEMU_MADV_*. Suggested by Alexander G= raf. >> * Add configure check for madvise(), too. >> Add defines to Makefile, not QEMU_CFLAGS. >> Convert all callers, untested. Suggested by Blue Swirl. >> * Keep Solaris' madvise() prototype around. Pointed out by Alexander G= raf. >> >> v1 -> v2: >> * Don't rely on posix_madvise() availability, add qemu_madvise(). >> Suggested by Blue Swirl. >> >> Signed-off-by: Andreas F=C3=A4rber >> Cc: Blue Swirl >> Cc: Alexander Graf >> --- >> arch_init.c | 2 +- >> configure | 33 +++++++++++++++++++++++++++++++++ >> exec.c | 8 ++++---- >> hw/virtio-balloon.c | 4 ++-- >> kvm-all.c | 6 +++--- >> osdep.c | 15 +++++++++++++++ >> osdep.h | 25 +++++++++++++++++++++++++ >> vl.c | 3 --- >> 8 files changed, 83 insertions(+), 13 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 versio= n_id) >> #ifndef _WIN32 >> if (ch =3D=3D 0 && >> (!kvm_enabled() || kvm_has_sync_mmu())) { >> - madvise(host, TARGET_PAGE_SIZE, MADV_DONTNEED); >> + qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNE= ED); >> } >> #endif >> } else if (flags & RAM_SAVE_FLAG_PAGE) { >> diff --git a/configure b/configure >> index 4061cb7..86558eb 100755 >> --- a/configure >> +++ b/configure >> @@ -2069,6 +2069,31 @@ if compile_prog "" "" ; then >> fi >> >> ########################################## >> +# check if we have madvise >> + >> +madvise=3Dno >> +cat > $TMPC << EOF >> +#include >> +#include >> +int main(void) { return madvise(NULL, 0, MADV_DONTNEED); } >> +EOF >> +if compile_prog "" "" ; then >> + madvise=3Dyes >> +fi >> + >> +########################################## >> +# check if we have posix_madvise >> + >> +posix_madvise=3Dno >> +cat > $TMPC << EOF >> +#include >> +int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); = } >> +EOF >> +if compile_prog "" "" ; then >> + posix_madvise=3Dyes >> +fi >> + >> +########################################## >> # check if trace backend exists >> >> sh "$source_path/tracetool" "--$trace_backend" --check-backend > /dev= /null 2> /dev/null >> @@ -2226,6 +2251,8 @@ echo "KVM support $kvm" >> echo "fdt support $fdt" >> echo "preadv support $preadv" >> echo "fdatasync $fdatasync" >> +echo "madvise $madvise" >> +echo "posix_madvise $posix_madvise" >> echo "uuid support $uuid" >> echo "vhost-net support $vhost_net" >> echo "Trace backend $trace_backend" >> @@ -2466,6 +2493,12 @@ fi >> if test "$fdatasync" =3D "yes" ; then >> echo "CONFIG_FDATASYNC=3Dy" >> $config_host_mak >> fi >> +if test "$madvise" =3D "yes" ; then >> + echo "CONFIG_MADVISE=3Dy" >> $config_host_mak >> +fi >> +if test "$posix_madvise" =3D "yes" ; then >> + echo "CONFIG_POSIX_MADVISE=3Dy" >> $config_host_mak >> +fi >> >> # XXX: suppress that >> if [ "$bsd" =3D "yes" ] ; then >> diff --git a/exec.c b/exec.c >> index 380dab5..b1fe3e9 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -2841,8 +2841,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *= dev, const char *name, >> new_block->host =3D file_ram_alloc(new_block, size, mem_pa= th); >> if (!new_block->host) { >> new_block->host =3D qemu_vmalloc(size); >> -#ifdef MADV_MERGEABLE >> - madvise(new_block->host, size, MADV_MERGEABLE); >> +#ifdef QEMU_MADV_MERGEABLE >> =20 > > I'd like to avoid these #ifdefs. How about always #defining > QEMU_MADV_MERGEABLE? QEMU_MADV_* values could be synthetic and not > rely on MADV_*. > =20 Hrm. Something like #ifdef MADV_MEREABLE #define QEMU_MADV_MERGEABLE MADV_MERGEABLE #else #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID #endif would work, right? Only need to find an unused bit in madv ... Alex