improve stats reporting

now again use three messages to transmit stats (much more efficient than
sending single values, also more acurate).
This commit is contained in:
Martin Preuss
2025-08-25 10:22:05 +02:00
parent 7efaf720cc
commit 6e062d3f60
13 changed files with 234 additions and 186 deletions

View File

@@ -25,7 +25,13 @@ AppNetwork_SendTxdStats:
bigcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendTxdStats_end:
ret
; @end
@@ -35,7 +41,7 @@ AppNetwork_SendTxdStats_end:
; ---------------------------------------------------------------------------
; @routine AppNetwork_SendRxdStats
; @param Y network interface to work with
; @param Y network interface whose stats to send
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
AppNetwork_SendRxdStats:
@@ -46,7 +52,13 @@ AppNetwork_SendRxdStats:
bigcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendRxdStats_end:
ret
; @end
@@ -54,9 +66,8 @@ AppNetwork_SendRxdStats_end:
; ---------------------------------------------------------------------------
; @routine AppNetwork_SendRxdStats
; @routine AppNetwork_SendMemStats
; @param Y network interface to work with
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
AppNetwork_SendMemStats:
@@ -67,7 +78,13 @@ AppNetwork_SendMemStats:
bigcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendMemStats_end:
ret
; @end

View File

@@ -11,7 +11,7 @@
; ***************************************************************************
; defines
.equ APP_STATS_INTERVAL_MINS = 31
.equ APP_STATS_INTERVAL_MINS = 10
@@ -62,10 +62,6 @@ AppStats_OnEveryMinute:
ret
AppStats_OnEveryMinute_noIrq:
; ldi yl, LOW(netInterfaceData)
; ldi yh, HIGH(netInterfaceData)
; rcall AppNetwork_SendRxdStats ; debug
lds r16, appStatsTimer
inc r16
cpi r16, APP_STATS_INTERVAL_MINS
@@ -73,71 +69,28 @@ AppStats_OnEveryMinute_noIrq:
clr r16
AppStats_OnEveryMinute_store:
sts appStatsTimer, r16
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
ldi r17, AQHOME_VALUEID_STATS_PACKETS_IN
ldi xl, LOW(netInterfaceData)
ldi xh, HIGH(netInterfaceData)
cpi r16, 1
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 2
breq AppStats_OnEveryMinute_sendMemStats
cpi r16, 3
breq AppStats_OnEveryMinute_sendPacketsIn
cpi r16, 5
breq AppStats_OnEveryMinute_sendPacketsOut
cpi r16, 6
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 7
breq AppStats_OnEveryMinute_sendContentErrs
cpi r16, 9
breq AppStats_OnEveryMinute_sendIoErrs
cpi r16, 10
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 11
breq AppStats_OnEveryMinute_sendNoBufErrs
cpi r16, 13
breq AppStats_OnEveryMinute_sendCollisionErrs
cpi r16, 14
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 15
breq AppStats_OnEveryMinute_sendBusyErrs
breq AppStats_OnEveryMinute_sendRecvStats1
cpi r16, 4
breq AppStats_OnEveryMinute_sendSendStats1
#ifdef APP_STATS_NETDEV2
ldi r17, AQHOME_VALUEID_STATS_PACKETS_IN2
ldi xl, LOW(netInterfaceData2)
ldi xh, HIGH(netInterfaceData2)
cpi r16, 16
breq AppStats_OnEveryMinute_sendPacketsIn
cpi r16, 17
breq AppStats_OnEveryMinute_sendPacketsOut
cpi r16, 18
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 19
breq AppStats_OnEveryMinute_sendContentErrs
cpi r16, 20
breq AppStats_OnEveryMinute_sendIoErrs
cpi r16, 21
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 22
breq AppStats_OnEveryMinute_sendNoBufErrs
cpi r16, 23
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 24
breq AppStats_OnEveryMinute_sendCollisionErrs
cpi r16, 25
breq AppStats_OnEveryMinute_sendBusyErrs
#endif
cpi r16, 5
breq AppStats_OnEveryMinute_sendRecvStats2
#ifdef MODULES_HEAP
cpi r16, 26
breq AppStats_OnEveryMinute_sendHeapUsed
cpi r16, 27
breq AppStats_OnEveryMinute_sendHeapfree
cpi r16, 6
breq AppStats_OnEveryMinute_sendSendStats2
#endif
cpi r16, 28
breq AppStats_OnEveryMinute_sendDevice
; add more here
ret
AppStats_OnEveryMinute_sendDevice:
push yl
push yh
@@ -152,68 +105,35 @@ AppStats_OnEveryMinute_sendDevice:
pop yh
pop yl
ret
AppStats_OnEveryMinute_sendPacketsIn:
ldi r16, 0
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendPacketsOut:
ldi r16, 1
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendContentErrs:
ldi r16, 2
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendIoErrs:
ldi r16, 3
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendNoBufErrs:
ldi r16, 4
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendCollisionErrs:
ldi r16, 5
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendBusyErrs:
ldi r16, 6
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendMemStats:
rjmp AppNetwork_SendMemStats
#ifdef MODULES_HEAP
AppStats_OnEveryMinute_sendHeapUsed:
ldi r17, AQHOME_VALUEID_STATS_HEAP_USED
lds r18, heapUsed
lds r19, heapUsed+1
rjmp appStatsSend16BitValue
AppStats_OnEveryMinute_sendHeapfree:
ldi r17, AQHOME_VALUEID_STATS_HEAP_FREE
lds r18, heapFree
lds r19, heapFree+1
rjmp appStatsSend16BitValue
AppStats_OnEveryMinute_sendRecvStats1:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats1:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendTxdStats
#ifdef APP_STATS_NETDEV2
AppStats_OnEveryMinute_sendRecvStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendTxdStats
#endif
; @end
; ---------------------------------------------------------------------------
; @routine AppStats_OnEveryMinute @global
;
; @param r16 index into device table (e.g. 0 for NET_IFACE_OFFS_PACKETSIN_LOW)
; @param r17 offset to first value id (e.g. AQHOME_VALUEID_STATS_PACKETS_IN for device 0,
; AQHOME_VALUEID_STATS_PACKETS_IN2 for device 1)
; @param Y pointer to device to send data to
; @param X pointer to device to inspect
appStatsSendDeviceStat:
add r17, r16
lsl r16
adiw xh:xl, NET_IFACE_OFFS_PACKETSIN_LOW
add xl, r16
adc xh, r16
sub xh, r16
ld r18, X+
ld r19, X
rjmp appStatsSend16BitValue
; @end
; ---------------------------------------------------------------------------
; @routine AppStats_OnEveryMinute @global
;

View File

@@ -165,10 +165,11 @@ Offset Length Meaning
2 1 command code
3 1 source address
---------------------------------------------------------
4 4 UID of the sending node
8 2 packets out
10 2 collisions
12 2 line busy errors
4 1 Interface number
5 4 UID of the sending node
9 2 packets out
11 2 collisions
13 2 line busy errors
---------------------------------------------------------
14 1 CRC8 byte
@@ -185,15 +186,16 @@ Offset Length Meaning
2 1 command code
3 1 source address
---------------------------------------------------------
4 4 UID of the sending node
8 2 packets in
10 2 content errors (invalid msg length, CRC errors)
12 2 io errors
14 2 no buffer errors
16 2 handled packets
18 2 missed packets
4 1 Interface number
5 4 UID of the sending node
9 2 packets in
11 2 content errors (invalid msg length, CRC errors)
13 2 io errors
15 2 no buffer errors
17 2 handled packets
19 2 missed packets
---------------------------------------------------------
20 1 CRC8 byte
21 1 CRC8 byte

View File

@@ -14,8 +14,8 @@
.equ NETMSG_CMD_PING = 10
.equ NETMSG_CMD_PONG = 11
.equ NETMSG_CMD_SENDSTATS = 20
.equ NETMSG_CMD_RECVSTATS = 21
.equ NETMSG_CMD_SENDSTATS = 22
.equ NETMSG_CMD_RECVSTATS = 23
.equ NETMSG_CMD_TWIBUSMEMBER = 30
.equ NETMSG_CMD_DEBUG = 40

View File

@@ -51,14 +51,10 @@ NETMSG_MemStats_Write:
st X+, r21
.endif
; current buffers used
push xl
push xh
bigcall NET_Buffer_CountUsed ; (r16, r17, r18, X)
pop xh
pop xl
lds r16, netBuffersUsed
st X+, r16
; max buffers used
clr r16
lds r16, netBuffersMaxUsed
st X+, r16
; no buffer errors
ldd r16, Y+NET_IFACE_OFFS_ERR_NOBUF_LOW

View File

@@ -19,21 +19,52 @@
NETMSG_RecvStats_Write:
ldi r16, 0xff
st X+, r16 ; dest address
ldi r16, 18 ; msg code+src address+10 payload bytes
ldi r16, 19 ; msg code+src address+10 payload bytes
st X+, r16 ; msg len
ldi r16, NETMSG_CMD_RECVSTATS
st X+, r16 ; msg code
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
st X+, r16 ; src address
bigcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
adiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW
ldi r18, 12
bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW+12
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
; UID
bigcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
; interface number
ldd r16, Y+NET_IFACE_OFFS_IFACENUM
st X+, r16
; packets in
ldd r16, Y+NET_IFACE_OFFS_PACKETSIN_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_PACKETSIN_HIGH
st X+, r16
; content error
ldd r16, Y+NET_IFACE_OFFS_ERR_CONTENT_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_CONTENT_HIGH
st X+, r16
; io error
ldd r16, Y+NET_IFACE_OFFS_ERR_IO_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_IO_HIGH
st X+, r16
; nobuf error
ldd r16, Y+NET_IFACE_OFFS_ERR_NOBUF_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_NOBUF_HIGH
st X+, r16
; msgsize error
ldd r16, Y+NET_IFACE_OFFS_ERR_MSGSIZE_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_MSGSIZE_HIGH
st X+, r16
; missed error
ldd r16, Y+NET_IFACE_OFFS_ERR_MISSED_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_MISSED_HIGH
st X+, r16
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
bigcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc)
sbiw xh:xl, 22 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc)
ret
; @end

View File

@@ -12,28 +12,44 @@
; ---------------------------------------------------------------------------
; @routine NETMSG_SendStats_Write @global
;
; @param Y pointer to device to write msg for and to
; @param Y pointer to device to write msg for
; @param X pointer to buffer to write to
; @clobbers R16, R18 (R17, R19, R20, R21, Z)
NETMSG_SendStats_Write:
ldi r16, 0xff
st X+, r16 ; dest address
ldi r16, 12 ; msg code+src address+10 payload bytes
ldi r16, 13 ; msg code+src address+11 payload bytes
st X+, r16 ; msg len
ldi r16, NETMSG_CMD_SENDSTATS
st X+, r16 ; msg code
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
st X+, r16 ; src address
bigcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
adiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW
ldi r18, 6
bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW+6
sbiw xh:xl, 14 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload)
; UID
bigcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
; interface number
ldd r16, Y+NET_IFACE_OFFS_IFACENUM
st X+, r16
; packets out
ldd r16, Y+NET_IFACE_OFFS_PACKETSOUT_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_PACKETSOUT_HIGH
st X+, r16
; collisions
ldd r16, Y+NET_IFACE_OFFS_ERR_COLLISIONS_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_COLLISIONS_HIGH
st X+, r16
; busy
ldd r16, Y+NET_IFACE_OFFS_ERR_BUSY_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_BUSY_HIGH
st X+, r16
sbiw xh:xl, 15 ; go back to beginning of message (1 byte dst addr, 1 byte length, 13 bytes payload)
bigcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 15 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload, 1 byte crc)
sbiw xh:xl, 16 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload, 1 byte crc)
ret
; @end