qosmngr: C daemon for gathering queue stats

This commit is contained in:
Shubham Sharma 2021-01-12 13:53:51 +05:30
parent 06c2d704a9
commit 613ef10273
4 changed files with 23 additions and 264 deletions

View file

@ -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))

View file

@ -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() {

View file

@ -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
}

View file

@ -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