Skip to content

Commit

Permalink
lock remote emu
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwljwljwljw committed Jan 8, 2021
1 parent fe1dc59 commit ba6bb9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ VERILATOR_FLAGS = --top-module $(EMU_TOP) \
--output-split 5000 \
--output-split-cfuncs 5000

EMU_MK := $(BUILD_DIR)/emu-compile/V$(EMU_TOP).mk
EMU_MK := $(abspath $(BUILD_DIR)/emu-compile/V$(EMU_TOP).mk)
EMU_DEPS := $(EMU_VFILES) $(EMU_CXXFILES)
EMU_HEADERS := $(shell find $(EMU_CSRC_DIR) -name "*.h")
EMU := $(BUILD_DIR)/emu
Expand All @@ -134,12 +134,23 @@ REF_SO := $(NEMU_HOME)/build/riscv64-nemu-interpreter-so
$(REF_SO):
$(MAKE) -C $(NEMU_HOME) ISA=riscv64 SHARE=1

$(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS) $(REF_SO)
LOCK = /var/emu/emu.lock
LOCK_BIN = $(abspath $(BUILD_DIR)/lock-emu)

$(LOCK_BIN): ./scripts/utils/lock-emu.c
gcc $^ -o $@

$(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS) $(REF_SO) $(LOCK_BIN)
date -R
ifeq ($(REMOTE),localhost)
CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))
CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(dir $(EMU_MK)) -f $(EMU_MK)
else
ssh -tt $(REMOTE) 'CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) -j128 VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))'
@echo "try to get emu.lock ..."
ssh -tt $(REMOTE) '$(LOCK_BIN) $(LOCK)'
@echo "get lock"
ssh -tt $(REMOTE) 'CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) -j230 VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(dir $(EMU_MK))-f $(EMU_MK)'
@echo "release lock ..."
ssh -tt $(REMOTE) 'rm -f $(LOCK)'
endif
date -R

Expand Down
27 changes: 27 additions & 0 deletions scripts/utils/lock-emu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>

int tryLock(char * file){
return open(file, O_CREAT | O_EXCL);
}

int main(int argc, char* argv[]){
int fd;
if(argc < 2){
printf("arguments are not right!\n");
exit(-1);
}

do{
fd = tryLock(argv[1]);
if(fd > 0) break;
printf("there is a job running, waiting ...\n");
sleep(10);
} while(1);

return 0;
}

0 comments on commit ba6bb9d

Please sign in to comment.