problem with g_iob_sem.semcount in socketCAN
- Dominant language
- C
- Stars
- 4k
- Forks
- 1.7k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 237
Description
Hi, I am using Nuttx SocketCAN together with UAVCAN in PX4 and got into a problem with `g_iob_sem.semcount` either exceeds the `CONFIG_IOB_NBUFFERS` or gets as low as 1. These happen expecially at high data rate (~1000fps for standard 2.0B CAN frame). When they occur, socketCAN network iface stops functional and no more RX/TX.
Regarding semcount oveflow issue, I dug into the code and noticed that in the TX path, `iob_update_pktlen` sporadically while doing trimming, frees up an amount of `CONFIG_IOB_NBUFFERS` or currently free iob buffers (most of the time equal to `CONFIG_IOB_BUFFERS` ) https://github.com/apache/nuttx/blob/c60dd72a2a8bace64480c73bc824daf8bb9d41a1/net/devif/devif_send.c#L105
This leads to `g_iob_sem.semcount` being increased to much higher than `CONFIG_IOB_NBUFFERS`.
I changed that part to
```
//iob_update_pktlen(dev->d_iob, offset);
ret = iob_trycopyin(dev->d_iob, buf, len, offset, false);
if (ret < 0 || dev->d_iob->io_pktlen != len)
{
netdev_iob_release(dev);
goto errout;
}
```
and I was able to get rid of the overflowed semcount problem
This is really weird since before that with `netdev_iob_prepare`, the new iob handle should always have `io_flink` NULL. And it actually does when I do a check before the line `iob_update_pktlen` but somehow, in that function, the whole amount of iob in `g_iob_freelist` is always freed up.
And for the `g_iob_sem.semcount` drop to 1 issue, when it happens, usually after 10mins of operation at high rate, suddenly semcount drops to 1 from a long lasting stable level around `CONFIG_IOB_NBUFFERS`. This issue is much harder to debug and currently I don't have any fix/workaround
Both issue happen regardless of `CONFIG_IOB_NBUFFERS` value, with/without `CONFIG_IOB_THROTTLE`, with/without `CONFIG_NET_TIMESTAMP` and seemingly independent of each other.
Contributor guide
Assessment
This issue has not been assessed yet.