Skip to content

Commit 7587bf6

Browse files
authored
Unify host locks (#2049)
* Take and release host lock in event_execute This avoids having to take and release the lock at finer granularity while executing an event. * Destroy and free Host shared memory
1 parent 93e4da0 commit 7587bf6

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

src/lib/shim/shim_shmem.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ struct _ShimShmemThread {
9696
size_t shimshmemhost_size() { return sizeof(ShimShmemHost); }
9797

9898
void shimshmemhost_init(ShimShmemHost* hostMem, Host* host, uint32_t unblockedSyscallLimit) {
99-
// We use `memcpy` here to allow us to initialize the const members of
100-
// `hostMem`.
99+
assert(hostMem);
100+
// We use `memcpy` instead of struct assignment here to allow us to
101+
// initialize the const members of `hostMem`.
101102
memcpy(hostMem,
102103
&(ShimShmemHost){
103104
.host_id = host_getID(host),
@@ -111,6 +112,11 @@ void shimshmemhost_init(ShimShmemHost* hostMem, Host* host, uint32_t unblockedSy
111112
sizeof(ShimShmemHost));
112113
}
113114

115+
void shimshmemhost_destroy(ShimShmemHost* hostMem) {
116+
assert(hostMem);
117+
pthread_mutex_destroy(&hostMem->mutex);
118+
}
119+
114120
void shimshmem_incrementUnblockedSyscallCount(ShimShmemHostLock* host) {
115121
assert(host);
116122
++host->unblocked_syscall_count;

src/lib/shim/shim_shmem.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct _ShimHostProtectedSharedMem ShimShmemHostLock;
3838

3939
size_t shimshmemhost_size();
4040
void shimshmemhost_init(ShimShmemHost* hostMem, Host* host, uint32_t unblockedSyscallLimit);
41+
void shimshmemhost_destroy(ShimShmemHost* hostMem);
4142

4243
ShimShmemHostLock* shimshmemhost_lock(ShimShmemHost* host);
4344

src/main/core/work/event.c

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void event_execute(Event* event) {
6565
MAGIC_ASSERT(event);
6666

6767
host_lock(event->dstHost);
68+
host_lockShimShmemLock(event->dstHost);
6869
worker_setActiveHost(event->dstHost);
6970

7071
/* check if we are allowed to execute or have to wait for cpu delays */
@@ -91,6 +92,7 @@ void event_execute(Event* event) {
9192
}
9293

9394
worker_setActiveHost(NULL);
95+
host_unlockShimShmemLock(event->dstHost);
9496
host_unlock(event->dstHost);
9597
}
9698

src/main/host/host.c

+4
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ void host_shutdown(Host* host) {
308308

309309
if(host->defaultAddress) address_unref(host->defaultAddress);
310310
if(host->params.hostname) g_free(host->params.hostname);
311+
312+
utility_assert(host_getSharedMem(host));
313+
shimshmemhost_destroy(host_getSharedMem(host));
314+
shmemallocator_globalFree(&host->shimSharedMemBlock);
311315
}
312316

313317
void host_ref(Host* host) {

src/main/host/process.c

-4
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,6 @@ void process_continue(Process* proc, Thread* thread) {
648648
worker_setActiveProcess(proc);
649649
worker_setActiveThread(thread);
650650

651-
host_lockShimShmemLock(proc->host);
652-
653651
#ifdef USE_PERF_TIMERS
654652
/* time how long we execute the program */
655653
g_timer_start(proc->cpuDelayTimer);
@@ -678,8 +676,6 @@ void process_continue(Process* proc, Thread* thread) {
678676
_process_check_thread(proc, thread);
679677
}
680678

681-
host_unlockShimShmemLock(proc->host);
682-
683679
worker_setActiveProcess(NULL);
684680
worker_setActiveThread(NULL);
685681
}

src/main/host/syscall_condition.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,7 @@ static bool _syscallcondition_satisfied(SysCallCondition* cond, Host* host) {
336336
// Primary condition is satisfied.
337337
return true;
338338
}
339-
ShimShmemHostLock* hostLock = shimshmemhost_lock(host_getSharedMem(host));
340-
bool signalPending = thread_unblockedSignalPending(cond->thread, hostLock);
341-
shimshmemhost_unlock(host_getSharedMem(host), &hostLock);
339+
bool signalPending = thread_unblockedSignalPending(cond->thread, host_getShimShmemLock(host));
342340
if (signalPending) {
343341
return true;
344342
}

0 commit comments

Comments
 (0)