All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 0/5] Spread the use of QEMU threading & locking API
Date: Thu, 05 Apr 2012 09:51:56 +0200	[thread overview]
Message-ID: <4F7D4F1C.3070208@redhat.com> (raw)
In-Reply-To: <4F7C82B8.8090602@siemens.com>

Il 04/04/2012 19:19, Jan Kiszka ha scritto:
>>>> >>> Yep, this screams for something like QemuEvent which pleases all users
>>>> >>> of current qemu_eventfd and EventNotifier - and fit into the existing
>>>> >>> threading/synchronization abstraction layout.
>>> >>
>>> >> Kind of, on Unix you cannot poll synchronization primitives so
> 
> Ah, you meant on Win32 you cannot poll!

No, I meant poll(2), or select if you prefer. :)

The difference between EventNotifier and Qemu{Cond,Mutex} is that the
former can be used in the main loop, the latter cannot.

Under POSIX you have file descriptors and synchronization primitives.
You can poll a set of fds, but synchronization primitives are distinct
and have separate APIs.

Under Windows you have various kinds of waitable objects.  You can poll
a set of them with WaitForMultipleObjects, and synchronization
primitives are waitable objects.  So they have no userspace-only fast
path and are much more heavyweight than POSIX, but you can poll on
different synchronization primitives at the same time.  For example you
can say "I want to get this mutex, but I also need to know if I have to
do this high-priority task; if so I won't care about getting the mutex
anymore".

Now, Qemu{Cond,Mutex} are POSIX-y (lightweight) synchronization
primitives, EventNotifier (waitable) is a Windows-y synchronization
primitive.  That's why I think it is substantially different from other
primitives in qemu-thread.{h,c}.

(Of course, theis is not entirely accurate.  Windows has always had a
POSIX-like lightweight mutex, called CRITICAL_SECTION, and we use it for
QemuMutex; starting from Vista it also grew POSIX-like lightweight
condvars and rwlocks, but QEMU Win32 code targets XP.  And eventfd could
be used to implement most Windows synchronization primitives on Linux,
possibly using EFD_SEMAPHORE).

BTW you _could_ have a QemuEvent primitive based on Windows manual-reset
events. It can be used in some cases as a replacement for condvars,
especially when you have multiple producers and a single consumer (MPSC
queue is perhaps the easiest lock-free data structure).  It can be made
very lightweight on Linux using futexes, and would also support timed
wait easily on Windows.  The API would be more or less like this:

  void qemu_event_init(QemuEvent *event, bool set);
  void qemu_event_wait(QemuEvent *event);
  void qemu_event_timedwait(QemuEvent *event, int ms);
  void qemu_event_set(QemuEvent *event);
  void qemu_event_reset(QemuEvent *event);

BTW^2 what's the guide for calling something qemu_blah?  So far my idea
was that qemu_blah should satisfy one of the following conditions:

1) it is a wrapper around a system call or ANSI C standard function;

2) it handles portability with a trivial implementation for POSIX (resp.
Win32) and a complex implementation on Win32 (resp. POSIX);

3) it modifies global state.

There are some exceptions (e.g. QemuOpts) but overall it roughly matches
cases when new qemu_* are being added.

Does it make sense?

Paolo

  reply	other threads:[~2012-04-05  7:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-04 15:08 [Qemu-devel] [PATCH 0/5] Spread the use of QEMU threading & locking API Jan Kiszka
2012-04-04 15:08 ` [Qemu-devel] [PATCH 1/5] Introduce qemu_cond_timedwait for POSIX Jan Kiszka
2012-04-04 15:08 ` [Qemu-devel] [PATCH 2/5] Switch POSIX compat AIO to QEMU abstractions Jan Kiszka
2012-04-04 15:08 ` [Qemu-devel] [PATCH 3/5] Use qemu_eventfd for POSIX AIO Jan Kiszka
2012-04-04 15:08 ` [Qemu-devel] [PATCH 4/5] Reorder POSIX compat AIO code Jan Kiszka
2012-04-04 15:08 ` [Qemu-devel] [PATCH 5/5] Switch compatfd to QEMU thread Jan Kiszka
2012-04-04 15:18 ` [Qemu-devel] [PATCH 0/5] Spread the use of QEMU threading & locking API Paolo Bonzini
2012-04-04 15:24   ` Jan Kiszka
2012-04-04 15:29     ` Paolo Bonzini
2012-04-04 15:38       ` Jan Kiszka
2012-04-04 15:43         ` Jan Kiszka
2012-04-04 16:05       ` Jan Kiszka
2012-04-04 16:39         ` Paolo Bonzini
2012-04-04 16:55           ` Jan Kiszka
2012-04-04 17:19             ` Jan Kiszka
2012-04-05  7:51               ` Paolo Bonzini [this message]
2012-04-05 10:55                 ` Jan Kiszka
2012-04-05 11:07                   ` Paolo Bonzini
2012-04-05 11:18                     ` Jan Kiszka
2012-04-05 11:29                       ` Paolo Bonzini
2012-04-05 12:04                         ` Jan Kiszka
2012-04-05 12:48                           ` Paolo Bonzini
     [not found]                             ` <4F7D977A.1020905@siemens.com>
2012-04-05 13:40                               ` Paolo Bonzini
2012-04-05 14:01                                 ` Jan Kiszka
2012-04-05 14:11                                   ` Paolo Bonzini

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=4F7D4F1C.3070208@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.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 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.