diff options
author | Havoc Pennington <hp@redhat.com> | 2003-05-11 07:59:08 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-05-11 07:59:08 +0000 |
commit | ab10ae902d8aa7c2b98fd080a7458127b1b8e648 (patch) | |
tree | b566d610ee13aa1a4ab9013eb7d19eb3dd7ad1c8 /dbus/dbus-sysdeps.c | |
parent | 27b694f6e109c78c633ddb8d96f524e46e536f4e (diff) |
2003-05-11 Havoc Pennington <hp@pobox.com>
Write a "test-profile" that does echo client-server with threads;
profile reveals lock contention, memcpy/realloc of buffers, and
UTF-8 validation as hot spots. 20% of lock contention eliminated
with dbus_atomic_inc/dec implementation on x86. Much remaining
contention is global mempool locks for GList and DBusList.
* dbus/dbus-sysdeps.c (_dbus_atomic_inc, _dbus_atomic_dec): add
x86 implementation
* dbus/dbus-connection.c (struct DBusConnection): use
dbus_atomic_t for the reference count
* dbus/dbus-message.c (struct DBusMessage): declare
dbus_atomic_t values as volatile
* configure.in: code to detect ability to use atomic integer
operations in assembly, from GLib patch
* dbus/dbus-internals.c (_dbus_verbose_real): call getpid every
time, tired of it being wrong in threads and forked processes
* glib/test-profile.c: a little program to bounce messages back
and forth between threads and eat CPU
* dbus/dbus-connection.c: add debug spew macros for debugging
thread locks; include config.h at top; fix deadlock in
dbus_connection_flush()
Diffstat (limited to 'dbus/dbus-sysdeps.c')
-rw-r--r-- | dbus/dbus-sysdeps.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 91f6e95a..c813a83c 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -1790,9 +1790,25 @@ _dbus_getgid (void) return getgid (); } - _DBUS_DEFINE_GLOBAL_LOCK (atomic); + +#ifdef DBUS_USE_ATOMIC_INT_486 +/* Taken from CVS version 1.7 of glibc's sysdeps/i386/i486/atomicity.h */ +/* Since the asm stuff here is gcc-specific we go ahead and use "inline" also */ +static inline dbus_atomic_t +atomic_exchange_and_add (volatile dbus_atomic_t *atomic, + volatile dbus_atomic_t val) +{ + register dbus_atomic_t result; + + __asm__ __volatile__ ("lock; xaddl %0,%1" + : "=r" (result), "=m" (*atomic) + : "0" (val), "m" (*atomic)); + return result; +} +#endif + /** * Atomically increments an integer * @@ -1802,8 +1818,11 @@ _DBUS_DEFINE_GLOBAL_LOCK (atomic); * @todo implement arch-specific faster atomic ops */ dbus_atomic_t -_dbus_atomic_inc (dbus_atomic_t *atomic) +_dbus_atomic_inc (volatile dbus_atomic_t *atomic) { +#ifdef DBUS_USE_ATOMIC_INT_486 + return atomic_exchange_and_add (atomic, 1); +#else dbus_atomic_t res; _DBUS_LOCK (atomic); @@ -1811,6 +1830,7 @@ _dbus_atomic_inc (dbus_atomic_t *atomic) res = *atomic; _DBUS_UNLOCK (atomic); return res; +#endif } /** @@ -1822,8 +1842,11 @@ _dbus_atomic_inc (dbus_atomic_t *atomic) * @todo implement arch-specific faster atomic ops */ dbus_atomic_t -_dbus_atomic_dec (dbus_atomic_t *atomic) +_dbus_atomic_dec (volatile dbus_atomic_t *atomic) { +#ifdef DBUS_USE_ATOMIC_INT_486 + return atomic_exchange_and_add (atomic, -1); +#else dbus_atomic_t res; _DBUS_LOCK (atomic); @@ -1831,6 +1854,7 @@ _dbus_atomic_dec (dbus_atomic_t *atomic) res = *atomic; _DBUS_UNLOCK (atomic); return res; +#endif } /** |