Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building stand-alone programs #363

Merged
merged 30 commits into from
Mar 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9ae09cb
Imported alt_getopt.lua to lib/lua/
lukego Feb 4, 2015
6d2a292
alt_getopt: Make module name match directory
lukego Feb 4, 2015
72eeebf
main: New front-end "snabb <PROGRAM> [ARGS].."
lukego Feb 6, 2015
2a727a0
snsh: Snabb Shell program
lukego Feb 6, 2015
a45fef8
packetblaster: loadgen reinvented as a program
lukego Feb 6, 2015
117e577
Makefile: Build programs in bin/
lukego Feb 6, 2015
10697cd
.gitignore updated
lukego Feb 6, 2015
8ef8bff
Makefile: Build only bin/snabb by default
lukego Feb 13, 2015
2ad90b0
snsh: Implement -P and -j arguments
lukego Feb 13, 2015
3d846b0
main.lua: Simplify program name interpretation
lukego Feb 13, 2015
272ccc3
snabbmark: new program for benchmarking
lukego Feb 13, 2015
c2d239a
snabbnfv: new program for the NFV functionality
lukego Feb 13, 2015
88f4dc6
snabbnfv: Add -B (--benchmark) argument
lukego Feb 21, 2015
3b8d459
src/Makefile: make ./snabb default target and add '.inc' files
lukego Feb 22, 2015
747f0e8
apps.vhost: Make vhost-user compatible with ljsyscall
lukego Feb 22, 2015
e49a292
apps.vhost: Remove vhost client app
lukego Feb 22, 2015
aa78770
main.lua: Require ljsyscall
lukego Feb 22, 2015
86f62c3
core.lib: Add have_module() and dogetopt()
lukego Feb 22, 2015
1918f98
core.main: Use have_module() to better detect programs
lukego Feb 22, 2015
9fd2851
snabbmark: Refactor usage into README
lukego Feb 22, 2015
7179e19
packetblaster: Refactor usage into README
lukego Feb 22, 2015
798cc6a
snsh: Refactor usage into README and use lib.dogetopt()
lukego Feb 22, 2015
49cadd6
Refactor NFV and Neutron functionality into programs/nfv/
lukego Feb 22, 2015
36ddd39
Remove the designs/ directory entirely
lukego Feb 22, 2015
9f1319f
Merge branch 'master' into program
lukego Feb 22, 2015
e1f852f
watchdog/selftest.sh: Updated to use snsh
lukego Feb 22, 2015
a910409
.gitignore: Removed git conflict markers
lukego Feb 22, 2015
ddd187f
New usage: packetblaster replay <file> <port...>
lukego Mar 1, 2015
eb759fe
Update dangling references to 'loadgen' (now packetblaster)
lukego Mar 1, 2015
e1a2b50
Makefile, src/Makefile: Submodule mistake proofing
lukego Mar 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
obj
*~
*.so
Expand All @@ -8,5 +9,7 @@ obj
/src/testlog
/src/apps/ipv6/selftest.cap.output
/src/apps/keyed_ipv6_tunnel/selftest.cap.output
/src/apps/vpn/vpws-selftest-customer.cap.output
/src/apps/vpn/vpws-selftest-uplink.cap.output
/src/syscall.lua
/src/syscall
29 changes: 17 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SYSCALL := src/syscall.lua
LUAJIT_CFLAGS := -DLUAJIT_USE_PERFTOOLS -DLUAJIT_USE_GDBJIT -DLUAJIT_NUMMODE=3 -include $(CURDIR)/gcc-preinclude.h

all: $(LUAJIT_O) $(SYSCALL)
@echo "Building snabbswitch"
cd src && $(MAKE)

install: all
Expand All @@ -23,30 +24,34 @@ install_compute_node: install
install -D src/scripts/sysv/default/snabb-nfv-sync-agent ${PREFIX}/etc/default/snabb-nfv-sync-agent

$(LUAJIT_O): check_luajit deps/luajit/Makefile
echo 'Building LuaJIT\n'
(cd deps/luajit && \
@echo 'Building LuaJIT'
@(cd deps/luajit && \
$(MAKE) PREFIX=`pwd`/usr/local \
CFLAGS="$(LUAJIT_CFLAGS)" && \
$(MAKE) DESTDIR=`pwd` install)
$(MAKE) DESTDIR=`pwd` install && \
git describe > ../luajit.vsn)
(cd deps/luajit/usr/local/bin; ln -fs luajit-2.1.0-alpha luajit)

check_luajit:
@if [ ! -f deps/luajit/Makefile ]; then \
echo "Can't find deps/luajit/. You might need to: git submodule update --init"; exit 1; \
echo "Initializing LuaJIT submodule.."; \
git submodule update --init deps/luajit; \
fi

$(SYSCALL): check_syscall
echo 'Copying ljsyscall components'
mkdir -p src/syscall/linux
cp -p deps/ljsyscall/syscall.lua src/
cp -p deps/ljsyscall/syscall/*.lua src/syscall/
cp -p deps/ljsyscall/syscall/linux/*.lua src/syscall/linux/
cp -pr deps/ljsyscall/syscall/linux/x64 src/syscall/linux/
cp -pr deps/ljsyscall/syscall/shared src/syscall/
@echo 'Copying ljsyscall components'
@mkdir -p src/syscall/linux
@cp -p deps/ljsyscall/syscall.lua src/
@cp -p deps/ljsyscall/syscall/*.lua src/syscall/
@cp -p deps/ljsyscall/syscall/linux/*.lua src/syscall/linux/
@cp -pr deps/ljsyscall/syscall/linux/x64 src/syscall/linux/
@cp -pr deps/ljsyscall/syscall/shared src/syscall/
@(cd deps/ljsyscall; git describe > ../ljsyscall.vsn)

check_syscall:
@if [ ! -f deps/ljsyscall/syscall.lua ]; then \
echo "Can't find deps/ljsyscall/. You might need to: git submodule update --init"; exit 1; \
echo "Initializing ljsyscall submodule.."; \
git submodule update --init deps/ljsyscall; \
fi

clean:
Expand Down
2 changes: 1 addition & 1 deletion deps/luajit
Submodule luajit updated from 04dc64 to 392b6c
59 changes: 50 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ E= @echo
#Q=
#E= @:

# Required submodule versions.
# Defined here to detect version mismatches at build time.
LUAJIT_VSN := "v2.0.3-328-g04dc64b"
LJSYSCALL_VSN := "v0.10-65-g7081d97"

TEST_SKIPPED="43"

SRCDIR = $(shell find . -type d -not -regex './obj.*' -printf '%P ')
Expand All @@ -14,6 +19,9 @@ CSRC = $(shell find . -regex '[^\#]*\.c' -printf '%P ')
CHDR = $(shell find . -regex '[^\#]*\.h' -printf '%P ')
ASM = $(shell find . -regex '[^\#]*\.dasc' -printf '%P ')
RMSRC = $(shell find . -name README.md.src -printf '%P ')
# regexp is to include program/foo but not program/foo/bar
PROGRAM = $(shell find program -regex '^[^/]+/[^/]+' -type d -printf '%P ')
INCSRC = $(shell find . -regex '[^\#]*\.inc' -printf '%P ')

LUAOBJ := $(patsubst %.lua,obj/%_lua.o,$(LUASRC))
COBJ := $(patsubst %.c,obj/%_c.o, $(CSRC))
Expand All @@ -22,6 +30,8 @@ ASMOBJ := $(patsubst %.dasc,obj/%_dasc.o, $(ASM))
JITOBJS:= $(patsubst %,obj/jit_%.o,$(JITSRC))
EXTRAOBJS := obj/jit_tprof.o obj/jit_vmprof.o obj/strict.o
RMOBJS := $(patsubst %.src,%,$(RMSRC))
INCOBJ := $(patsubst %.inc,obj/%_inc.o, $(INCSRC))
EXE := bin/snabb $(patsubst %,bin/%,$(PROGRAM))

# TESTMODS expands to:
# core.memory core.lib ...
Expand All @@ -37,19 +47,43 @@ TESTSCRIPTS = $(shell find . -name "selftest.sh" -executable | xargs)

PATH := ../deps/luajit/usr/local/bin:$(PATH)

all: snabb

markdown: $(RMOBJS)

snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)
snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ) $(INCOBJ) $(LUAJIT_A)
$(E) "SUBMODULES"
@if grep -vqF $(LUAJIT_VSN) ../deps/luajit.vsn || \
grep -vqF $(LJSYSCALL_VSN) ../deps/ljsyscall.vsn; then \
echo "Error: Submodule version mismatch" >&2; \
echo "luajit:" >&2; \
echo " require: $(LUAJIT_VSN)" >&2; \
echo " found: $(shell cat ../deps/luajit.vsn)" >&2; \
echo "ljsyscall:" >&2; \
echo " require: $(LJSYSCALL_VSN)" >&2; \
echo " found: $(shell cat ../deps/ljsyscall.vsn) " >&2; \
echo "Please update and rebuild submodules." >&2; \
echo "" >&2; \
echo "Cheat sheet:" >&2; \
echo " cd snabbswitch" >&2; \
echo " git submodule update" >&2; \
echo " make clean" >&2; \
echo " make -j" >&2; \
echo "" >&2; \
exit 1; \
fi
$(E) "LINK $@"
$(Q) gcc -Wl,--no-as-needed -Wl,-E -Werror -Wall -o $@ $^ \
../deps/luajit/src/libluajit.a \
-lrt -lc -ldl -lm -lpthread
@echo -n "Firmware: "
@echo -n "BINARY "
@ln -fs snabb snabbswitch
@ls -sh snabb

all: $(EXE)

$(EXE): snabb
$(E) "PROGRAM $@"
$(Q) install -D snabb $@

markdown: $(RMOBJS)

test: $(TESTMODS) $(TESTSCRIPTS)

test_ci: FAIL_ON_FIRST="true"
Expand All @@ -58,7 +92,7 @@ test_ci: $(TESTMODS) $(TESTSCRIPTS)

$(TESTMODS): testlog snabb
$(E) "TEST $@"
$(Q) ./snabb -t $@ > testlog/$@ 2>&1 || ( \
$(Q) ./snabb snsh -t $@ > testlog/$@ 2>&1 || ( \
EXITCODE="$$?"; \
[ "$$EXITCODE" -eq $(TEST_SKIPPED) ] \
&& ( \
Expand Down Expand Up @@ -89,7 +123,7 @@ $(TESTSCRIPTS): testlog snabb
) \
)

$(OBJDIR) testlog:
$(OBJDIR) bin testlog:
$(E) "DIR $@"
$(Q) mkdir -p $@

Expand Down Expand Up @@ -122,6 +156,13 @@ $(RMOBJS): %: %.src
$(E) "MARKDOWN $@"
$(Q) scripts/process-markdown $< > $@

$(INCOBJ): obj/%_inc.o: %.inc Makefile | $(OBJDIR)
$(E) "INC $@"
@(echo -n "return [=============["; \
cat $<; \
echo "]=============]") > $(basename $@).luainc
$(Q) luajit -bg -n $(subst /,.,$*)_inc $(basename $@).luainc $@

# extra/ third party bits and pieces
obj/strict.o: extra/strict.lua | $(OBJDIR)
$(E) "LUA $@"
Expand Down Expand Up @@ -152,7 +193,7 @@ doc/snabbswitch.epub: doc/snabbswitch.md
$(E) "PANDOC $@"
$(Q) (cd doc; pandoc --self-contained --css="style.css" -S -s --toc --chapters -o snabbswitch.epub snabbswitch.md)

CLEAN = snabb snabbswitch obj doc/snabbswitch.* doc/.images/* testlog
CLEAN = snabb snabbswitch obj bin doc/snabbswitch.* doc/.images/* testlog

clean:
$(E) "RM $(CLEAN)"
Expand Down
16 changes: 0 additions & 16 deletions src/apps/vhost/raw.lua

This file was deleted.

14 changes: 9 additions & 5 deletions src/apps/vhost/vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
// ranges we want to use for DMA. The kernel uses this to create a
// shared memory mapping.

struct vhost_memory_region {
/*
struct vhostu_memory_region {
uint64_t guest_phys_addr;
uint64_t memory_size;
uint64_t userspace_addr;
uint64_t flags_padding; // no flags currently specified
};
*/

enum { VHOST_MEMORY_MAX_NREGIONS = 8 };

/*
struct vhost_memory {
uint32_t nregions;
uint32_t padding;
struct vhost_memory_region regions[VHOST_MEMORY_MAX_NREGIONS];
struct vhostu_memory_region regions[VHOST_MEMORY_MAX_NREGIONS];
};
*/

// vhost is the top-level structure that the application allocates and
// initializes to open a virtio/vhost network device.
Expand All @@ -41,9 +45,9 @@ struct vhost {
// Below are structures imported from Linux headers.
// This is purely to avoid a compile-time dependency on those headers,
// which has been an problem on certain development machines.
struct vhost_vring_state { unsigned int index, num; };
struct vhost_vring_file { unsigned int index; int fd; };
struct vhost_vring_addr {
struct vhostu_vring_state { unsigned int index, num; };
struct vhostu_vring_file { unsigned int index; int fd; };
struct vhostu_vring_addr {
unsigned int index, flags;
uint64_t desc_user_addr, used_user_addr, avail_user_addr, log_guest_addr;
};
Expand Down
Loading