All of lore.kernel.org
 help / color / mirror / Atom feed
From: Blue Swirl <blauwirbel@gmail.com>
To: "Andreas Färber" <andreas.faerber@web.de>
Cc: "Alexander Graf" <agraf@suse.de>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Andreas Färber" <afaerber@opensolaris.org>
Subject: [Qemu-devel] Re: [PATCH] Introduce qemu_madvise()
Date: Sun, 12 Sep 2010 09:02:49 +0000	[thread overview]
Message-ID: <AANLkTinry4FAmM6P4yt2JymYCnUQToi=E8Ao-POS_chb@mail.gmail.com> (raw)
In-Reply-To: <1071EF70-1867-4099-86FD-B4AFA68AD07F@web.de>

On Sun, Sep 12, 2010 at 8:50 AM, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 12.09.2010 um 09:20 schrieb Blue Swirl:
>
>> On Sat, Sep 11, 2010 at 5:05 PM, Andreas Färber <andreas.faerber@web.de>
>> wrote:
>>>
>>> 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__
>>
>> For consistency, I'd convert all users. If an OS doesn't support a
>> flag, we can return something like -ENOTSUP which may be checked by
>> the caller if it cares.
>
> Will do.
>
>>> 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}"
>>
>> Please take a look around configure:2444 how to add new config flags.
>
> I did. It's just not obvious that they find their way from the Makefile to a
> C header, unlike autoconf.
>
>> I'd also add a similar check for madvise() if posix_madvise() check
>> fails.
>
> Fine with me.
>
>>> 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();
>>
>> This should be an assert, it's an internal error. It's also common to
>> both cases.
>>
>>> +    }
>>> +    return posix_madvise(addr, len, advice);
>>> +#else
>>
>> #elif defined(CONFIG_MADVISE)
>>
>>> +    switch (advice) {
>>> +        case QEMU_MADV_DONTNEED:
>>> +            advice = MADV_DONTNEED;
>>> +            break;
>>
>> case QEMU_MADV_DONTFORK:
>> #ifndef MADV_DONTFORK
>> return -ENOTSUP;
>> #else
>> advice = MADV_DONTFORK;
>> break;
>> #endif
>>
>> Same goes for MADV_MERGEABLE.
>
> So you disagree with or didn't yet read Alex' suggestion of eliminating this
> mapping code in qemu_madvise() altogether?
> Doing that in a sensible way would allow code to do:
>
> #ifdef QEMU_MADV_MERGEABLE
> ...
>
> as before at compile-time. The only qemu_madvise() error condition would
> then be the #else below.

That's one way too, if nobody cares about madvise() return values for
MADV_MERGEABLE. In any case I'd like to eliminate the #ifdefs in other
places than osdep.[ch].

  reply	other threads:[~2010-09-12  9:03 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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='AANLkTinry4FAmM6P4yt2JymYCnUQToi=E8Ao-POS_chb@mail.gmail.com' \
    --to=blauwirbel@gmail.com \
    --cc=afaerber@opensolaris.org \
    --cc=agraf@suse.de \
    --cc=andreas.faerber@web.de \
    --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 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.