Commit de8e771e authored by Carla Guillen's avatar Carla Guillen
Browse files

Merge branch 'development' of https://gitlab.lrz.de/dcdb/dcdb into development

parents 40a2bd54 cd77d69f
include config.mk
MAKEFILENAME := $(lastword $(MAKEFILE_LIST))
SUB_DIRS = lib collectagent dcdbpusher analytics tools scripts
SOURCEFORGE_MROR = vorboss
CASSANDRA_VERSION = 3.0.18
MOSQUITTO_VERSION = 1.5.5
BOOST_VERSION = 1.70.0
OPENSSL_VERSION = 1.1.1c
CPPDRV_VERSION = 2.10.0
LIBUV_VERSION = 1.24.0
BACNET-STACK_VERSION = 0.8.6
FREEIPMI_VERSION = 1.6.3
GCRYPT_VERSION = 1.8.4
GPG-ERROR_VERSION = 1.36
NET-SNMP_VERSION = 5.8
OPENCV_VERSION = 4.1.0
BOOST_VERSION_U = $(subst .,_,$(BOOST_VERSION))
DISTFILES = apache-cassandra-$(CASSANDRA_VERSION).tar.gz;http://archive.apache.org/dist/cassandra/$(CASSANDRA_VERSION)/apache-cassandra-$(CASSANDRA_VERSION)-bin.tar.gz \
mosquitto-$(MOSQUITTO_VERSION).tar.gz;http://mosquitto.org/files/source/mosquitto-$(MOSQUITTO_VERSION).tar.gz \
boost_$(BOOST_VERSION_U).tar.gz;http://$(SOURCEFORGE_MROR).dl.sourceforge.net/project/boost/boost/$(BOOST_VERSION)/boost_$(BOOST_VERSION_U).tar.gz \
openssl-$(OPENSSL_VERSION).tar.gz;https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz \
libuv-v$(LIBUV_VERSION).tar.gz;https://dist.libuv.org/dist/v$(LIBUV_VERSION)/libuv-v$(LIBUV_VERSION).tar.gz \
cpp-driver-$(CPPDRV_VERSION).tar.gz;https://github.com/datastax/cpp-driver/archive/$(CPPDRV_VERSION).tar.gz \
bacnet-stack-$(BACNET-STACK_VERSION).tgz;https://downloads.sourceforge.net/project/bacnet/bacnet-stack/bacnet-stack-$(BACNET-STACK_VERSION)/bacnet-stack-$(BACNET-STACK_VERSION).tgz \
libgpg-error-$(GPG-ERROR_VERSION).tar.gz;https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-$(GPG-ERROR_VERSION).tar.gz \
libgcrypt-$(GCRYPT_VERSION).tar.gz;https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-$(GCRYPT_VERSION).tar.gz \
freeipmi-$(FREEIPMI_VERSION).tar.gz;http://ftp.gnu.org/gnu/freeipmi/freeipmi-$(FREEIPMI_VERSION).tar.gz \
net-snmp-$(NET-SNMP_VERSION).tar.gz;https://sourceforge.net/projects/net-snmp/files/net-snmp/$(NET-SNMP_VERSION)/net-snmp-$(NET-SNMP_VERSION).tar.gz/download \
opencv-$(OPENCV_VERSION).tar.gz;https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz
DISTFILES_HASHES = apache-cassandra-3.0.18.tar.gz|94dbdaa58b366166c53f881b8e266bc8;\
mosquitto-1.5.5.tar.gz|a17dffc6f63b2a4ab2eb5c51139e60e9;\
boost_1_70_0.tar.gz|fea771fe8176828fabf9c09242ee8c26;\
openssl-1.1.1c.tar.gz|15e21da6efe8aa0e0768ffd8cd37a5f6;\
cpp-driver-2.10.0.tar.gz|6d15dd2cccd2efd1fdc86089d26971d0;\
libuv-v1.24.0.tar.gz|90320330757253b07404d2a97f59c66b;\
bacnet-stack-0.8.6.tgz|544ebd42ed959deb2213209b66bbc460;\
libgcrypt-1.8.4.tar.gz|433ab0a47b25994fa92b165db185f174;\
libgpg-error-1.36.tar.gz|f2283e22959ef71f44d8be3d0987a96b;\
freeipmi-1.6.3.tar.gz|b2d97e20db9b81b460ce1b9dad5bf54e;\
net-snmp-5.8.tar.gz|63bfc65fbb86cdb616598df1aff6458a; \
opencv-4.1.0.tar.gz|b80c59c7e4feee6a00608315e02b0b73;
include common.mk
CASSANDRA_CLUSTER_NAME = Datacenter Monitor Database
CASSANDRA_FLUSH_LARGEST_MEMTABLES_AT = 0.5
CASSANDRA_REDUCE_CACHE_SIZES_AT = 0.6
CASSANDRA_REDUCE_CACHE_CAPACITY_TO = 0.4
CASSANDRA_PARTITIONER = org.apache.cassandra.dht.ByteOrderedPartitioner
CASSANDRA_COMMITLOG_TOTAL_SPACE_IN_MB = 256
CASSANDRA_COMMITLOG_SEGMENT_SIZE_IN_MB = 16
CASSANDRA_TOMBSTONE_WARN_THRESHOLD = 100000
CASSANDRA_TOMBSTONE_FAILURE_THRESHOLD = 10000000
# If cross-compiling for ARM, adjust the build settings
ifeq ("$(ARCH)", "arm")
OPENSSL_TARGET = "linux-generic32"
else
OPENSSL_TARGET = $(if $(findstring $(shell uname),Darwin),"darwin64-x86_64-cc","linux-x86_64")
endif
PUBHEADERS = dcdbdaemon.h
.PHONY : info all clean cleanall cleandoc distclean deps depsinstall $(SUB_DIRS) doc
FULL_CC = $(shell which $(CC))
FULL_CXX = $(shell which $(CXX))
.PHONY : info all clean cleanall cleandoc distclean check-cross-compile deps depsinstall $(SUB_DIRS) doc
all: deps $(foreach s,$(SUB_DIRS),$(s)-build)
include dependencies.mk
info:
@echo ""
......@@ -99,14 +34,12 @@ info:
@echo "For ARM cross compilation, please type:"
@echo " make ARCH=arm CROSS_COMPILE=<X> all"
@echo "where <X> is your cross copmlier prefix ( e.g. arm-linux-gnueabihf- )"
@$(foreach f,$(DISTFILES), echo "$(f)";)
clean:
@$(foreach s,$(SUB_DIRS),echo "Cleaning $(s)..." && make -C $(s) clean && echo;)
cleandeps:
@$(foreach f,$(DISTFILESPATHS),echo "Cleaning $(f)..." && rm -rf $(DCDBDEPSPATH)/$(f) && echo;)
@$(foreach f,cpp-netlib,echo "Cleaning $(f)..." && rm -rf $(DCDBDEPSPATH)/$(f)_build && echo;)
@$(foreach f,$(DISTFILESPATHS_FULL),echo "Cleaning $(f)..." && rm -rf $(DCDBDEPSPATH)/$(f) && echo;)
cleandoc:
@echo "Cleaning doc/html..."
......@@ -130,8 +63,6 @@ doc:
@cd doc/ && doxygen Doxyfile && ln -sf ./html/index.html ./dcdb_documentation.html
@echo "Generated docs into doc/html"
all: check-cross-compile deps $(foreach s,$(SUB_DIRS),$(s)-build)
install: depsinstall $(SUB_DIRS)
@cd common/include && install $(PUBHEADERS) $(DCDBDEPLOYPATH)/include/dcdb && cd ..
@echo DONE
......@@ -140,163 +71,6 @@ deps: $(foreach f,$(DISTFILESPATHS),$(DCDBDEPSPATH)/$(f)/.built)
depsinstall: $(foreach f,$(DISTFILESPATHS),$(DCDBDEPSPATH)/$(f)/.installed)
$(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION)/.built: $(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION)/.patched
@echo "Building OpenSSL library..."
cd $(@D) && ./Configure shared --prefix=$(DCDBDEPLOYPATH) $(OPENSSL_TARGET)
cd $(@D) && make && touch $(@)
$(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION)/.installed: $(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing OpenSSL library..."
cd $(@D) && make install_sw && touch $(@)
$(DCDBDEPSPATH)/mosquitto-$(MOSQUITTO_VERSION)/.built: $(DCDBDEPSPATH)/mosquitto-$(MOSQUITTO_VERSION)/.patched
@echo "Building Mosquitto library...";
mkdir -p $(@D)/build;
cd $(@D)/build && \
CC=$(FULL_CC) CXX=$(FULL_CXX) cmake $(CMAKE_CROSS_FLAGS) \
-DWITH_SRV=no \
-DWITH_TLS=yes \
-DWITH_TLS_PSK=yes \
-DDOCUMENTATION=no \
-DCMAKE_INSTALL_PREFIX=$(DCDBDEPLOYPATH)/ \
$(@D) && \
make -j $(MAKETHREADS) && \
touch $(@)
$(DCDBDEPSPATH)/mosquitto-$(MOSQUITTO_VERSION)/.installed: $(DCDBDEPSPATH)/mosquitto-$(MOSQUITTO_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing Mosquitto library..."
cd $(@D)/build && make install && touch $(@)
$(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/.built: $(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/.patched
@echo "Building Boost..."
@ if [ "$(ARCH)" = "arm" ]; then \
echo " using gcc : arm : $(CROSS_COMPILE)g++ ; " > $(@D)/tools/build/src/user-config.jam; \
fi
cd $(@D) && ./bootstrap.sh --prefix=$(DCDBDEPLOYPATH) --with-libraries=atomic,chrono,date_time,exception,filesystem,log,program_options,random,regex,system,thread,timer && \
./b2 stage && touch $(@)
$(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/.installed: $(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/.built
cd $(@D) && ./b2 -j $(MAKETHREADS) --no-cmake-config install && touch $(@)
$(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION)/.built: $(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION)/.patched
@echo "Building libuv..."
mkdir -p $(@D)/build
cd $(@D)/build && \
CC=$(FULL_CC) CXX=$(FULL_CXX) cmake $(CMAKE_CROSS_FLAGS) \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_PREFIX=$(DCDBDEPLOYPATH)/ \
.. && \
make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION)/.installed: $(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing libuv..."
cd $(@D)/build && make install && touch $(@)
$(DCDBDEPSPATH)/cpp-driver-$(CPPDRV_VERSION)/.built: $(DCDBDEPSPATH)/cpp-driver-$(CPPDRV_VERSION)/.patched $(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION)/.built $(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION)/.built
@echo "Building cpp-driver..."
mkdir -p $(@D)/build
cd $(@D)/build && \
CC=$(FULL_CC) CXX=$(FULL_CXX) cmake $(CMAKE_CROSS_FLAGS) \
-DOPENSSL_ROOT_DIR=$(DCDBDEPSPATH)/openssl-$(OPENSSL_VERSION) \
-DLIBUV_ROOT_DIR=$(DCDBDEPSPATH)/libuv-v$(LIBUV_VERSION) \
-DCASS_BUILD_EXAMPLES=NO \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_PREFIX=$(DCDBDEPLOYPATH)/ \
-DCMAKE_EXE_LINKER_FLAGS="-L$(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/stage/lib -lboost_random" \
-DCMAKE_SHARED_LINKER_FLAGS="-L$(DCDBDEPSPATH)/boost_$(BOOST_VERSION_U)/stage/lib -lboost_random" \
.. && \
make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/cpp-driver-$(CPPDRV_VERSION)/.installed: $(DCDBDEPSPATH)/cpp-driver-$(CPPDRV_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing cpp-driver..."
cd $(@D)/build && make install && touch $(@)
$(DCDBDEPSPATH)/apache-cassandra-$(CASSANDRA_VERSION)/.built: $(DCDBDEPSPATH)/apache-cassandra-$(CASSANDRA_VERSION)/.patched
@touch $(DCDBDEPSPATH)/apache-cassandra-$(CASSANDRA_VERSION)/.built
$(DCDBDEPSPATH)/apache-cassandra-$(CASSANDRA_VERSION)/.installed: $(DCDBDEPSPATH)/apache-cassandra-$(CASSANDRA_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo ""
@echo "Staging and configuring Cassandra..."
@rsync -rlptD $(@D)/ $(DCDBDEPLOYPATH)/cassandra
@$(eval P := $(shell echo "$(DCDBDEPLOYPATH)" | sed 's/\//\\\//g'))
@sed -i.original -e 's/\/var\/lib\/cassandra/$(P)\/var\/lib\/cassandra/g' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*cluster_name:.*/cluster_name:\ '\''$(CASSANDRA_CLUSTER_NAME)'\''/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*flush_largest_memtables_at:.*/flush_largest_memtables_at:\ $(CASSANDRA_FLUSH_LARGEST_MEMTABLES_AT)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*reduce_cache_sizes_at:.*/reduce_cache_sizes_at:\ $(CASSANDRA_REDUCE_CACHE_SIZES_AT)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*reduce_cache_capacity_to:.*/reduce_cache_capacity_to:\ $(CASSANDRA_REDUCE_CACHE_CAPACITY_TO)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*partitioner:.*/partitioner:\ $(CASSANDRA_PARTITIONER)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*commitlog_total_space_in_mb:.*/commitlog_total_space_in_mb: $(CASSANDRA_COMMITLOG_TOTAL_SPACE_IN_MB)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*commitlog_segment_size_in_mb:.*/commitlog_segment_size_in_mb: $(CASSANDRA_COMMITLOG_SEGMENT_SIZE_IN_MB)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*tombstone_warn_threshold:.*/tombstone_warn_threshold: $(CASSANDRA_TOMBSTONE_WARN_THRESHOLD)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@sed -i -e 's/.*tombstone_failure_threshold:.*/tombstone_failure_threshold: $(CASSANDRA_TOMBSTONE_FAILURE_THRESHOLD)/' $(DCDBDEPLOYPATH)/cassandra/conf/cassandra.yaml
@touch $@
$(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/.built: $(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/.patched
@echo ""
@echo "Building BACNet-Stack..."
$(eval BACNET_PORT:= $(if $(filter $(OS),Darwin),bsd,linux))
cd $(@D) && BACNET_PORT=$(BACNET_PORT) MAKE_DEFINE=-fpic make -j $(MAKETHREADS) library
touch $(@)
$(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/.installed: $(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing BACNet-Stack..."
mkdir $(DCDBDEPLOYPATH)/include/bacnet && \
install $(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/include/* /$(DCDBDEPLOYPATH)/include/bacnet && \
install $(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/lib/libbacnet.a /$(DCDBDEPLOYPATH)/lib/ && touch $(@)
$(DCDBDEPSPATH)/libgpg-error-$(GPG-ERROR_VERSION)/.built: $(DCDBDEPSPATH)/libgpg-error-$(GPG-ERROR_VERSION)/.patched
@echo ""
@echo "Building gpg-error library..."
cd $(@D) && ./configure --prefix=$(DCDBDEPLOYPATH)
cd $(@D) && make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/libgpg-error-$(GPG-ERROR_VERSION)/.installed: $(DCDBDEPSPATH)/libgpg-error-$(GPG-ERROR_VERSION)/.built
@echo "Installing gpg-error library..."
cd $(@D) && make install && touch $(@)
$(DCDBDEPSPATH)/libgcrypt-$(GCRYPT_VERSION)/.built: $(DCDBDEPSPATH)/libgcrypt-$(GCRYPT_VERSION)/.patched
@echo ""
@echo "Building gcrypt library..."
cd $(@D) && ./configure --prefix=$(DCDBDEPLOYPATH) --with-libgpg-error-prefix=$(DCDBDEPLOYPATH)
cd $(@D) && make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/libgcrypt-$(GCRYPT_VERSION)/.installed: $(DCDBDEPSPATH)/libgcrypt-$(GCRYPT_VERSION)/.built
@echo "Installing gcrypt library..."
cd $(@D) && make install && touch $(@)
$(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.built: $(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.patched
@echo ""
@echo "Building FreeIPMI library..."
cd $(@D) && ./configure --prefix=$(DCDBDEPLOYPATH) --without-argp
cd $(@D) && make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.installed: $(DCDBDEPSPATH)/freeipmi-$(FREEIPMI_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo "Installing FreeIPMI library..."
cd $(@D) && make install && touch $(@)
$(DCDBDEPSPATH)/net-snmp-$(NET-SNMP_VERSION)/.built: $(DCDBDEPSPATH)/net-snmp-$(NET-SNMP_VERSION)/.patched
@echo ""
@echo "Building net-SNMP library..."
cd $(@D) && ./configure --prefix=$(DCDBDEPLOYPATH) --with-default-snmp-version=3 --with-defaults --with-logfile=none --with-persistent-directory=$(DCDBDEPLOYPATH)/var/net-snmp --disable-embedded-perl --disable-perl-cc-checks --without-perl-modules --disable-agent --disable-applications --disable-manuals --disable-scripts --disable-mibs
cd $(@D) && make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/net-snmp-$(NET-SNMP_VERSION)/.installed: $(DCDBDEPSPATH)/net-snmp-$(NET-SNMP_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo ""
@echo "Installing net-SNMP library..."
cd $(@D) && make install && touch $(@)
$(DCDBDEPSPATH)/opencv-$(OPENCV_VERSION)/.built: $(DCDBDEPSPATH)/opencv-$(OPENCV_VERSION)/.patched
@echo ""
@echo "Building OpenCV library..."
cd $(@D) && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(DCDBDEPLOYPATH) -DCMAKE_INSTALL_LIBDIR=lib -DINSTALL_C_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DBUILD_LIST=core,dnn,features2d,flann,gapi,ml ..
cd $(@D) && cd build && make -j $(MAKETHREADS) && touch $(@)
$(DCDBDEPSPATH)/opencv-$(OPENCV_VERSION)/.installed: $(DCDBDEPSPATH)/opencv-$(OPENCV_VERSION)/.built | $(DCDBDEPLOYPATH)
@echo ""
@echo "Installing OpenCV library..."
cd $(@D) && cd build && make install && touch $(@)
%-build: deps
@echo "Building $*"
@$(MAKE) -j $(MAKETHREADS) CC=$(CC) CXX=$(CXX) -C $*
......
FETCH = wget -c --no-check-certificate -O
MD5 = $(if $(shell which md5 2>/dev/null),md5,$(if $(shell md5sum --tag Makefile 2&> /dev/null || true),md5sum --tag,openssl md5))
OS = $(shell uname -s)
MAKETHREADS ?= $(if $(findstring $(shell uname),Darwin),$(shell sysctl machdep.cpu.thread_count | cut -b 27-),\
$(if $(findstring $(shell uname),Linux),$(shell cat /proc/cpuinfo | grep processor | wc -l),4))
DISTFILESNAMES = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/;.*//'))
DISTFILESPATHS = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/.tar.gz;.*//; s/.tgz;.*//; s/.zip;.*//' ))
CFLAGS += -I$(DCDBDEPLOYPATH)/include -O2 -g -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
LDFLAGS += -L$(DCDBDEPLOYPATH)/lib -O2 -g
.PHONY: all info
.PRECIOUS: $(DCDBDEPSPATH)/distfiles/% $(DCDBDEPSPATH)/%/.extracted $(DCDBDEPSPATH)/%/.patched
.SECONDEXPANSION:
getarchive = $(filter $1%,$(DISTFILESNAMES))
gethash = $(subst $(1)|,,$(filter $(1)%,$(subst ;, ,$(DISTFILES_HASHES))))
all: $(TARGET)
$(DCDBDEPSPATH):
@mkdir -p $(DCDBDEPSPATH)
$(DCDBDEPSPATH)/distfiles: | $(DCDBDEPSPATH)
@mkdir -p $(DCDBDEPSPATH)/distfiles
$(DCDBDEPLOYPATH):
@mkdir -p $(DCDBDEPLOYPATH)/bin
@mkdir -p $(DCDBDEPLOYPATH)/include
@mkdir -p $(DCDBDEPLOYPATH)/lib
$(DCDBDEPSPATH)/distfiles/%: | $(DCDBDEPSPATH)/distfiles
@echo "Check for $(*)"
$(eval U := $(shell echo "$(DISTFILES)" | sed 's/.*$(*);//' | sed 's/ .*//'))
@if [ -e $(@) ]; then \
if [ `$(MD5) $(@)|sed -e 's/.*\ //'` != $(call gethash,$(*)) ]; then \
rm $(@); \
fi; \
fi
@if [ ! -e $(@) ]; then \
$(FETCH) $(@) $(U); \
fi
$(DCDBDEPSPATH)/%/.extracted: | $(DCDBDEPSPATH)/distfiles/$$(call getarchive,%)
$(eval F := $(notdir $(|)))
@if [ ! -e $(@) ]; then \
printf "Verifying checksum: $(F) "; \
if [ `$(MD5) $(|)|sed -e 's/.*\ //'` = $(call gethash,$(F)) ]; then \
echo " => OK!"; \
else \
echo " => FAIL!"; \
exit 2; \
fi; \
echo Extracting: $(F); \
if [ "$(suffix $(F))" = "zip" ]; then \
cd $(DCDBDEPSPATH) && unzip distfiles/$(F); \
else \
cd $(DCDBDEPSPATH) && tar xf distfiles/$(F) > /dev/null; \
fi; \
fi
@touch $@
$(DCDBDEPSPATH)/%/.patched: $(DCDBDEPSPATH)/%/.extracted
$(eval P := $(realpath patches))
if [ ! -e $(@) ] && [ -e $(P)/$(*).patch ]; then \
echo Patching: $(*); \
cd $(@D) && (patch -N -p1 < $(P)/$(*).patch); \
fi
@touch $@
......@@ -2,6 +2,9 @@ DCDBBASEPATH ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/..)
DCDBDEPSPATH ?= $(DCDBBASEPATH)/deps
DCDBDEPLOYPATH ?= $(DCDBBASEPATH)/install
# dcdbpusher plugins to be built
PLUGINS = procfs pdu sysfs ipmi bacnet snmp gpfsmon msr tester
DEFAULT_VERSION = 0.3
GIT_VERSION = $(shell git describe --tags 2>/dev/null|sed 's/-\([0-9]*\)/.\1/')
VERSION := $(if $(GIT_VERSION),$(GIT_VERSION),$(DEFAULT_VERSION))
......@@ -11,5 +14,10 @@ CXXFLAGS = -std=c++11 -O2 -g -Wall -fmessage-length=0 \
-DBOOST_LOG_DYN_LINK -DVERSION=\"$(VERSION)\" \
-Wno-unused-function \
-Wno-unused-variable
FULL_CC = $(shell which $(CC))
FULL_CXX = $(shell which $(CXX))
OS = $(shell uname -s)
MAKETHREADS ?= $(if $(findstring $(shell uname),Darwin),$(shell sysctl machdep.cpu.thread_count | cut -b 27-),\
$(if $(findstring $(shell uname),Linux),$(shell cat /proc/cpuinfo | grep processor | wc -l),4))
......@@ -65,6 +65,7 @@
#include <sched.h>
#include <semaphore.h>
#include <string.h>
#include <thread>
#include <unistd.h>
#include <vector>
......@@ -143,25 +144,33 @@ private:
* //Communication queue, aka ring buffer:
* size_t r_index //points to the last read element
* size_t w_index //points to the last written element
* sem_t r_sem;
* sem_t w_sem;
* sem_t r_sem; // atomic access to r_index
* sem_t w_sem; // atomic access to w_index
* sem_t u_sem; // atomic access to symbol data and updateSymbolData.
* snap_data[MSGQ_SIZE]
*
* //TODO could we profit from some alignment here?
* int updateSymbolData;
*
* //symbol lookup data
* size_t addr_count
* addr_data[addr_count]
* addr_count * (fsym_data[addr_data.fsym_count])
*/
static constexpr size_t lookup_data_offset = 2*sizeof(size_t)
+ 2*sizeof(sem_t)
+ MSGQ_SIZE*sizeof(snap_data);
//TODO max one application per node? multiple threads per node OK, what about multiple (MPI-)processes
//TODO dynamic rebuild at runtime
+ 3*sizeof(sem_t)
+ MSGQ_SIZE*sizeof(snap_data)
+ sizeof(int);
//TODO test dynamic rebuild at runtime
//TODO investigate consequences of fork() on Caliper - DCDBPusher construct
void* shm; // pointer to shared memory object
int shm_file; // fd of the underlying shared memory file
size_t shm_bytes_written; // keep track if we exceed shm_size
int sock; // unix socket fd for initial shm setup communication
std::atomic<bool> run_sus;
std::thread sus; //symbol update service
const std::string pid_str; // PID at process start
bool initialized;
......@@ -171,12 +180,24 @@ private:
*
* @param filename ELF file (binary or shared library) to retrieve symbol info from
* @param start_addr Only store symbols whose address is in between start_addr and end_addr
* @param end_addr
* @param end_addr See start_addr
* @param dest_ptr Pointer to memory where to store fsym_data. Will be modified
* to point behind the last written element on return.
* @return The number of symbol entries written.
* //TODO include debug symbols
* //TODO check if symbols exceeding MAX_SYMBOL_SIZE overwrite succeeding syms
*
* --NOTE--
* As one could expect this custom symbol lookup routine is not very mature.
* The found symbols and their addresses seem to be calculated correctly.
* However, the symbol addresses calculated by gdb and this routine are
* slightly off *sometimes* (seldom). In this case gdb can still resolve our
* calculated address to the correct symbol name. Currently I lack the
* knowledge to explain this discrepancy, therefore I leave a TODO here as
* short-term legacy.
* Also symbol information can be incomplete for stripped binaries. But as
* this program is only intended for introspection into libraries controlled
* by us, we do not care about stripped binaries too much.
* We skip support for separate debug symbols. Unstripped binaries should
* provide us with enough symbol information.
*/
size_t write_function_symbols(const char* const filename,
const uintptr_t start_addr,
......@@ -455,6 +476,54 @@ private:
return true;
}
/**
* Symbol update service background thread. Whenever the DCDB Pusher plugin
* could not resolve a snapshot it notifies us and this thread comes into
* play. Updates the symbol data in the shared memory file.
*/
void startSUS(Channel* chn) {
if (run_sus.load(std::memory_order_acquire) ) {
run_sus.store(false, std::memory_order_release);
if (sus.joinable()) {
sus.join();
}
}
run_sus.store(true, std::memory_order_release);
sus = std::thread([=]() {
//to increase responsiveness on termination we sleep only 1 second at most
//however, to reduce update overhead we only check the update flag every 15 seconds
unsigned short cnt = 0;
constexpr unsigned short maxCnt = 15;
while (run_sus.load(std::memory_order_acquire)) {
if (cnt == maxCnt) {
sem_t* u_sem = reinterpret_cast<sem_t*>(static_cast<char*>(shm)
+ 2*sizeof(size_t)
+ 2*sizeof(sem_t));
if (sem_wait(u_sem)) {
continue;
}
int& updateSymbolData = *(reinterpret_cast<int*>(static_cast<char*>(shm) + lookup_data_offset - sizeof(int)));
if (updateSymbolData != 0) {
if (!setup_shm(chn)) {
Log(1).stream() << chn->name() << ": DcdbPusher: Failed to setup shm"
<< std::endl;
} else {
updateSymbolData = 0;
}
}
sem_post(u_sem);
cnt = 0;
}
//TODO best interval value? make it dynamic?
++cnt;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
});
}
void print_debug_shm() {
const size_t& addr_cnt = *(reinterpret_cast<size_t*>(static_cast<char*>(shm) + lookup_data_offset));
const addr_data* addr_ptr = reinterpret_cast<const addr_data*>(&addr_cnt + 1);
......@@ -504,7 +573,7 @@ private:
r_sem = reinterpret_cast<sem_t*>(static_cast<char*>(shm) + 2*sizeof(size_t));
w_sem = r_sem + 1;
msg_queue = reinterpret_cast<snap_data*>(w_sem + 1);
msg_queue = reinterpret_cast<snap_data*>(w_sem + 2);
//TODO atomic load/stores instead of semaphore locking?
if (sem_wait(r_sem)) {
......@@ -585,27 +654,27 @@ private:
}
//init r/w_index
*(reinterpret_cast<size_t*>(static_cast<char*>(shm))) = MSGQ_SIZE - 1;
*(reinterpret_cast<size_t*>(static_cast<char*>(shm))) = 0;
*(reinterpret_cast<size_t*>(static_cast<char*>(shm) + sizeof(size_t))) = 0;
//TODO fit shm size to used memory?
//init semaphores
sem_t* r_sem;
sem_t* w_sem;
sem_t* u_sem;
r_sem = reinterpret_cast<sem_t*>(static_cast<char*>(shm) + 2*sizeof(size_t));
w_sem = r_sem + 1;
u_sem = w_sem + 1;
if (sem_init(r_sem, 1, 1)) {
Log(1).stream() << chn->name() << ": DcdbPusher: Failed to init r_sem: "
if (sem_init(r_sem, 1, 1) || sem_init(w_sem, 1, 1) || sem_init(u_sem, 1, 1)) {
Log(1).stream() << chn->name() << ": DcdbPusher: Failed to init semaphore: "
<< strerror(errno) << std::endl;
return;
}
if (sem_init(w_sem, 1, 1)) {
Log(1).stream() << chn->name() << ": DcdbPusher: Failed to init w_sem: "
<< strerror(errno) << std::endl;
return;
}
//init symbol update service
*(reinterpret_cast<int*>(static_cast<char*>(shm) + lookup_data_offset - sizeof(int))) = 0;
startSUS(chn);
//print_debug_shm();
......@@ -708,6 +777,13 @@ private:
}
void finish_cb(Caliper* c, Channel* chn) {
if (run_sus.load(std::memory_order_acquire)) {
run_sus.store(false, std::memory_order_release);
if (sus.joinable()) {
sus.join();
}
}
if (shm != NULL) {
munmap(shm, SHM_SIZE);
shm = NULL;
......@@ -739,6 +815,7 @@ private:
shm_file(-1),
shm_bytes_written(0),
sock(-1),
run_sus(false),
pid_str(std::to_string(getpid())),
initialized(false) {
shm_buf_idx = 0;
......
include ../config.mk
include ../common.mk
CXXFLAGS += -DBOOST_NETWORK_ENABLE_HTTPS \
-I../common/include \
......@@ -32,7 +31,6 @@ OBJS = dcdbpusher.o \
../common/src/RESTHttpsServer.o
TARGET = dcdbpusher
PLUGINS = procfs pdu sysfs ipmi bacnet snmp gpfsmon msr tester
ifeq ($(OS),Darwin)
BACNET_PORT = bsd
......@@ -43,18 +41,21 @@ else
BACNET_PORT = linux
LIBEXT = so
LIBFLAGS = -shared -Wl,-soname,
PLUGINS+= perfevent caliper
PLUGINFLAGS = -fPIC
endif
PLUGIN_LIBS = $(foreach p,$(PLUGINS),libdcdbplugin_$(p).$(LIBEXT))
all: $(TARGET) $(PLUGIN_LIBS)
$(TARGET): $(foreach f,$(DISTFILESPATHS),$(DCDBDEPSPATH)/$(f)/.installed) $(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all: $(TARGET) $(PLUGIN_LIBS)
debug: CXXFLAGS += -DDEBUG
debug: all
info:
@echo $(PLUGINS) $(PLUGIN_LIBS)
clean:
rm -f $(PLUGIN_LIBS) $(TARGET) $(OBJS) $(shell find ./sensors -name "*.o")
......
......@@ -29,6 +29,7 @@
#include <errno.h>
#include <stdio.h>
#include <utility>
#include <sys/mman.h>
#include <sys/socket.h>
......@@ -42,9 +43,6 @@ CaliperSensorGroup::CaliperSensorGroup(const std::string& name) :
SensorGroupTemplate(name),
_socket(-1),
_connection(-1),
_shm(nullptr),
_shmFile(-1),
_shmFailCnt(0),
_globalMqttPrefix("") {
_lock.clear();
}
......@@ -53,9 +51,6 @@ CaliperSensorGroup::CaliperSensorGroup(const CaliperSensorGroup& other) :
SensorGroupTemplate(other),
_socket(-1),
_connection(-1),
_shm(nullptr),
_shmFile(-1),
_shmFailCnt(0),