-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/can/: add statistics for recv, sent and drop #15715
Conversation
[Experimental Bot, please feedback here] No, this PR description does not fully meet the NuttX requirements. Here's why and what's missing:
In short, the PR description needs to be significantly more detailed to meet the NuttX requirements. It needs to provide the missing why and how in the summary, complete the impact assessment, and include actual test logs demonstrating the change in functionality. |
Nice work Javier! Really well done PR and very detailed PR summary! Kudos!!! |
Add support for network statistics for CAN. It includes counters for receive, sent and drop frames. Signed-off-by: Javier Casas <[email protected]>
can_datahandler returns an unsigned value that represent the number of bytes actually bufffered, but the call to iob_tryadd_queue returns a negative value when it fails so that value can't be used as can_datahandler return value because it is interpreted as unsigned so a big number is wrongly returned when iob_tryadd_queue fails. The fix is just setting the return value to zero when iob_tryadd_queue fails, reflecting the actual meaning that no bytes have been buffered.
1183831
to
982b48c
Compare
Summary
Add support for network statistics for CAN. It includes counters for received, sent and dropped frames.
This change was necessary for our application to monitor the dropped can frames reported in the field.
The implementation has mimicked the existing ones for tcp and udp statistics, adding a can_stats_s struct to store the recv, sent and drop counters with the already existing net_stats_t type.
Impact
With this change, users can access the CAN statistics through procfs, the same way they access to all the other network statistics. The CAN recv, sent, and drop counters have been added to the /proc/net/stat output following the same design already existing for other network devices. This change doesn't change any driver behavior beyond just adding the new statistics. It does not introduce any new dependencies beyond the needed header files needed to access the new can_stats_s struct and g_netstats variable. These includes are nuttx/net/netconfig.h and nuttx/net/can.h.
The CAN statistics implemented are only enabled if CONFIG_NET_STATISTICS and CONFIG_NET_CAN configurations are set.
Testing
Tested using a Ubuntu 22.04 and a stm32h7 custom board with CONFIG_NET_STATISTICS and CONFIG_NET_CAN configurations enabled. The test application opens a CAN interface using socketCAN and echoes all the frames read. Every two seconds we print out the CAN statistics and see the recv and sent counters increase accordingly. To test the drop counter, we stop reading the CAN interface from the application so the frames start accumulating in the network buffer. Eventually, that buffer gets full and we start seeing the drop counter increasing as expected.
This traces are printed after reading the counters from /proc/net/stat
CAN stats:
Received: 00000022
Sent: 00000022
Dropped: 00000010