diff options
| author | Qiuwen Lu <[email protected]> | 2016-11-16 20:23:44 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2016-11-16 20:49:19 +0800 |
| commit | a5ef63fa77e9bf66674ba043f1785358a0b6846d (patch) | |
| tree | f1b7617c240c90d5550dd09bfc820a8d1dc9978b | |
| parent | a33a84b6f8f3839b33d9c5a57eaa939c9d6a81c7 (diff) | |
支持CentOS7上的systemd自启动方式
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | conf/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | conf/dpdk-x86_64.conf.in | 3 | ||||
| -rw-r--r-- | conf/mlx4.conf | 14 | ||||
| -rw-r--r-- | conf/mrzcpd.ld.conf.in | 2 | ||||
| -rw-r--r-- | conf/mrzcpd.pc.in | 11 | ||||
| -rw-r--r-- | conf/mrzcpd.sysconfig.in (renamed from conf/mrenv.conf.in) | 8 | ||||
| -rw-r--r-- | tools/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | tools/Makefile | 6 | ||||
| -rw-r--r-- | tools/dpdk_intel | 218 | ||||
| -rw-r--r-- | tools/dpdk_mlx4 | 196 | ||||
| -rw-r--r-- | tools/drv_monitor.sh | 34 | ||||
| -rw-r--r-- | tools/drv_start.sh | 21 | ||||
| -rw-r--r-- | tools/r2_driver.sh | 1 | ||||
| -rw-r--r-- | tools/script/mrstart (renamed from tools/mrstart) | 2 | ||||
| -rw-r--r-- | tools/script/mrstop (renamed from tools/mrstop) | 2 | ||||
| -rw-r--r-- | tools/script/mrzcpd (renamed from tools/mrzcpd) | 4 | ||||
| -rw-r--r-- | tools/systemd/mrenv-script | 312 | ||||
| -rw-r--r-- | tools/systemd/mrenv.service.in | 13 | ||||
| -rw-r--r-- | tools/systemd/mrzcpd.service.in | 12 |
20 files changed, 390 insertions, 511 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ba27a3e..182e872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,13 @@ set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -std=gnu++11") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") -# Default Install Destination Directory -#set(CMAKE_INSTALL_PREFIX /opt/iiesoft/marsio) +set(MR_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) +set(MR_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) +set(MR_INSTALL_SYSCONFDIR ${CMAKE_INSTALL_PREFIX}/etc) +set(MR_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include) +set(MR_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX}/bin) +set(MR_INSTALL_LDCONFDIR /etc/ld.so.conf.d/) +set(MR_INSTALL_SYSUNITCONFDIR /etc/sysconfig/) add_subdirectory(${CMAKE_SOURCE_DIR}/support ${CMAKE_BINARY_DIR}/support) add_subdirectory(${CMAKE_SOURCE_DIR}/driver) diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt index 8ab666b..07aeb31 100644 --- a/conf/CMakeLists.txt +++ b/conf/CMakeLists.txt @@ -1,7 +1,9 @@ -configure_file(dpdk-x86_64.conf.in ${CMAKE_SOURCE_DIR}/conf/dpdk-x86_64.conf)
-configure_file(mrenv.conf.in ${CMAKE_SOURCE_DIR}/conf/mrenv.conf)
+configure_file(mrzcpd.ld.conf.in mrzcpd.conf)
+configure_file(mrzcpd.pc.in mrzcpd.pc)
+configure_file(mrzcpd.sysconfig.in mrzcpd)
-install(FILES mrenv.conf DESTINATION /etc/ COMPONENT Profile)
install(FILES nl2fwd.conf DESTINATION /etc/ COMPONENT Profile)
-install(FILES dpdk-x86_64.conf DESTINATION /etc/ld.so.conf.d/ COMPONENT Profile)
\ No newline at end of file +install(FILES ${CMAKE_BINARY_DIR}/conf/mrzcpd.conf DESTINATION ${MR_INSTALL_LDCONFDIR} COMPONENT Profile)
+install(FILES ${CMAKE_BINARY_DIR}/conf/mrzcpd.pc DESTINATION ${MR_INSTALL_LIBDIR}/pkgconfig COMPONENT Profile)
+install(FILES ${CMAKE_BINARY_DIR}/conf/mrzcpd DESTINATION ${MR_INSTALL_SYSUNITCONFDIR} COMPONENT Profile)
\ No newline at end of file diff --git a/conf/dpdk-x86_64.conf.in b/conf/dpdk-x86_64.conf.in deleted file mode 100644 index 668e228..0000000 --- a/conf/dpdk-x86_64.conf.in +++ /dev/null @@ -1,3 +0,0 @@ -@DPDK_ROOT_DIR@/lib
-@CMAKE_INSTALL_PREFIX@/lib
-@CMAKE_INSTALL_PREFIX@/lib64
\ No newline at end of file diff --git a/conf/mlx4.conf b/conf/mlx4.conf deleted file mode 100644 index 3d06b6a..0000000 --- a/conf/mlx4.conf +++ /dev/null @@ -1,14 +0,0 @@ -# Configure File in Shell Format -# To configure mlx4 uio network drivers and dpdk env -# -# DPDK Envourment PATH - -export RTE_SDK=/root/DPDK -export RTE_TARGET=x86_64-default-linuxapp-gcc - -# HUGEPAGES Count -HUGEPAGE_MEM=25000 - -# PCI Resource Address using MLX4_UIO drivers -MLX4_UIO=0000:01:00.0 - diff --git a/conf/mrzcpd.ld.conf.in b/conf/mrzcpd.ld.conf.in new file mode 100644 index 0000000..c888375 --- /dev/null +++ b/conf/mrzcpd.ld.conf.in @@ -0,0 +1,2 @@ +@DPDK_ROOT_DIR@/lib
+@MR_INSTALL_LIBDIR@
\ No newline at end of file diff --git a/conf/mrzcpd.pc.in b/conf/mrzcpd.pc.in new file mode 100644 index 0000000..2e7ae4a --- /dev/null +++ b/conf/mrzcpd.pc.in @@ -0,0 +1,11 @@ +prefix=@MR_INSTALL_PREFIX@
+exec_prefix=@MR_INSTALL_PREFIX@
+libdir=@MR_INSTALL_LIBDIR@
+includedir=@MR_INSTALL_INCLUDEDIR@
+bindir=@MR_INSTALL_BINDIR@
+
+Name: mrzcpd
+Description: IIE-MESA Marsio ZeroCopy Driver
+Version: @MARSIO_VERSION@
+Libs: -L@MR_INSTALL_LIBDIR@ -lmarsio
+Cflags: -I@MR_INSTALL_INCLUDEDIR@
\ No newline at end of file diff --git a/conf/mrenv.conf.in b/conf/mrzcpd.sysconfig.in index 5755a15..f552aa4 100644 --- a/conf/mrenv.conf.in +++ b/conf/mrzcpd.sysconfig.in @@ -1,10 +1,6 @@ -# Configure File in Shell Format -# -# DPDK Envourment PATH - +# Marsio ZeroCopy Install Path DPDK_ROOT=@DPDK_ROOT_DIR@ -MARSIO_ROOT=@CMAKE_INSTALL_PREFIX@ - +MRZCPD_ROOT=@CMAKE_INSTALL_PREFIX@ # HUGEPAGES Count HUGEPAGE_NUM_2M=20000 # PCI Resource Address using IXGBE_UIO drivers diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 81fdf3c..11726e3 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,20 @@ -install(FILES mrstart DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
-install(FILES mrstop DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
-install(FILES mrzcpd DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE COMPONENT Program)
\ No newline at end of file +
+exec_program(pkg-config ARGS systemd --variable=systemdsystemconfdir OUTPUT_VARIABLE MR_INSTALL_SYSUNITDIR)
+
+# systemd install, use systemd to manage zcpd
+if(MR_INSTALL_SYSUNITDIR)
+ configure_file(systemd/mrenv.service.in systemd/mrenv.service)
+ install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrenv.service
+ DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program)
+
+ configure_file(systemd/mrzcpd.service.in systemd/mrzcpd.service)
+ install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrzcpd.service
+ DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program)
+
+ install(FILES systemd/mrenv-script DESTINATION ${MR_INSTALL_BINDIR}
+ PERMISSIONS WORLD_EXECUTE COMPONENT Program)
+else()
+ install(FILES mrstart DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
+ install(FILES mrstop DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
+ install(FILES mrzcpd DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE COMPONENT Program)
+endif()
\ No newline at end of file diff --git a/tools/Makefile b/tools/Makefile deleted file mode 100644 index ed23515..0000000 --- a/tools/Makefile +++ /dev/null @@ -1,6 +0,0 @@ - -.PHONY: install - -install: - cp dpdk_mlx4 /etc/init.d/ - cp *.sh $(INSTALL) diff --git a/tools/dpdk_intel b/tools/dpdk_intel deleted file mode 100644 index 5357f5a..0000000 --- a/tools/dpdk_intel +++ /dev/null @@ -1,218 +0,0 @@ -#! /bin/bash - -prog=dpdk_intel -config=/etc/ixgbe.conf - -quit() -{ - QUIT=$1 -} - -# -# Creates hugepage filesystem. -# -create_mnt_huge() -{ - echo "Creating /mnt/huge and mounting as hugetlbfs" - mkdir -p /mnt/huge - - grep -s '/mnt/huge' /proc/mounts > /dev/null - if [ $? -ne 0 ] ; then - mount -t hugetlbfs nodev /mnt/huge - fi -} - -# -# Removes hugepage filesystem. -# -remove_mnt_huge() -{ - echo "Unmounting /mnt/huge and removing directory" - grep -s '/mnt/huge' /proc/mounts > /dev/null - if [ $? -eq 0 ] ; then - umount /mnt/huge - fi - - if [ -d /mnt/huge ] ; then - rm -R /mnt/huge - fi -} - -# -# Unloads igb_uio.ko. -# -remove_igb_uio_module() -{ - echo "Unloading any existing DPDK UIO module" - /sbin/lsmod | grep -s igb_uio > /dev/null - if [ $? -eq 0 ] ; then - /sbin/rmmod igb_uio - fi -} - -# -# Loads new igb_uio.ko (and uio module if needed). -# -load_igb_uio_module() -{ - remove_igb_uio_module - - /sbin/lsmod | grep -s uio > /dev/null - if [ $? -ne 0 ] ; then - modinfo uio > /dev/null - if [ $? -eq 0 ]; then - echo "Loading uio module" - /sbin/modprobe uio - fi - fi - - # UIO may be compiled into kernel, so it may not be an error if it can't - # be loaded. - - echo "Loading DPDK UIO module" - /sbin/insmod $DPDK_MODULES_DIR/igb_uio.ko - if [ $? -ne 0 ] ; then - echo "## ERROR: Could not load kmod/igb_uio.ko." - quit - fi -} - -# -# Unloads the rte_kni.ko module. -# -remove_kni_module() -{ - echo "Unloading any existing DPDK KNI module" - /sbin/lsmod | grep -s rte_kni > /dev/null - if [ $? -eq 0 ] ; then - /sbin/rmmod rte_kni - fi -} - -# -# Loads the rte_kni.ko module. -# -load_kni_module() -{ - # Unload existing version if present. - remove_kni_module - - # Now try load the KNI module. - echo "Loading DPDK KNI module" - /sbin/insmod $DPDK_MODULES_DIR/rte_kni.ko - if [ $? -ne 0 ] ; then - echo "## ERROR: Could not load kmod/rte_kni.ko." - quit - fi -} - -# -# Removes all reserved hugepages. -# -clear_huge_pages() -{ - echo > .echo_tmp - for d in /sys/devices/system/node/node? ; do - echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp - done - echo "Removing currently reserved hugepages" - sh .echo_tmp - rm -f .echo_tmp - - remove_mnt_huge -} - -# -# Creates hugepages. -# -set_non_numa_pages() -{ - clear_huge_pages - - echo "echo $HUGEPAGE_MEM > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp - echo "Reserving hugepages" - - sh .echo_tmp - rm -f .echo_tmp - - create_mnt_huge -} - -# -# Uses dpdk_nic_bind.py to move devices to work with igb_uio -# -bind_nics_to_igb_uio() -{ - oldIFS=$IFS - IFS=, - for PCI_PATH in $IXGBE_UIO; do - $DPDK_TOOLS_DIR/dpdk_nic_bind -b igb_uio $PCI_PATH - done - IFS=$oldIFS -} - -# -# Uses dpdk_nic_bind.py to move devices to work with kernel drivers again -# -unbind_nics() -{ - oldIFS=$IFS - IFS=, - for PCI_PATH in $IXGBE_UIO; do - $DPDK_TOOLS_DIR/dpdk_nic_bind -b ixgbe $PCI_PATH - done - IFS=$oldIFS -} - -load_config_file() -{ - if [ ! -f $config ] ; then - echo "Loading Configure file $config error" - exit 3 - fi - source $config -} - -start() -{ - echo -n $"Starting $prog: " - - load_config_file - load_igb_uio_module - bind_nics_to_igb_uio - set_non_numa_pages - - return 0 -} - -stop() -{ - echo -n $"Stopping $prog: " - load_config_file - clear_huge_pages - unbind_nics - remove_igb_uio_module - - return 0 -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - *) - echo $"Usage: $0 {start|stop|restart}" - RETVAL=2 -esac -exit $RETVAL diff --git a/tools/dpdk_mlx4 b/tools/dpdk_mlx4 deleted file mode 100644 index 62b8289..0000000 --- a/tools/dpdk_mlx4 +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash -# -# dpdk-kernel Start up the DPDK configuration and insert kernel model -# -### END INIT INFO - -prog=dpdk_mlx4 -config=/etc/mlx4.conf - -load_mlx4_core_module() -{ - /sbin/insmod /lib/modules/$(uname -r)/kernel/drivers/net/mlx4/mlx4_core.ko - /sbin/insmod /lib/modules/$(uname -r)/kernel/drivers/net/mlx4/mlx4_en.ko -} - -remove_mlx4_uio_module() -{ - echo "Unloading any existing DPDK UIO module" - /sbin/lsmod | grep -s mlx4_uio > /dev/null - if [ $? -eq 0 ] ; then - sudo /sbin/rmmod mlx4_uio - fi -} - -remove_mlx4_en_module() -{ - echo "Unloading any existing MLX4 EN module" - /sbin/lsmod | grep -s mlx4_en > /dev/null - if [ $? -eq 0 ] ; then - sudo /sbin/rmmod mlx4_en - fi -} - -remove_mlx4_core_module() -{ - echo "Unloading any existing MLX4 CORE module" - /sbin/lsmod | grep -s mlx4_core > /dev/null - if [ $? -eq 0 ] ; then - sudo /sbin/rmmod mlx4_core - fi -} - -load_mlx4_uio_module() -{ - if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/mlx4_uio.ko ];then - echo "## ERROR: Target does not have the DPDK UIO Kernel Module." - echo " To fix, please try to rebuild target." - return - fi - - remove_mlx4_uio_module - - /sbin/lsmod | grep -s uio > /dev/null - if [ $? -ne 0 ] ; then - if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; then - echo "Loading uio module" - sudo /sbin/modprobe uio - fi - fi - - # UIO may be compiled into kernel, so it may not be an error if it can't - # be loaded. - - echo "Loading DPDK UIO module" - sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/mlx4_uio.ko intr_mode="msix" - if [ $? -ne 0 ] ; then - echo "## ERROR: Could not load kmod/mlx4_uio.ko." - quit - fi -} - -bind_mlx4_uio_module() -{ - oldIFS=$IFS - IFS=, - for PCI_PATH in $MLX4_UIO; do - sudo ${RTE_SDK}/tools/pci_unbind.py -b mlx4_uio $PCI_PATH - done - IFS=$oldIFS -} - -unbind_mlx4_uio_module() -{ - oldIFS=$IFS - IFS=, - - for PCI_PATH in $MLX4_UIO; do - sudo ${RTE_SDK}/tools/pci_unbind.py -b mlx4_core $PCI_PATH - done - IFS=$oldIFS -} - - -remove_mnt_huge() -{ - echo "Unmounting /mnt/huge and removing directory" - grep -s '/mnt/huge' /proc/mounts > /dev/null - if [ $? -eq 0 ] ; then - sudo umount /mnt/huge - fi - - if [ -d /mnt/huge ] ; then - sudo rm -R /mnt/huge - fi -} - -create_mnt_huge() -{ - echo "Creating /mnt/huge and mounting as hugetlbfs" - sudo mkdir -p /mnt/huge - - grep -s '/mnt/huge' /proc/mounts > /dev/null - if [ $? -ne 0 ] ; then - sudo mount -t hugetlbfs nodev /mnt/huge - fi -} - -clear_huge_pages() -{ - echo > .echo_tmp - for d in /sys/devices/system/node/node? ; do - echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp - done - echo "Removing currently reserved hugepages" - sudo sh .echo_tmp - rm -f .echo_tmp - - remove_mnt_huge -} - -# -# Creates hugepages. -# -set_non_numa_pages() -{ - clear_huge_pages - - echo "echo $HUGEPAGE_MEM > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp - echo "Reserving hugepages" - sudo sh .echo_tmp - rm -f .echo_tmp - create_mnt_huge -} - -load_config_file() -{ - if [ ! -f $config ] ; then - echo "Loading Configure file $config error" - exit 3 - fi - source $config -} - -start() -{ - echo -n $"Starting $prog: " - - load_config_file - load_mlx4_uio_module - bind_mlx4_uio_module - set_non_numa_pages - - return 0 -} - -stop() -{ - echo -n $"Stopping $prog: " - load_config_file - clear_huge_pages - unbind_mlx4_uio_module - remove_mlx4_uio_module - - return 0 -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - *) - echo $"Usage: $0 {start|stop|restart}" - RETVAL=2 -esac -exit $RETVAL diff --git a/tools/drv_monitor.sh b/tools/drv_monitor.sh deleted file mode 100644 index 4903da3..0000000 --- a/tools/drv_monitor.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -sleep_period=1 -worker_proc_name="start" -driver_proc_name="driver" -log_path="./MONITOR.log" - -get_worker_proc_num() -{ - num=`ps -ef | grep $worker_proc_name | grep -v grep | wc -l` - return $num -} - -get_driver_proc_num() -{ - num=`ps -ef | grep $driver_proc_name | grep -v grep | wc -l` - return $num -} - -while true -do - sleep $sleep_period - - get_worker_proc_num - nb_worker=$? - get_driver_proc_num - nb_driver=$? - - if [ $nb_worker -ge 1 ] && [ $nb_driver -eq 0 ] - then - pkill -f $worker_proc_name - fi -done - diff --git a/tools/drv_start.sh b/tools/drv_start.sh deleted file mode 100644 index 8e75d58..0000000 --- a/tools/drv_start.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -DRV_PROG=/usr/local/bin/marsio -DRV_MONITOR=./drv_monitor.sh - -sh $DRV_MONITOR & - -while [ 1 ]; do - count=`ls -l core.* |wc -l` - echo $count - if [ $count -lt 6 ] - then - ulimit -c unlimited - else - ulimit -c 0 - fi - - $DRV_PROG >> marsio.$(date +"%Y-%m-%d_%H-%M").log - echo $DRV_PROG crashed, restart at $(date +"%w %Y/%m/%d, %H:%M:%S") >> RESTART.log - sleep 5 -done
\ No newline at end of file diff --git a/tools/r2_driver.sh b/tools/r2_driver.sh deleted file mode 100644 index 19c8089..0000000 --- a/tools/r2_driver.sh +++ /dev/null @@ -1 +0,0 @@ -./drv_start.sh &> /dev/null & diff --git a/tools/mrstart b/tools/script/mrstart index 4895168..55722c0 100644 --- a/tools/mrstart +++ b/tools/script/mrstart @@ -37,7 +37,7 @@ NR_HUGEPAGE_FILE_1G=/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages HUGEPAGE_PATH_2M=/mnt/.huge_2M HUGEPAGE_PATH_1G=/mnt/.huge_1G -DAEMON_BASENAME=marsio +DAEMON_BASENAME=zcpd DAEMON=$DAEMOH_PATH/$DAEMON_BASENAME cd $DAEMOH_PATH diff --git a/tools/mrstop b/tools/script/mrstop index 91ea99c..6cadebd 100644 --- a/tools/mrstop +++ b/tools/script/mrstop @@ -9,7 +9,7 @@ HUGEPAGE_PATH_2M=/mnt/.huge_2M HUGEPAGE_PATH_1G=/mnt/.huge_1G -DAEMON_BASENAME=marsio +DAEMON_BASENAME=zcpd DAEMON=$DAEMOH_PATH/$DAEMON_BASENAME function kill_app() diff --git a/tools/mrzcpd b/tools/script/mrzcpd index b351d76..049dca0 100644 --- a/tools/mrzcpd +++ b/tools/script/mrzcpd @@ -38,7 +38,7 @@ HUGEPAGE_PATH_2M=/mnt/.huge_2M HUGEPAGE_PATH_1G=/mnt/.huge_1G # Execuate File path -DAEMON=$DAEMOH_PATH/marsio +DAEMON=$DAEMOH_PATH/zcpd NICTOOL=$DPDK_ROOT/sbin/dpdk_nic_bind DAEMON_START=$MARSIO_ROOT/bin/mrstart DAEMON_STOP=$MARSIO_ROOT/bin/mrstop @@ -232,6 +232,8 @@ function start() # Require Step, if failure, all step should be stop. action $"Loading IGB_UIO Module:" module_load_uio [ ! $? -eq 0 ] && return 1 + + action $"Loading Hugepage memory:" huge_alloc [ ! $? -eq 0 ] && return 1 action $"Binding IXGBE NIC Device with IGB_UIO:" nic_bind_ixgbe diff --git a/tools/systemd/mrenv-script b/tools/systemd/mrenv-script new file mode 100644 index 0000000..89c3e12 --- /dev/null +++ b/tools/systemd/mrenv-script @@ -0,0 +1,312 @@ +#!/bin/bash +# + +if [ -z "$DPDK_ROOT" ]; then + DPDK_ROOT="/opt/iiesoft/dpdk" +fi + +if [ -z "$MRZCPD_ROOT" ]; then + MRZCPD_ROOT=$(pkg-config mrzcpd --variable=prefix) +fi + +if [ -z "$HUGEPAGE_NUM_2M" ]; then + HUGEPAGE_NUM_2M=0 +fi + +if [ -z "$HUGEPAGE_NUM_1G" ]; then + HUGEPAGE_NUM_1G=0 +fi + +if [ -z "$PCI_ADDR_IXGBE" ]; then + PCI_ADDR_IXGBE="" +fi + +if [ -z "$PCI_ADDR_IGB" ]; then + PCI_ADDR_IGB="" +fi + +MODULE_PATH=$DPDK_ROOT/lib/modules/$(uname -r)/extra/dpdk +BIN_PATH=$MRZCPD_ROOT/bin/ +KNI_MODULE=rte_kni +UIO_MODULE=igb_uio + +NR_HUGEPAGE_FILE_2M=/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages +NR_HUGEPAGE_FILE_1G=/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages +HUGEPAGE_PATH_2M=/mnt/.huge_2M +HUGEPAGE_PATH_1G=/mnt/.huge_1G + +DAEMON=$BIN_PATH/marsio +NICTOOL=$DPDK_ROOT/sbin/dpdk_nic_bind +KNI_MODULE_FILENAME=$KNI_MODULE.ko +UIO_MODULE_FILENAME=$UIO_MODULE.ko + +function module_unload_uio() +{ + lsmod | grep -s $UIO_MODULE > /dev/null 2>&1 + [ $? -eq 0 ] && rmmod $UIO_MODULE 2>&1 + [ ! $? -eq 0 ] && return 1 + return 0 +} + +function module_unload_kni() +{ + lsmod | grep -s $KNI_MODULE > /dev/null 2>&1 + [ $? -eq 0 ] && rmmod $KNI_MODULE 2>&1 + [ ! $? -eq 0 ] && return 1 + return 0 +} + +function module_load_kni() +{ + if [ ! -e $MODULE_PATH/$KNI_MODULE_FILENAME ]; then + echo -n "$KNI_MODULE_FILENAME does not existed. " + return 1 + fi + + module_unload_kni + insmod $MODULE_PATH/$KNI_MODULE_FILENAME > /dev/null 2>&1 + [ ! $? -eq 0 ] && echo -n " $MODULE_PATH/$KNI_MODULE_FILENAME load failure." && return 1 + return 0 +} + +function module_load_uio() +{ + if [ ! -e $MODULE_PATH/$UIO_MODULE_FILENAME ]; then + echo -n "$MODULE_PATH/$UIO_MODULE_FILENAME does not existed. Check DPDK is installed or not. " + return 1 + fi + + module_unload_uio + modprobe uio &> /dev/null + insmod $MODULE_PATH/$UIO_MODULE_FILENAME + [ ! $? -eq 0 ] && echo -n "$MODULE_PATH/$UIO_MODULE_FILENAME load failure." && return 1 + return 0 +} + +function huge_release_1G() +{ + cat /proc/mounts | grep "$HUGEPAGE_PATH_1G" > /dev/null + grep -s "$HUGEPAGE_PATH_1G" /proc/mounts > /dev/null + if [ $? -eq 0 ]; then + umount $HUGEPAGE_PATH_1G > /dev/null + [ ! $? -eq 0 ] && echo "umount 1G hugepage failure, maybe in use" && return 1 + fi + + if [ -d $HUGEPAGE_PATH_1G ] ; then + rm -R $HUGEPAGE_PATH_1G + [ ! $? -eq 0 ] && echo "Cannot delete 2M hugepage" && return 1 + fi + return 0 +} + +function huge_release_2M() +{ + cat /proc/mounts | grep "$HUGEPAGE_PATH_2M" > /dev/null + grep -s "$HUGEPAGE_PATH_2M" /proc/mounts > /dev/null + if [ $? -eq 0 ]; then + umount $HUGEPAGE_PATH_2M > /dev/null + [ ! $? -eq 0 ] && echo "umount 2M hugepage failure, maybe in use" && return 1 + fi + + if [ -d $HUGEPAGE_PATH_2M ] ; then + rm -R $HUGEPAGE_PATH_2M + [ ! $? -eq 0 ] && echo "Cannot delete 2M hugepage" && return 1 + fi + + if [ -e $NR_HUGEPAGE_FILE_2M ]; then + echo -n 0 > $NR_HUGEPAGE_FILE_2M + fi + + return 0 +} + +function huge_alloc_1G() +{ + if [ ! -e $NR_HUGEPAGE_FILE_1G ]; then + return 1 + fi + + SIZE_1G=$(cat $NR_HUGEPAGE_FILE_1G) + [ $SIZE_1G -eq 0 ] && echo -n $HUGEPAGE_NUM_1G > $NR_HUGEPAGE_FILE_1G + + mkdir -p $HUGEPAGE_PATH_1G + mount -t hugetlbfs nodev -o pagesize=1G $HUGEPAGE_PATH_1G + [ $? -eq 0 ] && return 0 + + return 1 +} + +function huge_alloc_2M() +{ + if [ ! -e $NR_HUGEPAGE_FILE_2M ]; then + return 1 + fi + + SIZE_2M=$(cat $NR_HUGEPAGE_FILE_2M) + [ $SIZE_2M -eq 0 ] && echo -n $HUGEPAGE_NUM_2M > $NR_HUGEPAGE_FILE_2M + mkdir -p $HUGEPAGE_PATH_2M + mount -t hugetlbfs nodev $HUGEPAGE_PATH_2M + [ $? -eq 0 ] && return 0 + return 1 +} + +function huge_alloc() +{ + if [ ! $HUGEPAGE_NUM_1G -eq 0 ]; then + huge_release_1G + huge_alloc_1G + fi + + if [ ! $HUGEPAGE_NUM_2M -eq 0 ]; then + huge_release_2M + huge_alloc_2M + fi + + return $? +} + +function huge_release() +{ + huge_release_1G && huge_release_2M + huge_release_2M + return $? +} + +function nic_unbind_ixgbe() +{ + OLDIFS=$IFS; IFS=, + for ITER_PCI_ADDR in $PCI_ADDR_IXGBE; do + $NICTOOL --force -b ixgbe $ITER_PCI_ADDR + [ ! $? -eq 0 ] && return 1 + done + IFS=$OLDIFS + return 0 +} + +function nic_unbind_igb() +{ + OLDIFS=$IFS; IFS=, + for ITER_PCI_ADDR in $PCI_ADDR_IGB; do + $NICTOOL --force -b igb $ITER_PCI_ADDR + [ ! $? -eq 0 ] && return 1 + done + IFS=$OLDIFS + return 0 +} + +function nic_bind_ixgbe() +{ + OLDIFS=$IFS; IFS=, + for ITER_PCI_ADDR in $PCI_ADDR_IXGBE; do + $NICTOOL --force -b igb_uio $ITER_PCI_ADDR + [ ! $? -eq 0 ] && return 1 + done + IFS=$OLDIFS + return 0 +} + +function nic_bind_igb() +{ + OLDIFS=$IFS; IFS=, + for ITER_PCI_ADDR in $PCI_ADDR_IGB; do + $NICTOOL --force -b igb_uio $ITER_PCI_ADDR + [ ! $? -eq 0 ] && return 1 + done + IFS=$OLDIFS + return 0 +} + +function check_app_exist() +{ + APP_USE_HUGE_2M=$(lsof -t $HUGEPAGE_PATH_2M 2>/dev/null) + RET1=$? + APP_USE_HUGE_1G=$(lsof -t $HUGEPAGE_PATH_1G 2>/dev/null) + RET2=$? + + return $RET1 || $RET2 +} + +function kill_app() +{ + APP_USE_HUGE_2M=$(lsof -t $HUGEPAGE_PATH_2M 2>/dev/null) + RET1=$? + APP_USE_HUGE_1G=$(lsof -t $HUGEPAGE_PATH_1G 2>/dev/null) + RET2=$? + + if [ $RET1 -eq 0 -a "$APP_USE_HUGE_2M" != "" ]; then + kill $APP_USE_HUGE_2M + fi + if [ $RET2 -eq 0 -a "$APP_USE_HUGE_1G" != "" ]; then + kill $APP_USE_HUGE_1G + fi + return 0 +} + +function marsiod_stop() +{ + kill_app + return 0 +} + +function marsiod_start() +{ + echo 0 > /proc/sys/kernel/randomize_va_space + return 0 +} + +function start() +{ + # Require Step, if failure, all step should be stop. + module_load_uio + [ ! $? -eq 0 ] && return 1 + huge_alloc + [ ! $? -eq 0 ] && return 1 + nic_bind_ixgbe + [ ! $? -eq 0 ] && return 1 + nic_bind_igb + [ ! $? -eq 0 ] && return 1 + marsiod_start + [ ! $? -eq 0 ] && return 1 + return 0 +} + +function stop() +{ + marsiod_stop + [ ! $? -eq 0 ] && return 1 + huge_release + [ ! $? -eq 0 ] && return 1 + nic_unbind_ixgbe + [ ! $? -eq 0 ] && return 1 + nic_unbind_igb + [ ! $? -eq 0 ] && return 1 + module_unload_uio + [ ! $? -eq 0 ] && return 1 + return 0 +} + +function restart() +{ + stop + start $* +} + +action=$1 +shift + +case $action in + start) + start $* + ;; + stop) + stop + ;; + restart) + restart $* + ;; + *) + echo "Usage: service $0 {start|stop|restart}" + exit 1 +esac + +exit $?
\ No newline at end of file diff --git a/tools/systemd/mrenv.service.in b/tools/systemd/mrenv.service.in new file mode 100644 index 0000000..533071b --- /dev/null +++ b/tools/systemd/mrenv.service.in @@ -0,0 +1,13 @@ +[Unit] +Description=Setup/Unsetup mrzcpd runtime environment +After=network.target + +[Service] +Type=oneshot +EnvironmentFile=/etc/sysconfig/mrzcpd +ExecStart=@MR_INSTALL_BINDIR@/mrenv-script start +ExecStop=@MR_INSTALL_BINDIR@/mrenv-script stop +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target
\ No newline at end of file diff --git a/tools/systemd/mrzcpd.service.in b/tools/systemd/mrzcpd.service.in new file mode 100644 index 0000000..3bab77a --- /dev/null +++ b/tools/systemd/mrzcpd.service.in @@ -0,0 +1,12 @@ +[Unit] +Description=Marsio ZeroCopy Driver Daemon +Requires=mrenv.service +After=mrenv.service + +[Service] +EnvironmentFile=/etc/sysconfig/mrzcpd +ExecStart=@MR_INSTALL_BINDIR@/marsio +Restart=on-failure + +[Install] +WantedBy=multi-user.target
\ No newline at end of file |
