From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Evans Subject: Re: Fwd: Querying current tx_queue usage of a SocketCAN interface Date: Mon, 30 Mar 2015 09:42:57 +1100 Message-ID: <55187FF1.7020701@optusnet.com.au> References: Reply-To: tom_usenet@optusnet.com.au Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from mail110.syd.optusnet.com.au ([211.29.132.97]:54639 "EHLO mail110.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753266AbbC2WnB (ORCPT ); Sun, 29 Mar 2015 18:43:01 -0400 In-Reply-To: Sender: linux-can-owner@vger.kernel.org List-ID: To: Paarvai Naai , linux-can@vger.kernel.org On 29/03/15 07:26, Paarvai Naai wrote: > Hi, > > I have been looking into how to query the SocketCAN interface for its > current tx_queue usage. Just letting you know of a (what was for me) unexpected behaviour of the queue. Sockets can block or return ENOBUFS. Ethernet blocks before it returns ENOBUFS like you'd expect. With CAN it does the opposite "out of the box" and needs to be fixed. http://socket-can.996257.n3.nabble.com/Solving-ENOBUFS-returned-by-write-td2886.html With Ethernet, the transmit queue length is 1000 (which would return ENOBUF) but before that happens it hits SO_SNDBUF, which may be 108544, which is the total Data plus SKB, and with an SKB size of about 200 that means it blocks at about 500 before it ENOBUFs at 1000. With CAN, it would block at 500, but it ENOBUFs at 10 first with the default queue depth! I do the following to get a 256-deep queue that blocks before it overflows: /bin/echo 256 > /sys/class/net/can0/tx_queue_len /bin/echo 256 > /sys/class/net/can1/tx_queue_len int sndbuf = (250 + 8) * 256; socklen_t socklen = sizeof(sndbuf); /* Minimum socket buffer to try and get it blocking */ rc = setsockopt(pSkt->skt, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)); You might also like to read: http://rtime.felk.cvut.cz/can/socketcan-qdisc-final.pdf SocketCAN and queueing disciplines: Final Report M. Sojka, R. Lisovy, P. Psa Czech Technical University in Prague July 20, 2012 Version 1.2 Tom