diff --git a/Makefile b/Makefile index c917c7e08..f752a093b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TARGETS = node pipe signal test # Libraries -LIBS = libvillas.so +LIBS = libvillas.so thirdparty/xilinx/libxil.so DEBUG = 1 @@ -18,7 +18,7 @@ LIB_OBJS = sample.o path.o node.o \ timing.o # Source directories -VPATH = src lib +VPATH = src lib lib/kernel lib/nodes lib/hooks lib/fpga # Default prefix for installation PREFIX ?= /usr/local @@ -29,13 +29,14 @@ V ?= 2 GIT_REV=$(shell git rev-parse --short HEAD) # Compiler and linker flags -CC ?= gcc LDLIBS = -pthread -lrt -lm -lconfig -lvillas -CFLAGS += -std=c11 -Iinclude/ -I. -MMD -mcx16 +LIB_LDFLAGS = -shared + +CFLAGS += -std=c11 -Iinclude -Iinclude/villas -I. -MMD -mcx16 CFLAGS += -Wall -fdiagnostics-color=auto CFLAGS += -D_GIT_REV='"$(GIT_REV)"' -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE=1 -DV=$(V) -LDFLAGS += -L. -Wl,-rpath,'$$ORIGIN' +LDFLAGS += -pthread -L. -Wl,-rpath,'$$ORIGIN' # pkg-config dependencies PKGS = libconfig @@ -52,27 +53,29 @@ endif ######## Node types ######## -# Enable file node type support -ifndef DISABLE_FILE - LIB_OBJS += file.o -endif +# file node-type is always supported +LIB_OBJS += file.o # Enable Socket node type when libnl3 is available ifeq ($(shell pkg-config libnl-route-3.0; echo $$?),0) - LIB_OBJS += socket.o nl.o tc.o if.o msg.o - PKGS += libnl-route-3.0 + LIB_OBJS += socket.o nl.o tc.o if.o msg.o + PKGS += libnl-route-3.0 endif -## Enable GTFPGA support when libpci is available -#ifeq ($(shell pkg-config libpci; echo $$?),0) -# LIB_OBJS += gtfpga.o -# PKGS += libpci -#endif +# Enable VILLASfpga support when libpci is available +ifeq ($(shell pkg-config libpci; echo $$?),0) + LIB_OBJS += vfpga.o pci.o dma.o model.o fifo.o xsg.o vfio.o switch.o rtds_axis.o + LDLIBS += -lxil + LDFLAGS += -Lthirdparty/xilinx -Wl,-rpath-link,'$$ORIGIN/thirdparty/xilinx' + CFLAGS += -Ithirdparty/xilinx/include + PKGS += libpci + TARGETS += fpga +endif # Enable NGSI support ifeq ($(shell pkg-config libcurl jansson uuid; echo $$?),0) - LIB_OBJS += ngsi.o - PKGS += libcurl jansson uuid + LIB_OBJS += ngsi.o + PKGS += libcurl jansson uuid endif ## Enable WebSocket support @@ -82,14 +85,16 @@ endif #endif # Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!) -ifneq (,$(wildcard $(OPALDIR)/include_target/AsyncApi.h)) +ifdef WITH_OPAL +ifneq (,$(wildcard thirdparty/opal/include/AsyncApi.h)) LIB_OBJS += opal.o CFLAGS += -m32 LDFLAGS += -m32 - LIB_CFLAGS += -m32 -I$(OPALDIR)/include_target - LIB_LDFLAGS += -m32 -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -L$(OPALDIR)/lib/redhawk/ + LIB_CFLAGS += -m32 -I thirdparty/opal/include + LIB_LDFLAGS += -m32 -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -Lthirdparty/opal/lib/redhawk/ LIB_LDLIBS += -lOpalAsyncApiCore -lOpalCore -lOpalUtils -lirc endif +endif # Add flags by pkg-config LIB_CFLAGS += $(addprefix -DWITH_, $(shell echo ${PKGS} | tr a-z- A-Z_ | tr -dc ' A-Z0-9_' )) @@ -104,20 +109,27 @@ LIB_LDLIBS += $(shell pkg-config --libs ${PKGS}) all: $(LIBS) $(TARGETS) # Dependencies for individual binaries -node: server.o $(LIBS) -pipe: pipe.o $(LIBS) -test: test.o $(LIBS) -signal: signal.o $(LIBS) +fpga: LDLIBS += -lpci -lxil + +node: server.o +fpga: fpga.o fpga-tests.o +pipe: pipe.o +test: test.o +signal: signal.o # Libraries -$(LIBS): CFLAGS += -fPIC $(LIB_CFLAGS) -$(LIBS): $(LIB_OBJS) - $(CC) $(LIB_LDFLAGS) -shared -o $@ $^ $(LIB_LDLIBS) +$(LIB_OBJS): CFLAGS += -fPIC $(LIB_CFLAGS) +libvillas.so: $(LIB_OBJS) + $(CC) $(LIB_LDFLAGS) -o $@ $^ $(LIB_LDLIBS) + +thirdparty/xilinx/libxil.so: + $(MAKE) -C thirdparty/xilinx libxil.so # Common targets install: $(TARGETS) $(LIBS) install -m 0644 $(LIBS) $(PREFIX)/lib install -m 0755 node -T $(PREFIX)/bin/villas-node + install -m 0755 fpga $(PREFIX)/bin/villas-fpga install -m 0755 signal $(PREFIX)/bin/villas-signal install -m 0755 pipe $(PREFIX)/bin/villas-pipe install -m 0755 test $(PREFIX)/bin/villas-test diff --git a/include/cfg.h b/include/villas/cfg.h similarity index 100% rename from include/cfg.h rename to include/villas/cfg.h diff --git a/include/hist.h b/include/villas/hist.h similarity index 100% rename from include/hist.h rename to include/villas/hist.h diff --git a/include/hooks.h b/include/villas/hooks.h similarity index 100% rename from include/hooks.h rename to include/villas/hooks.h diff --git a/include/if.h b/include/villas/kernel/if.h similarity index 100% rename from include/if.h rename to include/villas/kernel/if.h diff --git a/include/kernel.h b/include/villas/kernel/kernel.h similarity index 100% rename from include/kernel.h rename to include/villas/kernel/kernel.h diff --git a/include/nl.h b/include/villas/kernel/nl.h similarity index 100% rename from include/nl.h rename to include/villas/kernel/nl.h diff --git a/include/tc.h b/include/villas/kernel/tc.h similarity index 100% rename from include/tc.h rename to include/villas/kernel/tc.h diff --git a/include/list.h b/include/villas/list.h similarity index 100% rename from include/list.h rename to include/villas/list.h diff --git a/include/log.h b/include/villas/log.h similarity index 100% rename from include/log.h rename to include/villas/log.h diff --git a/include/lstack.h b/include/villas/lstack.h similarity index 100% rename from include/lstack.h rename to include/villas/lstack.h diff --git a/include/msg.h b/include/villas/msg.h similarity index 100% rename from include/msg.h rename to include/villas/msg.h diff --git a/include/msg_format.h b/include/villas/msg_format.h similarity index 100% rename from include/msg_format.h rename to include/villas/msg_format.h diff --git a/include/node.h b/include/villas/node.h similarity index 100% rename from include/node.h rename to include/villas/node.h diff --git a/include/file.h b/include/villas/nodes/file.h similarity index 100% rename from include/file.h rename to include/villas/nodes/file.h diff --git a/include/ngsi.h b/include/villas/nodes/ngsi.h similarity index 100% rename from include/ngsi.h rename to include/villas/nodes/ngsi.h diff --git a/include/opal.h b/include/villas/nodes/opal.h similarity index 92% rename from include/opal.h rename to include/villas/nodes/opal.h index e1b1fb390..9ae48de9d 100644 --- a/include/opal.h +++ b/include/villas/nodes/opal.h @@ -35,8 +35,6 @@ struct opal { int send_id; int recv_id; - - int seq_no; Opal_SendAsyncParam send_params; Opal_RecvAsyncParam recv_params; @@ -70,9 +68,9 @@ int opal_open(struct node *n); int opal_close(struct node *n); /** @see node_vtable::read */ -int opal_read(struct node *n, struct pool *pool, int cnt); +int opal_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_vtable::write */ -int opal_write(struct node *n, struct pool *pool, int cnt); +int opal_write(struct node *n, struct sample *smps[], unsigned cnt); #endif /** _OPAL_H_ @} */ diff --git a/include/socket.h b/include/villas/nodes/socket.h similarity index 100% rename from include/socket.h rename to include/villas/nodes/socket.h diff --git a/include/websocket.h b/include/villas/nodes/websocket.h similarity index 100% rename from include/websocket.h rename to include/villas/nodes/websocket.h diff --git a/include/path.h b/include/villas/path.h similarity index 100% rename from include/path.h rename to include/villas/path.h diff --git a/include/pool.h b/include/villas/pool.h similarity index 100% rename from include/pool.h rename to include/villas/pool.h diff --git a/include/queue.h b/include/villas/queue.h similarity index 100% rename from include/queue.h rename to include/villas/queue.h diff --git a/include/sample.h b/include/villas/sample.h similarity index 100% rename from include/sample.h rename to include/villas/sample.h diff --git a/include/timing.h b/include/villas/timing.h similarity index 100% rename from include/timing.h rename to include/villas/timing.h diff --git a/include/utils.h b/include/villas/utils.h similarity index 85% rename from include/utils.h rename to include/villas/utils.h index 6c5b8e91c..6ce417ba0 100644 --- a/include/utils.h +++ b/include/villas/utils.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "log.h" @@ -75,6 +76,12 @@ }) #endif +#define BITS_PER_LONGLONG (sizeof(long long) * 8) + +/* Some helper macros */ +#define BITMASK(h, l) (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONGLONG - 1 - (h)))) +#define BIT(nr) (1UL << (nr)) + /* Forward declarations */ struct settings; struct timespec; @@ -162,5 +169,34 @@ int version_parse(const char *s, struct version *v); } while (0) #endif -#endif /* _UTILS_H_ */ +/** Wait on eventfd */ +uint64_t wait_irq(int irq); +/** Fill buffer with random data */ +int read_random(char *buf, size_t len); + +/** Hexdump bytes */ +void printb(void *mem, size_t len); + +/** Hexdump 32-bit dwords */ +void printdw(void *mem, size_t len); + +/** Get CPU timestep counter */ +__attribute__((always_inline)) static inline uint64_t rdtscp() +{ + uint64_t tsc; + + __asm__ ("rdtscp;" + "shl $32, %%rdx;" + "or %%rdx,%%rax" + : "=a" (tsc) + : + : "%rcx", "%rdx", "memory"); + + return tsc; +} + +/** Sleep with rdtsc */ +void rdtsc_sleep(uint64_t nanosecs, uint64_t start); + +#endif /* _UTILS_H_ */ \ No newline at end of file diff --git a/lib/cfg.c b/lib/cfg.c index 8498f71c2..53798f96d 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -12,7 +12,6 @@ #include "utils.h" #include "list.h" -#include "if.h" #include "cfg.h" #include "node.h" #include "path.h" diff --git a/lib/hooks-internal.c b/lib/hooks/hooks-internal.c similarity index 100% rename from lib/hooks-internal.c rename to lib/hooks/hooks-internal.c diff --git a/lib/hooks-other.c b/lib/hooks/hooks-other.c similarity index 100% rename from lib/hooks-other.c rename to lib/hooks/hooks-other.c diff --git a/lib/hooks-stats.c b/lib/hooks/hooks-stats.c similarity index 100% rename from lib/hooks-stats.c rename to lib/hooks/hooks-stats.c diff --git a/lib/if.c b/lib/kernel/if.c similarity index 97% rename from lib/if.c rename to lib/kernel/if.c index ccde603bd..3a859304c 100644 --- a/lib/if.c +++ b/lib/kernel/if.c @@ -16,12 +16,14 @@ #include #include -#include "if.h" -#include "tc.h" -#include "nl.h" -#include "socket.h" +#include "kernel/if.h" +#include "kernel/tc.h" +#include "kernel/nl.h" +#include "kernel/kernel.h" + +#include "nodes/socket.h" + #include "utils.h" -#include "kernel.h" struct interface * if_create(struct rtnl_link *link) { diff --git a/lib/kernel.c b/lib/kernel/kernel.c similarity index 99% rename from lib/kernel.c rename to lib/kernel/kernel.c index 385fb743b..022c3281c 100644 --- a/lib/kernel.c +++ b/lib/kernel/kernel.c @@ -20,7 +20,7 @@ #include "utils.h" #include "config.h" -#include "kernel.h" +#include "kernel/kernel.h" int kernel_module_set_param(const char *module, const char *param, const char *value) { diff --git a/lib/nl.c b/lib/kernel/nl.c similarity index 99% rename from lib/nl.c rename to lib/kernel/nl.c index a7d3ed8c7..bc7a57b12 100644 --- a/lib/nl.c +++ b/lib/kernel/nl.c @@ -13,8 +13,9 @@ #include #include +#include "kernel/nl.h" + #include "utils.h" -#include "nl.h" /** Singleton for global netlink socket */ static struct nl_sock *sock = NULL; diff --git a/lib/tc.c b/lib/kernel/tc.c similarity index 98% rename from lib/tc.c rename to lib/kernel/tc.c index 6be3ce0b8..39f2c509e 100644 --- a/lib/tc.c +++ b/lib/kernel/tc.c @@ -14,10 +14,11 @@ #include +#include "kernel/if.h" +#include "kernel/tc.h" +#include "kernel/nl.h" + #include "utils.h" -#include "if.h" -#include "tc.h" -#include "nl.h" int tc_parse(config_setting_t *cfg, struct rtnl_qdisc **netem) { diff --git a/lib/file.c b/lib/nodes/file.c similarity index 99% rename from lib/file.c rename to lib/nodes/file.c index 51459401e..8ccd2fbdb 100644 --- a/lib/file.c +++ b/lib/nodes/file.c @@ -9,8 +9,7 @@ #include #include -#include "msg.h" -#include "file.h" +#include "nodes/file.h" #include "utils.h" #include "timing.h" #include "queue.h" diff --git a/lib/ngsi.c b/lib/nodes/ngsi.c similarity index 99% rename from lib/ngsi.c rename to lib/nodes/ngsi.c index 6b6d1ed20..cfaaf872e 100644 --- a/lib/ngsi.c +++ b/lib/nodes/ngsi.c @@ -16,10 +16,10 @@ #include #include -#include "ngsi.h" +#include "nodes/ngsi.h" + #include "utils.h" #include "timing.h" -#include "pool.h" /* Some global settings */ static char *name = NULL; diff --git a/lib/opal.c b/lib/nodes/opal.c similarity index 98% rename from lib/opal.c rename to lib/nodes/opal.c index d6a268384..42849065f 100644 --- a/lib/opal.c +++ b/lib/nodes/opal.c @@ -179,7 +179,7 @@ int opal_close(struct node *n) return 0; } -int opal_read(struct node *n, struct pool *pool, int cnt) +int opal_read(struct node *n, struct pool *pool, unsigned cnt) { struct opal *o = n->_vd; @@ -244,7 +244,7 @@ int opal_read(struct node *n, struct pool *pool, int cnt) return 1; } -int opal_write(struct node *n, struct pool *pool, int cnt) +int opal_write(struct node *n, struct pool *pool, unsigned cnt) { struct opal *o = n->_vd; diff --git a/lib/socket.c b/lib/nodes/socket.c similarity index 99% rename from lib/socket.c rename to lib/nodes/socket.c index db84f136d..786a27c2a 100644 --- a/lib/socket.c +++ b/lib/nodes/socket.c @@ -19,13 +19,14 @@ #include #include -#include "socket.h" +#include "nodes/socket.h" + +#include "kernel/if.h" +#include "kernel/nl.h" +#include "kernel/tc.h" + #include "config.h" #include "utils.h" - -#include "if.h" -#include "nl.h" -#include "tc.h" #include "msg.h" #include "sample.h" #include "queue.h" diff --git a/lib/websocket-http.c b/lib/nodes/websocket-http.c similarity index 100% rename from lib/websocket-http.c rename to lib/nodes/websocket-http.c diff --git a/lib/websocket-live.c b/lib/nodes/websocket-live.c similarity index 100% rename from lib/websocket-live.c rename to lib/nodes/websocket-live.c diff --git a/lib/websocket.c b/lib/nodes/websocket.c similarity index 99% rename from lib/websocket.c rename to lib/nodes/websocket.c index c00c7e8bd..728a9be28 100644 --- a/lib/websocket.c +++ b/lib/nodes/websocket.c @@ -323,7 +323,7 @@ shutdown: warn("Dropping connection: node is currently shutting down"); #if LWS_LIBRARY_VERSION_NUMBER > 1006002 - char *bye = "S2SS is shutting down. Bye"; + char *bye = "VILLASnode is shutting down. Bye"; lws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY, (unsigned char *) bye, strlen(bye)); #endif @@ -377,7 +377,7 @@ int websocket_init(int argc, char * argv[], config_setting_t *cfg) if (!port) port = 80; if (!htdocs) - htdocs = "/s2ss/contrib/websocket"; + htdocs = "/villas/contrib/websocket"; /* Start server */ struct lws_context_creation_info info = { diff --git a/lib/pool.c b/lib/pool.c index 28af00428..94a382435 100644 --- a/lib/pool.c +++ b/lib/pool.c @@ -11,7 +11,7 @@ #include "utils.h" #include "pool.h" -#include "kernel.h" +#include "kernel/kernel.h" int pool_init_mmap(struct pool *p, size_t blocksz, size_t cnt) {