From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Davide Libenzi <davidel@xmailserver.org>,
Avi Kivity <avi@redhat.com>,
gleb@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] eventfd: new EFD_STATE flag
Date: Thu, 27 Aug 2009 12:09:26 +0300 [thread overview]
Message-ID: <20090827090925.GA8391@redhat.com> (raw)
In-Reply-To: <1251363930-3916-1-git-send-email-pbonzini@redhat.com>
On Thu, Aug 27, 2009 at 11:05:30AM +0200, Paolo Bonzini wrote:
> > Ok, so why not using the eventfd counter as state?
> > On the device side:
> >
> > void write_state(int sfd, int state) {
> > u64 cnt;
> >
> > /* Clear the current state, sfd is in non-blocking mode */
> > read(sfd,&cnt, sizeof(cnt));
> > /* Writes new state */
> > cnt = 1 + !!state;
> > write(sfd,&cnt, sizeof(cnt));
> > }
>
> It's interesting [no sarcasm intended, mind] that EFD_SEMAPHORE was
> added exactly to avoid a read+write combination for the case of
> decrementing a value. Here it's the same, just it's about the case of
> writing a *given* value. What about having EFD_STATE simply mean "do
> not use a counter, just write the value" without affecting the way
> read works, and use
>
> /* Writes new state */
> cnt = 1 + !!state;
> write(sfd,&cnt, sizeof(cnt));
That would work for kvm.
> See below?
>
> Paolo
>
> > On the hypervisor side:
> >
> > int read_state(int sfd) {
> > u64 cnt;
> >
> > read(sfd,&cnt, sizeof(cnt));
> > return state - 1;
> > }
>
>
> ------------- 8<-- ---------------
> Subject: [PATCH] eventfd: new EFD_ABSOLUTE flag
>
> This implements a new EFD_ABSOLUTE flag for eventfd.
> This changes eventfd behaviour so that write simply
> stores the value written, and is always non-blocking.
>
> Untested (I just modified Michael's patch, and given
> the simpler code I'm not sure it's now worthwhile
> introducing the inline functions), but otherwise
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> fs/eventfd.c | 13 ++++++++-----
> include/linux/eventfd.h | 4 ++--
> 2 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index 347a0e0..7b279e3 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -31,8 +31,6 @@
>
> static inline int eventfd_writeable(struct eventfd_ctx *ctx, u64 n)
> {
> - return ULLONG_MAX - n > ctx->count;
> - return (ctx->flags & EFD_ABSOLUTE) || (ULLONG_MAX - n > ctx->count);
> }
>
> static inline int eventfd_overflow(struct eventfd_ctx *ctx, u64 cnt)
> @@ -42,10 +40,14 @@
>
> static inline void eventfd_dowrite(struct eventfd_ctx *ctx, u64 ucnt)
> {
> - if (eventfd_writeable(ctx, ucnt))
> - ucnt = ULLONG_MAX - ctx->count;
> + if (ctx->flags & EFD_ABSOLUTE)
> + ctx->count = ucnt;
> + else {
> + if (ULLONG_MAX - ctx->count < ucnt)
> + ucnt = ULLONG_MAX - ctx->count;
>
> - ctx->count += ucnt;
> + ctx->count += ucnt;
> + }
> }
>
> static inline u64 eventfd_doread(struct eventfd_ctx *ctx)
> diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
> index 3b85ba6..78ff649 100644
> --- a/include/linux/eventfd.h
> +++ b/include/linux/eventfd.h
> @@ -19,11 +19,12 @@
> * shared O_* flags.
> */
> #define EFD_SEMAPHORE (1 << 0)
> +#define EFD_ABSOLUTE (1 << 1)
> #define EFD_CLOEXEC O_CLOEXEC
> #define EFD_NONBLOCK O_NONBLOCK
>
> #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
> -#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
> +#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE | EFD_ABSOLUTE)
>
> #ifdef CONFIG_EVENTFD
> --
> 1.6.2.5
next prev parent reply other threads:[~2009-08-27 9:15 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-20 15:56 Michael S. Tsirkin
2009-08-20 16:20 ` Davide Libenzi
2009-08-20 17:38 ` Avi Kivity
2009-08-20 17:44 ` Davide Libenzi
2009-08-20 17:56 ` Paolo Bonzini
2009-08-21 17:21 ` Davide Libenzi
2009-08-20 17:55 ` Michael S. Tsirkin
2009-08-20 18:06 ` Avi Kivity
2009-08-20 18:28 ` Michael S. Tsirkin
2009-08-23 13:01 ` Avi Kivity
2009-08-23 13:36 ` Michael S. Tsirkin
2009-08-23 13:40 ` Avi Kivity
2009-08-23 14:30 ` Michael S. Tsirkin
2009-08-23 16:51 ` Paolo Bonzini
2009-08-24 18:25 ` Davide Libenzi
2009-08-24 18:31 ` Avi Kivity
2009-08-24 22:08 ` Davide Libenzi
2009-08-24 22:10 ` Paolo Bonzini
2009-08-24 22:32 ` Davide Libenzi
2009-08-25 6:59 ` Paolo Bonzini
2009-08-25 4:26 ` Avi Kivity
2009-08-24 21:49 ` Michael S. Tsirkin
2009-08-24 22:15 ` Davide Libenzi
2009-08-25 7:22 ` Michael S. Tsirkin
2009-08-25 21:57 ` Davide Libenzi
2009-08-26 10:29 ` Michael S. Tsirkin
2009-08-26 10:41 ` Avi Kivity
2009-08-26 17:45 ` Davide Libenzi
2009-08-26 18:58 ` Avi Kivity
2009-08-26 19:13 ` Davide Libenzi
2009-08-26 19:42 ` Avi Kivity
2009-08-26 19:44 ` Davide Libenzi
2009-08-26 23:30 ` Davide Libenzi
2009-08-27 4:13 ` Avi Kivity
2009-08-27 8:06 ` Michael S. Tsirkin
2009-08-27 14:20 ` Davide Libenzi
2009-08-26 19:50 ` Gleb Natapov
2009-08-26 20:04 ` Davide Libenzi
2009-08-27 5:25 ` Gleb Natapov
2009-08-27 9:05 ` Paolo Bonzini
2009-08-27 9:09 ` Michael S. Tsirkin [this message]
2009-08-27 14:21 ` Davide Libenzi
2009-08-27 14:30 ` Michael S. Tsirkin
2009-08-27 14:38 ` Davide Libenzi
2009-08-27 14:49 ` Michael S. Tsirkin
2009-08-27 15:29 ` Davide Libenzi
2009-08-27 17:09 ` Davide Libenzi
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=20090827090925.GA8391@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=davidel@xmailserver.org \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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
Powered by JetHome