All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Andrew Bell <andrew.bell.ia@gmail.com>
Cc: linux-can@vger.kernel.org
Subject: Re: Full Buffers and the Passive bus
Date: Fri, 31 Aug 2012 19:32:42 +0200	[thread overview]
Message-ID: <5040F53A.5080609@hartkopp.net> (raw)
In-Reply-To: <CACJ51z35dnc7udK2AaYxRrf6vgZLvC=V-Weuf8TokTL0=3nAbA@mail.gmail.com>

On 31.08.2012 18:52, Andrew Bell wrote:

> On Fri, Aug 31, 2012 at 11:49 AM, Oliver Hartkopp
> <socketcan@hartkopp.net> wrote:
>> On 31.08.2012 18:36, Andrew Bell wrote:
>>
>>> Is there some way within socket CAN to detect the state when no nodes
>>> are on the BUS?  I do get CAN_ERR_TX_TIMEOUT error frames after some
>>> time, but I'm writing to the BUS faster than frames drain from the
>>> buffers, so eventually buffers fill up and writes start failing.  In
>>> this case, write does return ENOBUFS.  But I'd like to be able to
>>> differentiate between the case where buffers are full because of some
>>> transient condition (I'm writing too fast for the BUS) and the
>>> condition when nobody is home to receive anything at all.
>>>
>>> Suggestions appreciated.
>>
>>
>> Hello Andrew,
>>
>> this first idea was to check, if the successful transmissions increase the tx
>> counter in the netdevice statistics. When there's no increasing value no
>> frames have been sent on the wire.
> 
> Thanks for the idea.
> 
> What is the interface/API for getting these statistics?
> 


/sbin/ifconfig reads /proc/net/dev for this reason.

But strace /sbin/ifstat turns out, that ifstat uses AF_NETLINK sockets.

(..)
socket(PF_NETLINK, SOCK_RAW, 0)         = 4
setsockopt(4, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(4, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(4, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(4, {sa_family=AF_NETLINK, pid=5009, groups=00000000}, [12]) = 0
time(NULL)                              = 1346434087
send(4, "\34\0\0\0\22\0\1\3(\364@P\0\0\0\0\2\0\0\0\10\0\35\0\1\0\0\0", 28, 0) = 28
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\374\3\0\0\20\0\2\0(\364@P\221\23\0\0\0\0\4\3\1\0\0\0I\0\1\0\0\0\0\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 3652
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"8\2\0\0\20\0\2\0(\364@P\221\23\0\0\0\0\30\1\5\0\0\0\301\0\1\0\0\0\0\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 1704
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0(\364@P\221\23\0\0\0\0\0\0\5\0\0\0\301\0\1\0\0\0\0\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 20
close(4)                                = 0
(..)

I would try the AF_NETLINK method, but i have no sample code at hand.

Please check out for the ifstat code yourself.

Regards,
Oliver

  parent reply	other threads:[~2012-08-31 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 16:36 Full Buffers and the Passive bus Andrew Bell
2012-08-31 16:49 ` Oliver Hartkopp
2012-08-31 16:52   ` Andrew Bell
2012-08-31 16:53     ` Andrew Bell
2012-08-31 17:32     ` Oliver Hartkopp [this message]
2012-08-31 17:37   ` Kurt Van Dijck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5040F53A.5080609@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=andrew.bell.ia@gmail.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.