Skip to contentSkip to conversation

can4linux compilation for i.mx25 under 2.6.39

DISCUSSION Martin Kozusky 4 participants 20 messages May 30, 2012 – Jun 1, 2012 CAN network drivers

lore
Share & tools
lore
#0 lore raw

Hello,
I downloaded latest sources of can4linux from svn and I'm trying to compile it for 2.6.39 kernel (i.mx25 driver). I edit cross-imx25 with proper compiler settings etc then ". cross-imx25" and "make"

There are some errors like
core.c:441:12: error: 'CAN1_BASE_ADDR' undeclared
core.c:452:11: error: 'MXC_INT_CAN1' undeclared

I can change CAN1_BASE_ADDR to MX25_CAN1_BASE_ADDR and MXC_INT_CAN1 to MX25_INT_CAN1, but there is error

imx35.c:18:26: fatal error: mach/mxc_can.h: No such file or directory

Does anybody have idea where do I get this file? When I comment this line, compilation continues and stops at

imx35.c:113:18: error: dereferencing pointer to incomplete type

Does it have anything to do with Karo tx25 board? (which I'm not using) I already have CAN running using SocketCAN, but I also wanted to try can4linux.

Thanks for any help,
Martin

#1 lore raw

Hello Martin,

Quoted 6 lines · Martin Kozusky

Hello,
I downloaded latest sources of can4linux from svn and I'm trying to compile it for 2.6.39 kernel (i.mx25 driver).
I edit cross-imx25 with proper compiler settings etc then ". cross-imx25" and "make"

Quoted 8 lines

There are some errors like
core.c:441:12: error: 'CAN1_BASE_ADDR' undeclared
core.c:452:11: error: 'MXC_INT_CAN1' undeclared

I can change CAN1_BASE_ADDR to MX25_CAN1_BASE_ADDR and MXC_INT_CAN1 to MX25_INT_CAN1, but there is error

imx35.c:18:26: fatal error: mach/mxc_can.h: No such file or directory

It comes from a Karo patch:

http://git.openpandora.org/cgi-bin/gitweb.cgi?p=openembedded.git;a=commitdiff_plain;h=58d6c0ace0c9fe2a3ed9fa845bec9a89583e2fd5

Quoted 8 lines

Does anybody have idea where do I get this file? When I comment this line, compilation continues and stops at

imx35.c:113:18: error: dereferencing pointer to incomplete type

Does it have anything to do with Karo tx25 board? (which I'm not using) I already have CAN running using SocketCAN, but I also wanted to try can4linux.

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Regards, Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#2 lore raw

Dne 30.5.2012 13:50, Marc Kleine-Budde napsal(a):

Quoted 31 lines

Hello Martin,

Quoted 6 lines · Martin Kozusky

Hello,
I downloaded latest sources of can4linux from svn and I'm trying to compile it for 2.6.39 kernel (i.mx25 driver).
I edit cross-imx25 with proper compiler settings etc then ". cross-imx25" and "make"

Quoted 8 lines

There are some errors like
core.c:441:12: error: 'CAN1_BASE_ADDR' undeclared
core.c:452:11: error: 'MXC_INT_CAN1' undeclared

I can change CAN1_BASE_ADDR to MX25_CAN1_BASE_ADDR and MXC_INT_CAN1 to MX25_INT_CAN1, but there is error

imx35.c:18:26: fatal error: mach/mxc_can.h: No such file or directory

It comes from a Karo patch:

http://git.openpandora.org/cgi-bin/gitweb.cgi?p=openembedded.git;a=commitdiff_plain;h=58d6c0ace0c9fe2a3ed9fa845bec9a89583e2fd5

Quoted 8 lines

Does anybody have idea where do I get this file? When I comment this line, compilation continues and stops at

imx35.c:113:18: error: dereferencing pointer to incomplete type

Does it have anything to do with Karo tx25 board? (which I'm not using) I already have CAN running using SocketCAN, but I also wanted to try can4linux.

Quoted 7 lines

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Regards, Marc

Hello Marc,
I wanted to try if it will be faster than socketcan (which is dropping some CAN frames on my HW under heavy load). I need the closest way to the controller, and I thought that when can4linux is not using sockets layer it could be faster. I also wanted to try LinCAN (which is compared to SocketCAN here: http://dce.felk.cvut.cz/hanzalek/publications/Hanzalek10_168894.pdf ) but I think it doesn't support Flexcan

Martin

#3 lore raw

Dne 30.5.2012 14:05, Martin Kozusky napsal(a):

Quoted 39 lines

Dne 30.5.2012 13:50, Marc Kleine-Budde napsal(a):

Quoted 38 lines

Hello Martin,

Quoted 6 lines · Martin Kozusky

Hello,
I downloaded latest sources of can4linux from svn and I'm trying to compile it for 2.6.39 kernel (i.mx25 driver).
I edit cross-imx25 with proper compiler settings etc then ". cross-imx25" and "make"

Quoted 8 lines

There are some errors like
core.c:441:12: error: 'CAN1_BASE_ADDR' undeclared
core.c:452:11: error: 'MXC_INT_CAN1' undeclared

I can change CAN1_BASE_ADDR to MX25_CAN1_BASE_ADDR and MXC_INT_CAN1 to MX25_INT_CAN1, but there is error

imx35.c:18:26: fatal error: mach/mxc_can.h: No such file or directory

It comes from a Karo patch:

http://git.openpandora.org/cgi-bin/gitweb.cgi?p=openembedded.git;a=commitdiff_plain;h=58d6c0ace0c9fe2a3ed9fa845bec9a89583e2fd5

Quoted 8 lines

Does anybody have idea where do I get this file? When I comment this line, compilation continues and stops at

imx35.c:113:18: error: dereferencing pointer to incomplete type

Does it have anything to do with Karo tx25 board? (which I'm not using) I already have CAN running using SocketCAN, but I also wanted to try can4linux.

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Regards, Marc

And I can only use 2.6.39 kernel because there is no patch for my board for kernel 3.x yet :(

Quoted 18 lines
Quoted 1 line

Hello Marc,
I wanted to try if it will be faster than socketcan (which is dropping some CAN frames on my HW under heavy load). I need the closest way to the controller, and I thought that when can4linux is not using sockets layer it could be faster. I also wanted to try LinCAN (which is compared to SocketCAN here:
http://dce.felk.cvut.cz/hanzalek/publications/Hanzalek10_168894.pdf ) but I think it doesn't support Flexcan

Martin

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to Martin Kozusky
Quoted 9 lines · Martin Kozusky
Quoted 5 lines

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Regards, Marc

Hello Marc,
I wanted to try if it will be faster than socketcan (which is dropping some CAN frames on my HW under heavy load). I need the closest way to

Have you debugged which component is dropping frames? Is it the hardware or the socket because your application is to slow?

Quoted 5 lines

the controller, and I thought that when can4linux is not using sockets layer it could be faster. I also wanted to try LinCAN (which is compared to SocketCAN here:
http://dce.felk.cvut.cz/hanzalek/publications/Hanzalek10_168894.pdf ) but I think it doesn't support Flexcan

Good luck :)

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#4 lore raw
In reply to Martin Kozusky
Quoted 9 lines · Martin Kozusky
Quoted 6 lines
Quoted 6 lines

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Regards, Marc

And I can only use 2.6.39 kernel because there is no patch for my board for kernel 3.x yet :(

Ask your supplier to a) backport the fixes to your kernel or b) to deliver a 3.4 based BSP.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#8 lore raw
In reply to Marc Kleine-Budde

Dne 30.5.2012 14:16, Marc Kleine-Budde napsal(a):

Quoted 5 lines · Martin Kozusky
Quoted 4 lines
Quoted 4 lines

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Regards, Marc

Hello Marc,
I wanted to try if it will be faster than socketcan (which is dropping some CAN frames on my HW under heavy load). I need the closest way to

Have you debugged which component is dropping frames? Is it the hardware or the socket because your application is to slow?

I tried to solve this 19.4.2012 (thread "CAN messages being lost on i.MX25 with flexcan") and when I changed rcvbuf_size to 10000000 it helped, but still sometimes few CAN frames are dropped (and many more when I try to write to SD card or internal flash). So I think it's not HW problem. The best for me would be some kernel module which would just put the CAN frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Martin

Quoted 10 lines
Quoted 5 lines

the controller, and I thought that when can4linux is not using sockets layer it could be faster. I also wanted to try LinCAN (which is compared to SocketCAN here:
http://dce.felk.cvut.cz/hanzalek/publications/Hanzalek10_168894.pdf ) but I think it doesn't support Flexcan

Good luck :)

Marc

#5 lore raw
In reply to Marc Kleine-Budde

Dne 30.5.2012 14:18, Marc Kleine-Budde napsal(a):

Quoted 5 lines · Martin Kozusky
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Why do you want to use can4linux? Socketcan is the official CAN Stack for Linux. Be sure you use the latest kernel, because the flexcan driver has some bugs and problems prior to v3.4.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Regards, Marc

And I can only use 2.6.39 kernel because there is no patch for my board for kernel 3.x yet :(

Ask your supplier to a) backport the fixes to your kernel or b) to deliver a 3.4 based BSP.

or c) backport the fixes myself :) I think that will be fastest way, if it's just about fixes of flexcan driver. Or are there many changes in many kernel files?

Martin

Quoted 2 lines

Marc

#6 lore raw
Quoted 9 lines · Martin Kozusky
Quoted 5 lines
Quoted 2 lines

And I can only use 2.6.39 kernel because there is no patch for my board for kernel 3.x yet :(

Ask your supplier to a) backport the fixes to your kernel or b) to deliver a 3.4 based BSP.

or c) backport the fixes myself :) I think that will be fastest way, if it's just about fixes of flexcan driver. Or are there many changes in many kernel files?

No, IIRC 2 patches on the driver, one small infrastructure patch.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#9 lore raw
In reply to Martin Kozusky
Quoted 5 lines · Martin Kozusky
Quoted 2 lines

Have you debugged which component is dropping frames? Is it the hardware or the socket because your application is to slow?

I tried to solve this 19.4.2012 (thread "CAN messages being lost on i.MX25 with flexcan") and when I changed rcvbuf_size to 10000000 it

Oh, I see, this conversation slipped my mind.

Quoted 9 lines

helped, but still sometimes few CAN frames are dropped (and many more when I try to write to SD card or internal flash). So I think it's not HW problem.
The best for me would be some kernel module which would just put the CAN frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Are you writing the can frames to storage in the same thread as receiving them?

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#10 lore raw

Dne 30.5.2012 14:40, Marc Kleine-Budde napsal(a):

Quoted 19 lines · Martin Kozusky
Quoted 5 lines
Quoted 2 lines

Have you debugged which component is dropping frames? Is it the hardware or the socket because your application is to slow?

I tried to solve this 19.4.2012 (thread "CAN messages being lost on i.MX25 with flexcan") and when I changed rcvbuf_size to 10000000 it

Oh, I see, this conversation slipped my mind.

Quoted 9 lines

helped, but still sometimes few CAN frames are dropped (and many more when I try to write to SD card or internal flash). So I think it's not HW problem.
The best for me would be some kernel module which would just put the CAN frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Quoted 2 lines

Are you writing the can frames to storage in the same thread as receiving them?

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).

Martin

Quoted 2 lines

Marc

#11 lore raw
Quoted 11 lines · Martin Kozusky
Quoted 9 lines
Quoted 6 lines

The best for me would be some kernel module which would just put the CAN frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Are you writing the can frames to storage in the same thread as receiving them?

Quoted 9 lines

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?

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#12 lore raw

Dne 30.5.2012 15:18, Marc Kleine-Budde napsal(a):

Quoted 22 lines · Martin Kozusky
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

The best for me would be some kernel module which would just put the CAN frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Are you writing the can frames to storage in the same thread as receiving them?

Quoted 9 lines

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).

Quoted 1 line

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?

Martin

Quoted 3 lines

Marc

#13 lore raw
Quoted 24 lines · Martin Kozusky

Dne 30.5.2012 15:18, Marc Kleine-Budde napsal(a):

Quoted 23 lines · Martin Kozusky
Quoted 21 lines
Quoted 10 lines
Quoted 7 lines

The best for me would be some kernel module which would just put the CAN
frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Are you writing the can frames to storage in the same thread as receiving them?

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).

Quoted 3 lines
Quoted 1 line

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.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#14 lore raw

Dne 30.5.2012 16:18, Marc Kleine-Budde napsal(a):

Quoted 25 lines · Martin Kozusky
Quoted 24 lines

Dne 30.5.2012 15:18, Marc Kleine-Budde napsal(a):

Quoted 23 lines · Martin Kozusky
Quoted 21 lines
Quoted 10 lines
Quoted 7 lines

The best for me would be some kernel module which would just put the CAN
frame into some big "from userspace available" buffer in the interrupt and nothing more. My app would check if there is anything new and read it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the problem arise, I think it's not that much.

Are you writing the can frames to storage in the same thread as receiving them?

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).

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

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 :(

Martin

Quoted 3 lines

Marc

#15 lore raw
Quoted 31 lines · Martin Kozusky

Dne 30.5.2012 16:18, Marc Kleine-Budde napsal(a):

Quoted 30 lines · Martin Kozusky
Quoted 29 lines

Dne 30.5.2012 15:18, Marc Kleine-Budde napsal(a):

Quoted 28 lines · Martin Kozusky
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

The best for me would be some kernel module which would just put the CAN
frame into some big "from userspace available" buffer in the interrupt
and nothing more. My app would check if there is anything new and read
it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the
problem arise, I think it's not that much.

Quoted 2 lines

Are you writing the can frames to storage in the same thread as receiving them?

Quoted 10 lines

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?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#16 lore raw
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

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?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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 :(

Quoted 4 lines

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?

Regards,
Oliver

#19 lore raw
In reply to Marc Kleine-Budde

Dne 31.5.2012 15:42, Marc Kleine-Budde napsal(a):

Quoted 41 lines · Martin Kozusky
Quoted 31 lines

Dne 30.5.2012 16:18, Marc Kleine-Budde napsal(a):

Quoted 30 lines · Martin Kozusky
Quoted 29 lines

Dne 30.5.2012 15:18, Marc Kleine-Budde napsal(a):

Quoted 28 lines · Martin Kozusky
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

The best for me would be some kernel module which would just put the CAN
frame into some big "from userspace available" buffer in the interrupt
and nothing more. My app would check if there is anything new and read
it out.
There are around 1500/sec (at 250kbit) can frames on the bus when the
problem arise, I think it's not that much.

Quoted 2 lines

Are you writing the can frames to storage in the same thread as receiving them?

Quoted 10 lines

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?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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 :(

Quoted 4 lines

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'm already using this Marc, it helped only a little :(

Martin

Quoted 2 lines

Marc

#17 lore raw
In reply to Oliver Hartkopp

Dne 31.5.2012 18:28, Oliver Hartkopp napsal(a):

Quoted 36 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

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?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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 :(

Quoted 4 lines

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

Quoted 7 lines

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

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

Martin

Quoted 7 lines

Regards,
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw
Quoted 66 lines · Martin Kozusky

Dne 31.5.2012 18:28, Oliver Hartkopp napsal(a):

Quoted 36 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

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?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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 :(

Quoted 4 lines

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

Quoted 7 lines

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.

Quoted 7 lines

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 :-(

Quoted 2 lines

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