提交 ba6bb9d6 编写于 作者: L LinJiawei

lock remote emu

上级 fe1dc59c
......@@ -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
......@@ -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
......
#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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册