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

lib: rename arch/sim to arch/lib #25

Merged
merged 1 commit into from
Dec 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ install:
compiler:
- gcc
script:
- make defconfig ARCH=sim && make clean ARCH=sim && make library ARCH=sim
- ./arch/sim/test/nuse/nuse-test.sh
- make defconfig ARCH=lib && make clean ARCH=lib && make library ARCH=lib
- ./arch/lib/test/nuse/nuse-test.sh
63 changes: 63 additions & 0 deletions Documentation/virtual/libos-howto.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Library operating system (libos) version of Linux
=================================================

* Overview

New hardware independent architecture 'arch/lib', configured by
CONFIG_LIB gives you two features.

- network stack in userspace (NUSE)
- network simulator integration, which is called Direct Code Execution
(DCE)
(- more abstracted rump hypercall implementation will be a future
direction)

In both features, Linux kernel network stack is running on top of
userspace application with a linked or dynamically loaded library.

They have their own, isolated network stack from host operating system
so they are configured different IP addresses as other virtualization
methods do.

* Install

configuration of arch/lib follows a standard configuration of kernel.

make defconfig ARCH=lib

or

make menuconfig ARCH=lib

then you can build a set of libraries for libos.

make library ARCH=lib

* Hello world

you may first need to configure a configuration file, named
'nuse.conf' so that the library version of network stack can know what
kind of IP configuration should be used.

sudo NUSECONF=nuse.conf ./nuse ping 172.16.0.2


* Features
- per-userspace application network stack
- netmap support
- intel dpdk support


* Setup

* Files

files sim*.[c] indicate to relate to simulator via Direct Code
Execution (DCE), files nuse*.[ch] indicate to relate to Network Stack
in Userspace (NUSE). other files are shared functions between them.


* Authors
Mathieu Lacage <mathieu.lacage@gmail.com>
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
Frederic Urbani <frederic.urbani@inria.fr>
1 change: 1 addition & 0 deletions arch/sim/.gitignore → arch/lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ objs.mk
timeconst.h
hz.bc
crc32table.h
*.d
10 changes: 5 additions & 5 deletions arch/sim/Kconfig → arch/lib/Kconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
config SIM
config LIB
bool
default y
select PROC_FS
select PROC_SYSCTL
select SYSCTL
select SYSFS
help
The 'sim' architecture is a user-mode version of the linux
kernel that includes only its network stack and is used
within the ns-3 simulator. For more information, about ns-3,
see http://www.nsnam.org.
The 'lib' architecture is a library (user-mode) version of
the linux kernel that includes only its network stack and is
used within the userspace application, and ns-3 simulator.
For more information, about ns-3, see http://www.nsnam.org.

config EXPERIMENTAL
def_bool y
Expand Down
128 changes: 83 additions & 45 deletions arch/sim/Makefile → arch/lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARCH_DIR := arch/sim
ARCH_DIR := arch/lib
SRCDIR=$(dir $(firstword $(MAKEFILE_LIST)))

CC = gcc
Expand All @@ -13,7 +13,7 @@ netmap_yes=nuse-vif-netmap.c
netmap_no=

DPDK?=no
dpdk_yes=$(opt_$(OPT)) -g3 -fPIC -m64 -pthread -march=native $(DPDK_CFLAGS)
dpdk_yes=nuse-vif-dpdk.c
dpdk_no=
dpdkl_yes=-L $(RTE_SDK)/$(RTE_TARGET) -L$(RTE_SDK)/$(RTE_TARGET)/lib $(ARCH_DIR)/nuse-vif-dpdk.o $(DPDK_LDLIBS)
dpdkl_no=
Expand All @@ -36,13 +36,7 @@ DPDK_LDLIBS += -lrte_pmd_virtio_uio -lrte_pmd_vmxnet3_uio -lrte_pmd_ixgbe \

quiet_cmd_vif_dpdk = VIF-DPDK $@
cmd_vif_dpdk = \
$(CC) $(dpdk_$(DPDK)) -c $^ -o $@

dpdk-sdk:
git submodule init; \
git submodule update; \
cd $(srctree)/dpdk ; make CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=y T=$(shell expr `uname -m`)-native-linuxapp-gcc config && \
make SRCARCH=x86 CONFIG_RTE_BUILD_COMBINE_LIBS=y EXTRA_CFLAGS="-fPIC -g" ;\
$(CC) $(CFLAGS_USPACE) -m64 -pthread -march=native $(DPDK_CFLAGS) -c $^ -o $@

$(ARCH_DIR)/nuse-vif-dpdk.o: $(ARCH_DIR)/nuse-vif-dpdk.c
ifeq ($(DPDK), yes)
Expand All @@ -51,20 +45,40 @@ else
@echo -n ""
endif

dpdk-sdk:
git submodule init; \
git submodule update; \
cd $(srctree)/dpdk ; make CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=y T=$(shell expr `uname -m`)-native-linuxapp-gcc config && \
make SRCARCH=x86 CONFIG_RTE_BUILD_COMBINE_LIBS=y EXTRA_CFLAGS="-fPIC -g" ;\


NUSE_SRC=\
nuse.c nuse-fiber.c nuse-vif.c nuse-poll.c \
nuse-vif-rawsock.c nuse-glue.c nuse-hostcalls.c nuse-config.c \
nuse-vif-tap.c $(netmap_$(NETMAP))

NUSE_USPACE_SRC=\
nuse-fiber.c nuse-vif.c nuse-hostcalls.c nuse-config.c \
nuse-vif-rawsock.c nuse-vif-tap.c $(netmap_$(NETMAP))

NUSE_SRC=$(NUSE_USPACE_SRC)\
nuse.c nuse-poll.c nuse-glue.c

SIM_SRC=\
fs.c random.c softirq.c time.c \
glue.c sim-device.c sysctl.c timer.c \
hrtimer.c sched.c sim-socket.c sysfs.c workqueue.c \
sim.c

LIB_SRC=\
lib.c lib-device.c lib-socket.c random.c softirq.c time.c \
glue.c fs.c sysctl.c timer.c \
hrtimer.c sched.c sysfs.c workqueue.c \
print.c security.c slab.c tasklet.c \
proc.c seq.c socket.c tasklet-hrtimer.c \
cred.c pid.c modules.c filemap.c splice.c vmscan.c \
dcache.c super.c inode.c $(NUSE_SRC)
dcache.c super.c inode.c

DEPENDS=$(addprefix $(ARCH_DIR)/,\
$(addsuffix .d,$(basename $(NUSE_SRC)))\
$(addsuffix .d,$(basename $(SIM_SRC)))\
$(addsuffix .d,$(basename $(LIB_SRC)))\
)
-include $(DEPENDS)


COV?=no
cov_yes=-fprofile-arcs -ftest-coverage
Expand All @@ -79,27 +93,37 @@ PIC?=yes
pic_yes=-fpic -DPIC
pic_no=-mcmodel=large
PIC_CFLAGS=$(pic_$(PIC))
KERNEL_LIB=libnuse-linux$(KERNELVERSION).so
NUSE_LIB=libnuse-linux$(KERNELVERSION).so
SIM_LIB=libsim-linux$(KERNELVERSION).so
KERNEL_LIB=$(NUSE_LIB) $(SIM_LIB)
SIM_OBJ=$(addprefix $(ARCH_DIR)/,$(addsuffix .o,$(basename $(SIM_SRC))))
CFLAGS+= \
$(opt_$(OPT)) -g3 -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs \
-fno-inline -iwithprefix $(srctree)/include -DKBUILD_BASENAME=\"clnt\" \
-fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks \
NUSE_OBJ=$(addprefix $(ARCH_DIR)/,$(addsuffix .o,$(basename $(NUSE_SRC))))
LIB_OBJ=$(addprefix $(ARCH_DIR)/,$(addsuffix .o,$(basename $(LIB_SRC))))

CFLAGS_USPACE= \
$(opt_$(OPT)) -g3 -Wall -Wstrict-prototypes -Wno-trigraphs \
-fno-inline -fno-strict-aliasing -fno-common \
-fno-delete-null-pointer-checks \
-fno-stack-protector -Wno-unused -Wno-pointer-sign \
-DKBUILD_MODNAME=\"nsc\" -DMODVERSIONS -DEXPORT_SYMTAB \
-include $(srctree)/include/linux/kconfig.h \
$(PIC_CFLAGS) -D_DEBUG $(cov_$(COV))

CFLAGS+= \
$(CFLAGS_USPACE) -D__KERNEL__ -iwithprefix $(srctree)/include \
-DKBUILD_BASENAME=\"clnt\" -DKBUILD_MODNAME=\"nsc\" -DMODVERSIONS \
-DEXPORT_SYMTAB -include $(srctree)/include/linux/kconfig.h \
-U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \
-I$(ARCH_DIR)/include -I$(srctree)/include \
-I$(ARCH_DIR) -I$(srctree) -I$(srctree) -I$(srctree)/include/uapi \
$(PIC_CFLAGS) -D_DEBUG $(cov_$(COV))
-I$(ARCH_DIR) -I$(srctree) -I$(srctree) -I$(srctree)/include/uapi

include $(ARCH_DIR)/processor.mk

ifeq ($(PROCESSOR_SIZE),64)
CFLAGS+= -DCONFIG_64BIT
endif

LDFLAGS += -nodefaultlibs -g3 -Wl,-O1 -Wl,-T$(ARCH_DIR)/linker.lds $(covl_$(COV)) -lpthread -ldl -lrt
LDFLAGS += -shared -nodefaultlibs -g3 -Wl,-O1 -Wl,-T$(ARCH_DIR)/linker.lds $(covl_$(COV))
LDFLAGS_NUSE = -ldl -lpthread -lrt
LDFLAGS_SIM =

modules:=
all-obj-for-clean:=
Expand Down Expand Up @@ -156,8 +180,8 @@ quiet_cmd_autoconf = GEN $@
$(AUTOCONF): $(ARCH_DIR)/generate-autoconf.py $(srctree)/.config $(ARCH_DIR)/timeconst.h
$(call if_changed,autoconf)
quiet_cmd_timeconst = GEN $@
cmd_timeconst = echo "hz=$(CONFIG_HZ)" > $(srctree)/arch/sim/hz.bc ; \
bc $(srctree)/arch/sim/hz.bc kernel/time/timeconst.bc > $@
cmd_timeconst = echo "hz=$(CONFIG_HZ)" > $(ARCH_DIR)/hz.bc ; \
bc $(ARCH_DIR)/hz.bc kernel/time/timeconst.bc > $@
$(ARCH_DIR)/timeconst.h: $(srctree)/.config
$(call if_changed,timeconst)
quiet_cmd_linker = GEN $@
Expand All @@ -182,17 +206,25 @@ $(CRC32TABLE): $(srctree)/lib/gen_crc32table
$(call if_changed,crc32)

KERNEL_BUILTIN=$(addprefix $(srctree)/,$(addsuffix builtin.o,$(dirs)))
OBJS=$(SIM_OBJ) $(foreach builtin,$(KERNEL_BUILTIN),$(if $($(builtin)),$($(builtin))))

OBJS=$(LIB_OBJ) $(foreach builtin,$(KERNEL_BUILTIN),$(if $($(builtin)),$($(builtin))))
quiet_cmd_cc = CC $@
cmd_cc = mkdir -p $(dir $@); \
$(CC) $(CFLAGS) -c $^ -o $@
$(CC) $(CFLAGS) -c $< -o $@
quiet_cmd_linkko = KO $@
cmd_linkko = $(CC) -shared -o $@ -nostdlib $^
quiet_cmd_builtin = BUILTIN $@
cmd_builtin = mkdir -p $(dir $(srctree)/$@); if test -n "$($(srctree)/$@)"; then for f in $($(srctree)/$@); \
do $(AR) Tcru $@ $$f; done; else $(AR) Tcru $@; fi

# XXX: no idea how to handle these exception cleanly..
quiet_cmd_ccusp = CC $@
cmd_ccusp = mkdir -p $(dir $@); \
$(CC) $(CFLAGS_USPACE) -c $< -o $@

NUSE_USPACE_OBJ=$(addprefix $(ARCH_DIR)/,$(addsuffix .o,$(basename $(NUSE_USPACE_SRC))))
$(NUSE_USPACE_OBJ): %.o : %.c
$(call if_changed,ccusp)

%/builtin.o:
$(call if_changed,builtin)
%.ko:%.o
Expand All @@ -213,34 +245,40 @@ install: modules library

install-dir:

.patch.ts: $(ARCH_DIR)/kernel.patch
CWD=`pwd` && cd $(srctree) && patch -p1 < $(ARCH_DIR)/kernel$(KERNEL_VERSION).patch && cd $$CWD && touch $(ARCH_DIR)/.patch.ts
unpatch:
CWD=`pwd` && cd $(srctree) && git reset --hard $(KERNEL_VERSION) && cd $$CWD && rm -f $(ARCH_DIR)/.patch.ts

quiet_cmd_clean = CLEAN $@
cmd_clean = for f in $(foreach m,$(modules),$($(m))) ; do rm -f $$f 2>/dev/null; done ; \
for f in $(OBJS) $(KERNEL_LIB) $(modules) $(all-obj-for-clean); do rm -f $$f; done 2>/dev/null ;\
for f in $(ALL_OBJS) $(KERNEL_LIB) $(modules) $(all-obj-for-clean); do rm -f $$f; done 2>/dev/null ;\
rm -rf $(ARCH_DIR)/linker.lds $(AUTOCONF) $(ARCH_DIR)/objs.mk $(ARCH_DIR)/timeconst.h 2>/dev/null ;\
rm -f $(DEPENDS) ;\
$(MAKE) -C $(ARCH_DIR)/test clean ;\
$(MAKE) -C $(ARCH_DIR)/test/nuse clean

ALL_OBJS=$(OBJS) $(KERNEL_LIB) $(modules) $(all-obj-for-clean)
ALL_OBJS=$(NUSE_OBJ) $(SIM_OBJ) $(OBJS) $(KERNEL_LIB) $(modules) $(all-obj-for-clean)
archclean:
$(call if_changed,clean)

quiet_cmd_linklib = LIB $@
quiet_cmd_linknuse = LIBNUSE $@
# order of $(dpdkl_$(DPDK)) matters...
cmd_linklib = $(CC) -shared -Wl,--whole-archive $(dpdkl_$(DPDK)) $(OBJS) $(LDFLAGS) -o $@; \
ln -s -f $(KERNEL_LIB) libnuse-linux.so
cmd_linknuse = $(CC) -Wl,--whole-archive $(dpdkl_$(DPDK)) $(OBJS) $(NUSE_OBJ) $(LDFLAGS) $(LDFLAGS_NUSE) -o $@; \
ln -s -f $(NUSE_LIB) libnuse-linux.so

$(KERNEL_LIB): $(ARCH_DIR)/objs.mk $(CRC32TABLE) $(AUTOCONF) $(ARCH_DIR)/nuse-vif-dpdk.o $(OBJS) $(ARCH_DIR)/linker.lds
$(call if_changed,linklib)
quiet_cmd_linksim = LIBSIM $@
cmd_linksim = $(CC) -Wl,--whole-archive $(OBJS) $(SIM_OBJ) $(LDFLAGS) $(LDFLAGS_SIM) -o $@; \
ln -s -f $(SIM_LIB) liblinux.so

$(NUSE_LIB): $(ARCH_DIR)/objs.mk $(CRC32TABLE) $(AUTOCONF) $(ARCH_DIR)/nuse-vif-dpdk.o $(NUSE_OBJ) $(OBJS) $(ARCH_DIR)/linker.lds
$(call if_changed,linknuse)

$(SIM_LIB): $(ARCH_DIR)/objs.mk $(CRC32TABLE) $(AUTOCONF) $(SIM_OBJ) $(OBJS) $(ARCH_DIR)/linker.lds
$(call if_changed,linksim)

test:
$(MAKE) -C $(ARCH_DIR)/test

.PHONY : clean $(dpdk_$(DPDK))
.PHONY : clean depend

%.d:%.c
@set -e; $(CC) -MM -MT $(<:.c=.o) $(CFLAGS) $< > $@

KBUILD_KCONFIG := arch/$(ARCH)/Kconfig
CLEAN_FILES := $(ARCH_DIR)/test/buildtop/source/quagga/lib/*.lo
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion arch/sim/defconfig → arch/lib/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Linux kernel version: KERNELVERSION
# Mon Jan 31 22:06:08 2011
#
CONFIG_SIM=y
CONFIG_LIB=y
# CONFIG_MMU is not set
# CONFIG_FPU is not set
# CONFIG_SMP is not set
Expand Down
2 changes: 1 addition & 1 deletion arch/sim/filemap.c → arch/lib/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ssize_t generic_file_aio_read(struct kiocb *a, const struct iovec *b,
unsigned long c, loff_t d)
{
sim_assert(false);
lib_assert(false);

return 0;
}
Expand Down
Loading