ditch the priority inheritance locks; use malloc's version of lock
i did some testing trying to switch malloc to use the new internal lock with priority inheritance, and my malloc contention test got 20-100 times slower. if priority inheritance futexes are this slow, it's simply too high a price to pay for avoiding priority inversion. maybe we can consider them somewhere down the road once the kernel folks get their act together on this (and perferably don't link it to glibc's inefficient lock API)... as such, i've switch __lock to use malloc's implementation of lightweight locks, and updated all the users of the code to use an array with a waiter count for their locks. this should give optimal performance in the vast majority of cases, and it's simple. malloc is still using its own internal copy of the lock code because it seems to yield measurably better performance with -O3 when it's inlined (20% or more difference in the contention stress test).
This commit is contained in:
parent
e7655ed37b
commit
4750cf4202
15 changed files with 54 additions and 77 deletions
|
|
@ -10,7 +10,7 @@
|
|||
#include <pthread.h>
|
||||
#include "libc.h"
|
||||
|
||||
static int lock;
|
||||
static int lock[2];
|
||||
static const char *log_ident;
|
||||
static int log_opt;
|
||||
static int log_facility = LOG_USER;
|
||||
|
|
@ -36,10 +36,10 @@ void closelog(void)
|
|||
{
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
LOCK(&lock);
|
||||
LOCK(lock);
|
||||
close(log_fd);
|
||||
log_fd = -1;
|
||||
UNLOCK(&lock);
|
||||
UNLOCK(lock);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
}
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ void openlog(const char *ident, int opt, int facility)
|
|||
{
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
LOCK(&lock);
|
||||
LOCK(lock);
|
||||
__openlog(ident, opt, facility);
|
||||
UNLOCK(&lock);
|
||||
UNLOCK(lock);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
|
|||
if (log_fd < 0) {
|
||||
__openlog(log_ident, log_opt | LOG_NDELAY, log_facility);
|
||||
if (log_fd < 0) {
|
||||
UNLOCK(&lock);
|
||||
UNLOCK(lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
|
|||
sendto(log_fd, buf, l, 0, (void *)&log_addr, 11);
|
||||
}
|
||||
|
||||
UNLOCK(&lock);
|
||||
UNLOCK(lock);
|
||||
}
|
||||
|
||||
void __vsyslog(int priority, const char *message, va_list ap)
|
||||
|
|
@ -106,9 +106,9 @@ void __vsyslog(int priority, const char *message, va_list ap)
|
|||
int cs;
|
||||
if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
LOCK(&lock);
|
||||
LOCK(lock);
|
||||
_vsyslog(priority, message, ap);
|
||||
UNLOCK(&lock);
|
||||
UNLOCK(lock);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue