diff mbox series

[v2] ltq-dsl-base: only lock the dsl pipe once for all stats

Message ID 20201204115734.31639-1-a.heider@gmail.com
State Superseded
Headers show
Series [v2] ltq-dsl-base: only lock the dsl pipe once for all stats | expand

Commit Message

Andre Heider Dec. 4, 2020, 11:57 a.m. UTC
Instead of locking/unlocking it for every command.

Reduces the runtime for the dslstat/lucistat commands to ~66%.

Before:
real	0m 2.66s
user	0m 0.90s
sys	0m 1.76s

After:
real	0m 1.76s
user	0m 0.63s
sys	0m 1.13s

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
v2: bump PKG_RELEASE

 package/network/utils/ltq-dsl-base/Makefile   |  2 +-
 .../files/lib/functions/lantiq_dsl.sh         | 21 +++++++++++++------
 2 files changed, 16 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/package/network/utils/ltq-dsl-base/Makefile b/package/network/utils/ltq-dsl-base/Makefile
index e2cfc4004c..aae07bc299 100644
--- a/package/network/utils/ltq-dsl-base/Makefile
+++ b/package/network/utils/ltq-dsl-base/Makefile
@@ -6,7 +6,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ltq-dsl-base
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 include $(INCLUDE_DIR)/package.mk
 
diff --git a/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh b/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
index 39011f134f..89dc5c25c9 100755
--- a/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
+++ b/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
@@ -7,16 +7,24 @@  else
 	XDSL_CTRL=dsl_cpe_control
 fi
 
+DSL_PIPE_LOCKED=0
+
 #
 # Basic functions to send CLI commands to the vdsl_cpe_control daemon
 #
+dsl_init() {
+	killall -q -0 ${XDSL_CTRL} && lock /var/lock/dsl_pipe && DSL_PIPE_LOCKED=1
+	trap dsl_deinit EXIT INT KILL TERM
+}
+dsl_deinit() {
+	test $DSL_PIPE_LOCKED -gt 0 && lock -u /var/lock/dsl_pipe && DSL_PIPE_LOCKED=0
+	exit
+}
 dsl_cmd() {
-	killall -q -0 ${XDSL_CTRL} && (
-		lock /var/lock/dsl_pipe
-		echo "$@" > /tmp/pipe/dsl_cpe0_cmd
-		cat /tmp/pipe/dsl_cpe0_ack
-		lock -u /var/lock/dsl_pipe
-	)
+	test $DSL_PIPE_LOCKED -eq 0 && return
+
+	echo "$@" > /tmp/pipe/dsl_cpe0_cmd
+	cat /tmp/pipe/dsl_cpe0_ack
 }
 dsl_val() {
 	expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*'
@@ -783,6 +791,7 @@  line_features() {
 }
 
 dslstat() {
+	dsl_init
 	vendor
 	chipset
 	xtse