From 613ef102733276a25e531d42f049e67a7e8052de Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Tue, 12 Jan 2021 13:53:51 +0530 Subject: [PATCH] qosmngr: C daemon for gathering queue stats --- qosmngr/Makefile | 23 ++- qosmngr/files/etc/init.d/qos | 9 +- qosmngr/files/lib/qos/broadcom.sh | 225 ----------------------------- qosmngr/files/usr/libexec/rpcd/qos | 30 ---- 4 files changed, 23 insertions(+), 264 deletions(-) delete mode 100755 qosmngr/files/usr/libexec/rpcd/qos diff --git a/qosmngr/Makefile b/qosmngr/Makefile index 3752a3bbc..2fc87d5f5 100644 --- a/qosmngr/Makefile +++ b/qosmngr/Makefile @@ -8,8 +8,15 @@ include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=qosmngr PKG_VERSION:=1.0.0 -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) +LOCAL_DEV:=0 +ifneq ($(LOCAL_DEV),1) +PKG_SOURCE_PROTO:=git +PKG_SOURCE_VERSION:=03df56c6eb7c6737ce95576e89c915df77396953 +PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/qosmngr.git +PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz +endif +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) PKG_LICENSE:=GPL-2.0-only PKG_LICENSE_FILES:=LICENSE @@ -19,22 +26,24 @@ define Package/qosmngr SECTION:=utils CATEGORY:=Utilities TITLE:=QoS Manager - DEPENDS:=@(TARGET_iopsys_brcm63xx_arm) + DEPENDS:=@(TARGET_iopsys_brcm63xx_arm) +libuci +libubox +libubus +libblobmsg-json +libjson-c +libqos endef define Package/qosmngr/description Configures L2 QoS and collects queue statistics endef -#define Build/Prepare -# $(CP) -rf ./qosmngr/* $(PKG_BUILD_DIR)/ -#endef - -define Build/Compile +ifeq ($(LOCAL_DEV),1) +define Build/Prepare + $(CP) -rf ./qosmngr/* $(PKG_BUILD_DIR)/ endef +endif define Package/qosmngr/install $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/usr + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/qosmngr $(1)/usr/sbin endef $(eval $(call BuildPackage,qosmngr)) diff --git a/qosmngr/files/etc/init.d/qos b/qosmngr/files/etc/init.d/qos index 5a69c7dac..3014f767b 100755 --- a/qosmngr/files/etc/init.d/qos +++ b/qosmngr/files/etc/init.d/qos @@ -4,18 +4,23 @@ # include /lib/qos START=21 +STOP=10 USE_PROCD=1 NAME=qosmngr +PROG=/usr/sbin/qosmngr . /lib/functions.sh include /lib/qos start_service() { if [ -f "/etc/config/qos" ]; then - ubus -S call qos reload + reload_qos + procd_open_instance qosmngr + procd_set_param command ${PROG} + procd_set_param respawn + procd_close_instance fi - } stop() { diff --git a/qosmngr/files/lib/qos/broadcom.sh b/qosmngr/files/lib/qos/broadcom.sh index e7281627b..ca7a99bbb 100755 --- a/qosmngr/files/lib/qos/broadcom.sh +++ b/qosmngr/files/lib/qos/broadcom.sh @@ -886,228 +886,3 @@ reload_qos() { configure_policer fi } - -get_queue_stats() { - local ifname - local f_name - local tmp_val - local q_index=0 - local max_q_index=0 - - json_init - json_add_array "queues" - - if [ -n "$1" ]; then - ifname=$1 - max_q_index=$(cat /tmp/qos/queue_stats/${ifname}/q_idx) - while : - do - if [ $q_index -eq $max_q_index ]; then - break - fi - stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $q_index)" - ret="$(echo $stats | awk '{print substr($0,0,5)}')" - #check tmctl ERROR condition - if [ $ret == 'ERROR' ]; then - q_index=$((q_index + 1)) - continue - fi - json_add_object "" - json_add_int "qid" "$q_index" - json_add_string "iface" "$ifname" - - IFS=$'\n' - for stat in $stats; do - pname="$(echo $stat | awk '{print$1}')" - if [ $pname == 'ret' ]; then - continue - fi - - val="$(echo $stat | awk '{print$2}')" - - # remove trailing : from the name - pname="${pname::-1}" - local f_name="/tmp/qos/queue_stats/${ifname}/q_${q_index}/${pname}" - # In non BCM968* chips, read operation on queues is actually a read and reset, - # so values need to be maintained to present cumulative value - if [ $POLICER_SKIP -eq 0 ]; then - tmp_val=$(cat $f_name) - val=$((val + tmp_val)) - fi - echo $val > $f_name - - # convert to iopsyswrt names - case "$pname" in - txPackets) - json_add_int "tx_packets" "$val" - ;; - txBytes) - json_add_int "tx_bytes" "$val" - ;; - droppedPackets) - json_add_int "tx_dropped_packets" "$val" - ;; - droppedBytes) - json_add_int "tx_dropped_bytes" "$val" - ;; - esac - done - json_close_object - - q_index=$((q_index + 1)) - done - else - for intf in $(db get hw.board.ethernetPortOrder); do - ifname=$intf - q_index=0 - max_q_index=$(cat /tmp/qos/queue_stats/${ifname}/q_idx) - while : - do - if [ $q_index -eq $max_q_index ]; then - break - fi - stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $q_index)" - ret="$(echo $stats | awk '{print substr($0,0,5)}')" - #check tmctl ERROR condition - if [ $ret == 'ERROR' ]; then - q_index=$((q_index + 1)) - continue - fi - json_add_object "" - json_add_int "qid" "$q_index" - json_add_string "iface" "$ifname" - - IFS=$'\n' - for stat in $stats; do - pname="$(echo $stat | awk '{print$1}')" - if [ $pname == 'ret' ]; then - continue - fi - - val="$(echo $stat | awk '{print$2}')" - - # remove trailing : from the name - pname="${pname::-1}" - local f_name="/tmp/qos/queue_stats/${ifname}/q_${q_index}/${pname}" - # In non BCM968* chips, read operation on queues is actually a read and reset, - # so values need to be maintained to present cumulative value - if [ $POLICER_SKIP -eq 0 ]; then - tmp_val=$(cat $f_name) - val=$((val + tmp_val)) - fi - echo $val > $f_name - - # convert to iopsyswrt names - case "$pname" in - txPackets) - json_add_int "tx_packets" "$val" - ;; - txBytes) - json_add_int "tx_bytes" "$val" - ;; - droppedPackets) - json_add_int "tx_dropped_packets" "$val" - ;; - droppedBytes) - json_add_int "tx_dropped_bytes" "$val" - ;; - esac - done - json_close_object - - q_index=$((q_index + 1)) - done - done - fi - - json_close_array - json_dump -} - -get_eth_q_stats() { - json_init - json_add_array "queues" - - ifname="$1" - local tmp_val=0 - - # if ifname is empty that is good enough to break - if [ -z "$ifname" ];then - return - fi - - qid="$2" - if [ -z "$qid" ];then - return - fi - - stats="$(tmctl getqstats --devtype 0 --if $ifname --qid $qid)" - ret="$(echo $stats | awk '{print substr($0,0,5)}')" - - #check tmctl ERROR condition - if [ $ret == 'ERROR' ]; then - return - fi - - json_add_object "" - json_add_int "qid" "$qid" - json_add_string "iface" "$ifname" - - IFS=$'\n' - for stat in $stats; do - pname="$(echo $stat | awk '{print$1}')" - if [ $pname == 'ret' ]; then - continue - fi - - val="$(echo $stat | awk '{print$2}')" - - # remove trailing : from the name - pname="${pname::-1}" - local f_name="/tmp/qos/queue_stats/${ifname}/q_${qid}/${pname}" - # In non BCM968* chips, read operation on queues is actually a read and reset, - # so values need to be maintained to present cumulative value - if [ $POLICER_SKIP -eq 0 ]; then - tmp_val=$(cat $f_name) - val=$((val + tmp_val)) - fi - echo $val > $f_name - - # convert to iopsyswrt names - case "$pname" in - txPackets) - json_add_int "tx_packets" "$val" - ;; - txBytes) - json_add_int "tx_bytes" "$val" - ;; - droppedPackets) - json_add_int "tx_dropped_packets" "$val" - ;; - droppedBytes) - json_add_int "tx_dropped_bytes" "$val" - ;; - esac - done - - json_close_object - - json_close_array - json_dump -} - -read_queue_stats() { - itf="$1" - q_idx="$2" - local cpu_model="$(brcm_fw_tool -k info)" - - case $cpu_model in - 68*|6755) POLICER_SKIP=1 ;; - esac - - if [ -n "$itf" -a -n "$q_idx" ]; then - get_eth_q_stats $itf $q_idx - else - get_queue_stats $itf - fi -} diff --git a/qosmngr/files/usr/libexec/rpcd/qos b/qosmngr/files/usr/libexec/rpcd/qos deleted file mode 100755 index 338a545a5..000000000 --- a/qosmngr/files/usr/libexec/rpcd/qos +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -. /usr/share/libubox/jshn.sh -. /lib/functions.sh -include /lib/qos - -case "$1" in - list) - echo '{ "queue_stats": { "ifname":"String", "qid":"Integer" }, "reload": { "section":"String" } }' - ;; - call) - case "$2" in - queue_stats) - read input; - json_load "$input" - json_get_var iface ifname - json_get_var qid qid - - read_queue_stats $iface $qid - ;; - reload) - read input; - json_load "$input" - json_get_var service section - reload_qos $service - ;; - esac - ;; -esac -