Skip to contentSkip to conversation

poll broken (for can) (was: Re: Multiple programs trying to access the socket)

DISCUSSION Marc Kleine-Budde 4 participants 7 messages Mar 28, 2011 – Mar 30, 2011 9 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1301321142.9519.10.camel@lukonin-pc

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines

BTW: I figured out why poll() wakes you up but the next write will fail with -ENOBUFS again.

Ah, I'm curious? I also did realize that poll does burn CPU cycles (instead of waiting).

The poll callback checks if the used memory is less than the half of per socket snd buffer (IIRC ~60K). See:

datagram_poll (http://lxr.linux.no/linux+v2.6.38/net/core/datagram.c#L737)
sock_writeable (http://lxr.linux.no/linux+v2.6.38/include/net/sock.h#L1618)

Because the size of a can frame (+the skb overhead) is much less then the ethernet frame (+overhead) the default value for the snd buffer is too big for can.

We get the -ENOBUF from write() if the tx_queue_len (default 10) is exceeded.

http://lxr.linux.no/linux+v2.6.38/drivers/net/can/dev.c#L435
http://lxr.linux.no/linux+v2.6.38/net/can/af_can.c#L268

cheers, 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   |

_______________________________________________
Socketcan-users mailing list [email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: poll broken (for can)

Quoted 17 lines · Marc Kleine-Budde
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines

BTW: I figured out why poll() wakes you up but the next write will fail with -ENOBUFS again.

Ah, I'm curious? I also did realize that poll does burn CPU cycles (instead of waiting).

The poll callback checks if the used memory is less than the half of per socket snd buffer (IIRC ~60K). See:

datagram_poll (http://lxr.linux.no/linux+v2.6.38/net/core/datagram.c#L737)
sock_writeable (http://lxr.linux.no/linux+v2.6.38/include/net/sock.h#L1618)

Because the size of a can frame (+the skb overhead) is much less then the ethernet frame (+overhead) the default value for the snd buffer is too big for can.

Quoted 6 lines

We get the -ENOBUF from write() if the tx_queue_len (default 10) is exceeded.

http://lxr.linux.no/linux+v2.6.38/drivers/net/can/dev.c#L435
http://lxr.linux.no/linux+v2.6.38/net/can/af_can.c#L268

What would be your suggestion? Decreasing the socket send buffer for CAN by default?

Regards,
Oliver

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: poll broken (for can)

Quoted 21 lines · Oliver Hartkopp
Quoted 20 lines · Marc Kleine-Budde
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines

BTW: I figured out why poll() wakes you up but the next write will fail with -ENOBUFS again.

Ah, I'm curious? I also did realize that poll does burn CPU cycles (instead of waiting).

The poll callback checks if the used memory is less than the half of per socket snd buffer (IIRC ~60K). See:

datagram_poll (http://lxr.linux.no/linux+v2.6.38/net/core/datagram.c#L737)
sock_writeable (http://lxr.linux.no/linux+v2.6.38/include/net/sock.h#L1618)

Because the size of a can frame (+the skb overhead) is much less then the ethernet frame (+overhead) the default value for the snd buffer is too big for can.

We get the -ENOBUF from write() if the tx_queue_len (default 10) is exceeded.

Quoted 6 lines
Quoted 3 lines

http://lxr.linux.no/linux+v2.6.38/drivers/net/can/dev.c#L435
http://lxr.linux.no/linux+v2.6.38/net/can/af_can.c#L268

What would be your suggestion? Decreasing the socket send buffer for CAN by default?

I haven't done any testing.....As far as I understand the code, we can
a) increase the default tx_queue_len and/or
b) decrease the default snd buffer size.

Note: a) is a per device setting whereas b) is a per socket setting.

With the current settings the -ENOBUF is triggered if we have X unsend can frames (per device) where X equals the tx_queue_len. This means using 5 applications, it about 2 queued (i.e. unsent) frames per app and device.

If we increase the tx_queue_len to a high value (via ifconfig), so that the snd buffer is fully used, before the tx_queue_len is exceeded the write system call will block, (or return -EAGAIN of opened non blocking). At least the last time I've done this.

I think solution b) would lead to a similar behavioural change.

What do we really want to specify?

Something like: queue up to X frames per socket and queue only Y frames per device. Where Y = X * n and n is "I don't know yet"?

Y is simple, it's the tx_queue_len. But X is more complicated. The can frames have non constant length (i.e. dlc) and I'm not sure that the netdev people say if we misuse the sock_alloc_send_pskb() for our tx-flow-control :)

Cheers, 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   |

_______________________________________________
Socketcan-users mailing list [email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: poll broken (for can)

Quoted 40 lines · Marc Kleine-Budde
Quoted 21 lines · Oliver Hartkopp
Quoted 20 lines · Marc Kleine-Budde
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines

BTW: I figured out why poll() wakes you up but the next write will fail with -ENOBUFS again.

Ah, I'm curious? I also did realize that poll does burn CPU cycles (instead of waiting).

The poll callback checks if the used memory is less than the half of per socket snd buffer (IIRC ~60K). See:

datagram_poll (http://lxr.linux.no/linux+v2.6.38/net/core/datagram.c#L737)
sock_writeable (http://lxr.linux.no/linux+v2.6.38/include/net/sock.h#L1618)

Because the size of a can frame (+the skb overhead) is much less then the ethernet frame (+overhead) the default value for the snd buffer is too big for can.

We get the -ENOBUF from write() if the tx_queue_len (default 10) is exceeded.

Quoted 6 lines
Quoted 3 lines

http://lxr.linux.no/linux+v2.6.38/drivers/net/can/dev.c#L435
http://lxr.linux.no/linux+v2.6.38/net/can/af_can.c#L268

What would be your suggestion? Decreasing the socket send buffer for CAN by default?

I haven't done any testing.....As far as I understand the code, we can
a) increase the default tx_queue_len and/or
b) decrease the default snd buffer size.

Note: a) is a per device setting whereas b) is a per socket setting.

With the current settings the -ENOBUF is triggered if we have X unsend can frames (per device) where X equals the tx_queue_len. This means using 5 applications, it about 2 queued (i.e. unsent) frames per app and device.

Quoted 8 lines

If we increase the tx_queue_len to a high value (via ifconfig), so that the snd buffer is fully used, before the tx_queue_len is exceeded the write system call will block, (or return -EAGAIN of opened non blocking). At least the last time I've done this.

I think solution b) would lead to a similar behavioural change.

What do we really want to specify?

Hm - the problem could be that people expect their frames to be sent 'in time', so if we increase the tx_queue_len, it's not transparent when the frames are potentially leaving the system - and if the application data is already out-dated when hitting the medium.

What about having up to three CAN frames in each CAN_RAW socket send buffer and e.g.50 frames in the tx_queue_len of the netdevice as a starting point?

Quoted 8 lines

Something like: queue up to X frames per socket and queue only Y frames per device. Where Y = X * n and n is "I don't know yet"?

Y is simple, it's the tx_queue_len. But X is more complicated. The can frames have non constant length (i.e. dlc) and I'm not sure that the netdev people say if we misuse the sock_alloc_send_pskb() for our tx-flow-control :)

I would propose to count the CAN frames independently from the can_dlc. AFAIK the tx_queue_len is dealing with skb's - and the skb->len for the socket send buffer is also size of struct can_frame, right?

Regards,
Oliver

maintainer
#12 lore raw

Re: poll broken (for can)

From: Oliver Hartkopp <[email protected]>
Date: Tue, 29 Mar 2011 22:03:12 +0200

Quoted 7 lines

Hm - the problem could be that people expect their frames to be sent 'in time', so if we increase the tx_queue_len, it's not transparent when the frames are potentially leaving the system - and if the application data is already out-dated when hitting the medium.

What about having up to three CAN frames in each CAN_RAW socket send buffer and e.g.50 frames in the tx_queue_len of the netdevice as a starting point?

Setting tx_queue_len low is bound to cause all kinds of problems.

This poll() peculiarity is just one such problem.

I would suggest increasing it for CAN devices to at least 100.

#13 lore raw

Re: [Socketcan-users] poll broken (for can)

In reply to Oliver Hartkopp
Quoted 7 lines · Oliver Hartkopp
Quoted 5 lines · Marc Kleine-Budde
Quoted 2 lines · Oliver Hartkopp
Quoted 1 line · Marc Kleine-Budde

On 03/28/2011 05:55 PM, Wolfgang Grandegger wrote:

What do we really want to specify?

Quoted 7 lines

Hm - the problem could be that people expect their frames to be sent 'in time', so if we increase the tx_queue_len, it's not transparent when the frames are potentially leaving the system - and if the application data is already out-dated when hitting the medium.

What about having up to three CAN frames in each CAN_RAW socket send buffer and e.g.50 frames in the tx_queue_len of the netdevice as a starting point?

50 looks good, but 3 is a bit small IMHO.

Quoted 6 lines
Quoted 6 lines

Something like: queue up to X frames per socket and queue only Y frames per device. Where Y = X * n and n is "I don't know yet"?

Quoted 6 lines
Quoted 4 lines

Y is simple, it's the tx_queue_len. But X is more complicated. The can frames have non constant length (i.e. dlc) and I'm not sure that the netdev people say if we misuse the sock_alloc_send_pskb() for our tx-flow-control :)

I would propose to count the CAN frames independently from the can_dlc.

ack.

Quoted 3 lines

AFAIK
the tx_queue_len is dealing with skb's - and the skb->len for the socket send buffer is also size of struct can_frame, right?

ack.

Quoted 8 lines

Regards,
Oliver

_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw

Re: poll broken (for can)

Quoted 50 lines · Oliver Hartkopp
Quoted 40 lines · Marc Kleine-Budde
Quoted 21 lines · Oliver Hartkopp
Quoted 20 lines · Marc Kleine-Budde
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines

BTW: I figured out why poll() wakes you up but the next write will fail with -ENOBUFS again.

Ah, I'm curious? I also did realize that poll does burn CPU cycles (instead of waiting).

The poll callback checks if the used memory is less than the half of per socket snd buffer (IIRC ~60K). See:

datagram_poll (http://lxr.linux.no/linux+v2.6.38/net/core/datagram.c#L737)
sock_writeable (http://lxr.linux.no/linux+v2.6.38/include/net/sock.h#L1618)

Because the size of a can frame (+the skb overhead) is much less then the ethernet frame (+overhead) the default value for the snd buffer is too big for can.

We get the -ENOBUF from write() if the tx_queue_len (default 10) is exceeded.

Quoted 6 lines
Quoted 3 lines

http://lxr.linux.no/linux+v2.6.38/drivers/net/can/dev.c#L435
http://lxr.linux.no/linux+v2.6.38/net/can/af_can.c#L268

What would be your suggestion? Decreasing the socket send buffer for CAN by default?

I haven't done any testing.....As far as I understand the code, we can
a) increase the default tx_queue_len and/or
b) decrease the default snd buffer size.

Note: a) is a per device setting whereas b) is a per socket setting.

With the current settings the -ENOBUF is triggered if we have X unsend can frames (per device) where X equals the tx_queue_len. This means using 5 applications, it about 2 queued (i.e. unsent) frames per app and device.

Quoted 8 lines

If we increase the tx_queue_len to a high value (via ifconfig), so that the snd buffer is fully used, before the tx_queue_len is exceeded the write system call will block, (or return -EAGAIN of opened non blocking). At least the last time I've done this.

I think solution b) would lead to a similar behavioural change.

What do we really want to specify?

Quoted 7 lines

Hm - the problem could be that people expect their frames to be sent 'in time', so if we increase the tx_queue_len, it's not transparent when the frames are potentially leaving the system - and if the application data is already out-dated when hitting the medium.

What about having up to three CAN frames in each CAN_RAW socket send buffer and e.g.50 frames in the tx_queue_len of the netdevice as a starting point?

With current the tx_queue_len of 10 it's 10 frames for a single application scenario. But I don't have any real world CAN experience.

Quoted 9 lines
Quoted 7 lines

Something like: queue up to X frames per socket and queue only Y frames per device. Where Y = X * n and n is "I don't know yet"?

Y is simple, it's the tx_queue_len. But X is more complicated. The can frames have non constant length (i.e. dlc) and I'm not sure that the netdev people say if we misuse the sock_alloc_send_pskb() for our tx-flow-control :)

I would propose to count the CAN frames independently from the can_dlc. AFAIK

Sure - That's what we want. The code has to be written, though :)

Quoted 2 lines

the tx_queue_len is dealing with skb's - and the skb->len for the socket send buffer is also size of struct can_frame, right?

I don't know the code in depth, but I think the skb holding the outgoing can frame is allocated (or at least accounted) from the snd buffer. Maybe even more data structures.

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   |

_______________________________________________
Socketcan-users mailing list [email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users