rump: Enable single CPU lock semantics

* Compile in single CPU support only
* Fix 'try_enter' semtantic for mutexes
* Unschedule when entering RW locks

Issue #1409
This commit is contained in:
Sebastian Sumpf 2015-02-19 11:40:41 +01:00 committed by Christian Helmuth
parent 422923cc95
commit 47b0b9b689
4 changed files with 37 additions and 18 deletions

View File

@ -28,8 +28,8 @@ SOURCE = $(addprefix $(REP_DIR)/src/lib/rump/,$(SRC_CC))
BUILD_CMD = BUILD_CC=cc BUILD_AR=ar BUILD_NM=nm BUILD_OBJCOPY=objcopy \
AR=$(AR) NM=$(NM) OBJCOPY=$(OBJCOPY) CC_TARGET=$(shell basename $(CC)) \
$(RUMP_CONTRIB_DIR)/buildrump.sh -k -V'MAKEVERBOSE=$(VERBOSE_LEVEL)' \
-V'NOGCCERROR=1' $(RUMP_OPT) -s $(RUMP_SRC) -T $(RUMP_TOOLS) \
-o $(RUMP_OBJ) -d $(RUMP_BASE)
-V'NOGCCERROR=1' $(RUMP_OPT) -V'RUMP_LOCKS_UP=yes' \
-s $(RUMP_SRC) -T $(RUMP_TOOLS) -o $(RUMP_OBJ) -d $(RUMP_BASE)
#
# Linkage

View File

@ -230,11 +230,11 @@ int rumpuser_malloc(size_t len, int alignment, void **memp)
{
Genode::Lock::Guard guard(_alloc_lock);
int align = Genode::log2(alignment);
int align = alignment ? Genode::log2(alignment) : 0;
*memp = allocator()->alloc(len, align);
if (verbose)
PWRN("ALLOC: p: %p, s: %zx, a: %d", *memp, len, align);
PWRN("ALLOC: p: %p, s: %zx, a: %d %d", *memp, len, align, alignment);
return *memp ? 0 : -1;

View File

@ -309,15 +309,13 @@ void rumpuser_bio(int fd, int op, void *data, size_t dlen, int64_t off,
rump_biodone_fn biodone, void *donearg)
{
int nlocks;
rumpkern_unsched(&nlocks, 0);
rumpkern_unsched(&nlocks, 0);
Packet *p = backend()->alloc();
#if 0
PDBG("fd: %d op: %d len: %zu off: %lx p %p bio %p sync %u", fd, op, dlen, off,
p, donearg, !!(op & RUMPUSER_BIO_SYNC));
#endif
if (verbose)
PDBG("fd: %d op: %d len: %zu off: %lx p %p bio %p sync %u", fd, op, dlen, off,
p, donearg, !!(op & RUMPUSER_BIO_SYNC));
p->opcode= op & RUMPUSER_BIO_WRITE ? Block::Packet_descriptor::WRITE :
Block::Packet_descriptor::READ;

View File

@ -35,18 +35,19 @@ struct rumpuser_mtx
bool down(bool try_lock = false)
{
counter_lock.lock();
Genode::Lock::Guard guard(counter_lock);
if (sem.cnt() > 1)
PERR("SEM cnt > 1");
PERR("%p: SEM cnt > 1 (%d) %p", rumpuser_curlwp(), sem.cnt(), this);
bool locked = sem.cnt() <= 0;
counter_lock.unlock();
if (locked && try_lock)
return false;
if (!try_lock)
counter_lock.unlock();
sem.down();
set_owner();
@ -56,6 +57,10 @@ struct rumpuser_mtx
void up()
{
Genode::Lock::Guard guard(counter_lock);
if (sem.cnt() >= 1)
return;
clear_owner();
sem.up();
}
@ -453,10 +458,26 @@ void rumpuser_rw_init(struct rumpuser_rw **rw)
void rumpuser_rw_enter(int enum_rumprwlock, struct rumpuser_rw *rw)
{
if (enum_rumprwlock == RUMPUSER_RW_WRITER)
rw->rw.lock(false);
else
rw->rw.read_lock(false);
int nlocks;
bool try_lock = true;
bool locked = false;
while (!locked) {
if (!try_lock)
rumpkern_unsched(&nlocks, 0);
if (enum_rumprwlock == RUMPUSER_RW_WRITER)
locked = rw->rw.lock(try_lock);
else
locked = rw->rw.read_lock(try_lock);
if (!try_lock)
rumpkern_sched(nlocks, 0);
try_lock = false;
}
}