public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>, Anthony Liguori <aliguori@us.ibm.com>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>
Subject: [patch 02/13] QEMU: introduce QEMUDevice
Date: Thu, 17 Apr 2008 17:10:23 -0300	[thread overview]
Message-ID: <20080417203026.379177631@localhost.localdomain> (raw)
In-Reply-To: 20080417201021.515148882@localhost.localdomain

[-- Attachment #1: qemu-device --]
[-- Type: text/plain, Size: 4734 bytes --]

Introduce a QEMUDevice type to allow global knowledge of present devices.

At the moment its only used for locking purposes, but not limited to that.


Index: kvm-userspace.io/qemu/qemu-common.h
===================================================================
--- kvm-userspace.io.orig/qemu/qemu-common.h
+++ kvm-userspace.io/qemu/qemu-common.h
@@ -27,6 +27,8 @@
 #define ENOMEDIUM ENODEV
 #endif
 
+#include "qemu-device.h"
+
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
Index: kvm-userspace.io/qemu/vl.c
===================================================================
--- kvm-userspace.io.orig/qemu/vl.c
+++ kvm-userspace.io/qemu/vl.c
@@ -32,6 +32,7 @@
 #include "net.h"
 #include "console.h"
 #include "sysemu.h"
+#include "qemu-common.h"
 #include "gdbstub.h"
 #include "qemu-timer.h"
 #include "qemu-char.h"
@@ -270,6 +271,13 @@ void decorate_application_name(char *app
     }
 }
 
+int qemu_register_device(QEMUDevice *qemu_device)
+{
+    qemu_mutex_init(&qemu_device->lock);
+
+    return 0;
+}
+
 /***********************************************************/
 /* x86 ISA bus support */
 
Index: kvm-userspace.io/qemu/hw/hw.h
===================================================================
--- kvm-userspace.io.orig/qemu/hw/hw.h
+++ kvm-userspace.io/qemu/hw/hw.h
@@ -99,6 +99,8 @@ typedef void QEMUResetHandler(void *opaq
 
 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
 
+int qemu_register_device(QEMUDevice *qemu_device);
+
 /* These should really be in isa.h, but are here to make pc.h happy.  */
 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
Index: kvm-userspace.io/qemu/cpu-all.h
===================================================================
--- kvm-userspace.io.orig/qemu/cpu-all.h
+++ kvm-userspace.io/qemu/cpu-all.h
@@ -17,6 +17,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#include "qemu-device.h"
 #ifndef CPU_ALL_H
 #define CPU_ALL_H
 
Index: kvm-userspace.io/qemu/qemu-device.h
===================================================================
--- /dev/null
+++ kvm-userspace.io/qemu/qemu-device.h
@@ -0,0 +1,85 @@
+#ifndef QEMU_DEVICE_H
+#define QEMU_DEVICE_H
+#include <unistd.h>
+#if defined (_POSIX_THREADS)
+#include <stdlib.h>
+#include <pthread.h>
+#define DEBUG_PTHREADS
+#ifndef DEBUG_PTHREADS
+#define qemu_mutex_t pthread_mutex_t
+#define qemu_mutex_lock(mutex) pthread_mutex_lock(mutex)
+#define qemu_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
+#define assert_is_locked(mutex) do { } while (0)
+static inline void qemu_mutex_init(qemu_mutex_t *mutex)
+{
+    pthread_mutex_init(mutex, NULL);
+}
+#else
+#include <execinfo.h>
+
+struct qemu_mutex_t {
+    pthread_mutex_t mutex;
+    pthread_t owner;
+};
+
+typedef struct qemu_mutex_t qemu_mutex_t;
+
+static void print_backtrace(void)
+{
+    void *buffer[4096];
+    int len;
+
+    len = backtrace(buffer, sizeof(buffer));
+    backtrace_symbols_fd(buffer, len, 2);
+}
+
+static inline void assert_is_locked(qemu_mutex_t *mutex)
+{
+    if (mutex->owner != pthread_self()) {
+        printf("assert failure, not locked!\n");
+        print_backtrace();
+        exit(0);
+    }
+}
+
+static inline void qemu_mutex_lock(qemu_mutex_t *mutex)
+{
+    if (!mutex) {
+        print_backtrace();
+        exit(0);
+    }
+    if (mutex->owner == pthread_self()) {
+        printf("attempting to acquire lock twice!\n");
+        print_backtrace();
+        exit(0);
+    }
+    pthread_mutex_lock(&mutex->mutex);
+    mutex->owner = pthread_self();
+}
+
+static inline void qemu_mutex_unlock(qemu_mutex_t *mutex)
+{
+    if (mutex->owner != pthread_self()) {
+        printf("thread %lx attempting to release lock acquired by %lx\n",
+                (unsigned long)pthread_self(), (unsigned long)mutex->owner);
+        print_backtrace();
+        exit(0);
+    }
+    mutex->owner = 0;
+    pthread_mutex_unlock(&mutex->mutex);
+}
+
+static inline void qemu_mutex_init(qemu_mutex_t *mutex)
+{
+    pthread_mutex_init(&mutex->mutex, NULL);
+    mutex->owner = 0;
+}
+#endif /* DEBUG_PTHREADS */
+#endif /* _POSIX_THREADS */
+
+struct QEMUDevice {
+    qemu_mutex_t lock;
+};
+
+typedef struct QEMUDevice QEMUDevice;
+#endif /* QEMU_DEVICE_H */

-- 


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  parent reply	other threads:[~2008-04-17 20:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-17 20:10 [patch 00/13] RFC: split the global mutex Marcelo Tosatti
2008-04-17 20:10 ` [patch 01/13] QEMU: get rid of global cpu_single_env Marcelo Tosatti
2008-04-17 20:10 ` Marcelo Tosatti [this message]
2008-04-17 20:10 ` [patch 03/13] QEMU: make esp.c build conditional to SPARC target Marcelo Tosatti
2008-04-17 20:10 ` [patch 04/13] QEMU: plug QEMUDevice pt1 / ioport awareness Marcelo Tosatti
2008-04-17 20:10 ` [patch 05/13] QEMU: add a mutex to protect IRQ chip data structures Marcelo Tosatti
2008-04-17 20:10 ` [patch 06/13] QEMU: plug QEMUDevice pt2 / iomem awareness Marcelo Tosatti
2008-04-17 20:10 ` [patch 07/13] QEMU: grab device lock for ioport/iomem processing Marcelo Tosatti
2008-04-17 20:10 ` [patch 08/13] QEMU: character device locking Marcelo Tosatti
2008-04-17 20:10 ` [patch 09/13] QEMU: network " Marcelo Tosatti
2008-04-17 20:10 ` [patch 10/13] QEMU: get rid of aiocb cache Marcelo Tosatti
2008-04-17 20:10 ` [patch 11/13] QEMU: block device locking Marcelo Tosatti
2008-04-17 20:10 ` [patch 12/13] QEMU: scsi-disk reentrancy fix Marcelo Tosatti
2008-04-17 20:10 ` [patch 13/13] QEMU/KVM: get rid of global lock Marcelo Tosatti
2008-04-20 11:16 ` [patch 00/13] RFC: split the global mutex Avi Kivity
2008-04-21  0:00   ` Marcelo Tosatti
2008-04-21  6:10     ` Avi Kivity

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=20080417203026.379177631@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /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