All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
To: Martin Kozusky <mkozusky@kkmicro.cz>
Cc: linux-can Mailing List <linux-can@vger.kernel.org>
Subject: Re: can4linux compilation for i.mx25 under 2.6.39
Date: Fri, 01 Jun 2012 13:22:48 +0200	[thread overview]
Message-ID: <4FC8A608.1050303@volkswagen.de> (raw)
In-Reply-To: <jq9ti4$hur$1@dough.gmane.org>

On 01.06.2012 10:12, Martin Kozusky wrote:
> Dne 31.5.2012 18:28, Oliver Hartkopp napsal(a):
>>
>>>>>>>> No, CAN has it's own thread, which is just making struct from can
>>>>>>>> messages (reading via select() ) and writes them into another buffer.
>>>>>>>> Then the main thread reads this buffer and writes to SD card. Now I
>>>>>>>> changed it so that this buffer is 30MB big, so I first store all the
>>>>>>>> messages into RAM, and when I don't need to record CAN frames
>>>>>>>> anymore, I
>>>>>>>> write all of them to card from this big buffer.
>>>>>>>> But this is just limited workaround because I'm limited with the RAM
>>>>>>>> size (so I had to make the buffer cyclic and just latest xxxx messages
>>>>>>>> are stored, older are overwritten when the buffer is full).
>>>>>>>
>>>>>>> Have you setup realtime priorities for you CAN thread?
>>>>>> No, I did't set up any special attributes. Do you mean I should use
>>>>>> pthread_attr_setschedpolicy(ptr,SCHED_RR) or something else?
>>>>>
>>>>> or better SCHED_FIFO for your can thread.
>>>> Hello Marc,
>>>> I tried that and still when I write
>>>> dd if=/dev/zero of=/mnt/mmcblk0p1/test bs=512 count=10000 (copy 5MB to
>>>> SD card) around 300 CAN frames (from 68500 frames) are lost :(
>>>
>>> http://man7.org/linux/man-pages/man2/recvmmsg.2.html
>>>
>>> Maybe you can use recvmmsg(). I don't know if it works already on can
>>> sockets.
>>
>>
>> I wonder, if accessing the MMC/SD card leads to a long-time blocking of
>> interrupts and therefore lost frames on controller level.
>>
>> Looks like the flexcan RX FIFO overflow is documented here:
>> http://lxr.linux.no/#linux+v3.4/drivers/net/can/flexcan.c#L603
>>
>> Martin, can you check the overflow counters with
>>
>> ifconfig can0
>>
>> or
>>
>> ip -statistics link show can0
>>
>> after the problem with writing to the MMC/SD card showed up?
> 
> Hello Oliver,
> I just configured can0 with canconfig (speed to 250kbs) and canconfig can0 start
> (BTW: what does "can0 state: ERROR-ACTIVE" mean after I write canconfig can0 
> start? )
> 
> Then I started sending CAN packets. I sent 39660 packets to CAN, but only 
> 35734 were received by the CAN layer?
> 
> this is what is shown (without any app running)
> 
> root@vmx25 /opt$ ./ip -statistics link show can0
> 2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
>     link/can
>     RX: bytes  packets  errors  dropped overrun mcast
>     280440     35734    6       0       6       0
>     TX: bytes  packets  errors  dropped carrier collsns
>     0          0        0       0       0       0 
> 
> And this is show when I copy 5MB to SD card with dd. This time 39347 packets 
> where sent from my app.
> 
> 2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
>     link/can
>     RX: bytes  packets  errors  dropped overrun mcast
>     152197     19335    21      0       21      0
>     TX: bytes  packets  errors  dropped carrier collsns
>     0          0        0       0       0       0 
> 

Well this seems to prove my assumption that you get overruns in the flexcan RX FIFO
when you access the SD card :-(

> Should I try to backport the latest flexcan.c to my 2.6.39 kernel and see if 
> it helps?

In general a backport is a good idea (and should be pretty easy) - there are
only four fixes to apply - especially the irq flooding fix is recommended:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=history;f=drivers/net/can/flexcan.c

But i think you will still have the overruns shown up in your output above.
No matter if you use the Mainline flexcan driver or if you would use any
other flexcan driver. :-(

It really looks like the the SD card access blocks the interrupts in a way
the the frames are overwritten inside the controller itself as no-one gets
the CAN frames from the RX FIFO in time.

Don't know if there's anything that could be done with the interrupt
subsystem in Linux to solve this.

@Marc: Is there something that can be done ...
- with or without NAPI
- by increasing the flexcan RX FIFO
- with interrupt priorities on the i.mx25 ??

Regards,
Oliver

  reply	other threads:[~2012-06-01 11:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 11:39 can4linux compilation for i.mx25 under 2.6.39 Martin Kozusky
2012-05-30 11:50 ` Marc Kleine-Budde
2012-05-30 12:05   ` Martin Kozusky
2012-05-30 12:08     ` Martin Kozusky
2012-05-30 12:18       ` Marc Kleine-Budde
2012-05-30 12:34         ` Martin Kozusky
2012-05-30 12:37           ` Marc Kleine-Budde
2012-05-30 12:16     ` Marc Kleine-Budde
2012-05-30 12:29       ` Martin Kozusky
2012-05-30 12:40         ` Marc Kleine-Budde
2012-05-30 12:50           ` Martin Kozusky
2012-05-30 13:18             ` Marc Kleine-Budde
2012-05-30 13:26               ` Martin Kozusky
2012-05-30 14:18                 ` Marc Kleine-Budde
2012-05-31 13:29                   ` Martin Kozusky
2012-05-31 13:42                     ` Marc Kleine-Budde
2012-05-31 16:28                       ` Oliver Hartkopp
2012-06-01  8:12                         ` Martin Kozusky
2012-06-01 11:22                           ` Oliver Hartkopp [this message]
2012-06-01  6:19                       ` Martin Kozusky

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=4FC8A608.1050303@volkswagen.de \
    --to=oliver.hartkopp@volkswagen.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mkozusky@kkmicro.cz \
    /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.